PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::d2::UnitVec Class Reference

2-D unit vector. More...

#include <UnitVec.hpp>

Collaboration diagram for playrho::d2::UnitVec:
[legend]

Public Types

using value_type = Real
 Value type used for the coordinate values of this vector.
 
using size_type = std::size_t
 Size type.
 
using const_reference = const value_type &
 Constant reference type.
 
using const_pointer = const value_type *
 Constant pointer type.
 
using const_iterator = const value_type *
 Constant iterator type.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 Constant reverse iterator type.
 
template<typename T >
using PolarCoord = std::enable_if_t< IsArithmetic< T >::value, std::pair< UnitVec, T > >
 Polar coordinate. More...
 

Public Member Functions

constexpr size_type max_size () const noexcept
 Gets the max size.
 
constexpr size_type size () const noexcept
 Gets the size.
 
constexpr bool empty () const noexcept
 Whether empty. More...
 
const_iterator begin () const noexcept
 Gets a "begin" iterator.
 
const_iterator end () const noexcept
 Gets an "end" iterator.
 
const_iterator cbegin () const noexcept
 Gets a "begin" iterator.
 
const_iterator cend () const noexcept
 Gets an "end" iterator.
 
const_reverse_iterator crbegin () const noexcept
 Gets a reverse "begin" iterator.
 
const_reverse_iterator crend () const noexcept
 Gets a reverse "end" iterator.
 
const_reverse_iterator rbegin () const noexcept
 Gets a reverse "begin" iterator.
 
const_reverse_iterator rend () const noexcept
 Gets a reverse "end" iterator.
 
constexpr const_reference operator[] (size_type pos) const noexcept
 Gets a constant reference to the requested element. More...
 
constexpr const_reference at (size_type pos) const
 Gets a constant reference to the requested element. More...
 
constexpr const_pointer data () const noexcept
 Direct access to data.
 
constexpr auto GetX () const noexcept
 Gets the "X" value.
 
constexpr auto GetY () const noexcept
 Gets the "Y" value.
 
constexpr UnitVec FlipXY () const noexcept
 Flips the X and Y values.
 
constexpr UnitVec FlipX () const noexcept
 Flips the X value.
 
constexpr UnitVec FlipY () const noexcept
 Flips the Y value.
 
constexpr UnitVec Rotate (UnitVec amount) const noexcept
 Rotates the unit vector by the given amount. More...
 
constexpr UnitVec GetRevPerpendicular () const noexcept
 Gets a vector counter-clockwise (reverse-clockwise) perpendicular to this vector. More...
 
constexpr UnitVec GetFwdPerpendicular () const noexcept
 Gets a vector clockwise (forward-clockwise) perpendicular to this vector. More...
 
constexpr UnitVec operator- () const noexcept
 Negation operator.
 
constexpr UnitVec operator+ () const noexcept
 Positive operator.
 
constexpr UnitVec Absolute () const noexcept
 Gets the absolute value.
 

Static Public Member Functions

static constexpr UnitVec GetRight () noexcept
 Gets the right-ward oriented unit vector. More...
 
static constexpr UnitVec GetTop () noexcept
 Gets the top-ward oriented unit vector. More...
 
static constexpr UnitVec GetLeft () noexcept
 Gets the left-ward oriented unit vector. More...
 
static constexpr UnitVec GetBottom () noexcept
 Gets the bottom-ward oriented unit vector. More...
 
static constexpr UnitVec GetZero () noexcept
 Gets the non-oriented unit vector.
 
static constexpr UnitVec GetTopRight () noexcept
 Gets the 45 degree unit vector. More...
 
static constexpr UnitVec GetBottomRight () noexcept
 Gets the -45 degree unit vector. More...
 
static constexpr UnitVec GetDefaultFallback () noexcept
 Gets the default fallback.
 
template<typename T >
static PolarCoord< T > Get (const T x, const T y, const UnitVec fallback=GetDefaultFallback()) noexcept
 Gets the unit vector & magnitude from the given parameters.
 
static UnitVec Get (const Angle angle) noexcept
 Gets the given angled unit vector. More...
 

Private Member Functions

constexpr UnitVec (value_type x, value_type y) noexcept
 Initializing constructor.
 

Private Attributes

value_type m_elems [2] = { value_type{0}, value_type{0} }
 Element values.
 

Detailed Description

2-D unit vector.

This is a 2-dimensional directional vector.

Examples
Body.cpp, PulleyJoint.cpp, and World.cpp.

Member Typedef Documentation

◆ PolarCoord

template<typename T >
using playrho::d2::UnitVec::PolarCoord = std::enable_if_t<IsArithmetic<T>::value, std::pair<UnitVec, T> >

Polar coordinate.

This is a direction and magnitude pair defined by the unit vector class.

Note
A magnitude of 0 indicates that no conclusive direction could be determined. The magnitude will otherwise be a normal value.

Member Function Documentation

◆ at()

constexpr const_reference playrho::d2::UnitVec::at ( size_type  pos) const
inlineconstexpr

Gets a constant reference to the requested element.

Exceptions
InvalidArgumentif given a position that's >= size().

◆ empty()

constexpr bool playrho::d2::UnitVec::empty ( ) const
inlineconstexprnoexcept

Whether empty.

Note
Always false for N > 0.

◆ Get()

UnitVec playrho::d2::UnitVec::Get ( const Angle  angle)
staticnoexcept

Gets the given angled unit vector.

Note
For angles that are meant to be at exact multiples of the quarter turn, better accuracy will be had by using one of the four oriented unit vector returning methods - for the right, top, left, bottom orientations.

◆ GetBottom()

static constexpr UnitVec playrho::d2::UnitVec::GetBottom ( )
inlinestaticconstexprnoexcept

Gets the bottom-ward oriented unit vector.

Note
This is the actual value for the 3/4 turned (270 degree angled) unit vector.
This is the reverse perpendicular unit vector of the left oriented vector.
This is the forward perpendicular unit vector of the right oriented vector.
Examples
PulleyJoint.cpp.

Referenced by playrho::d2::RayCast(), and playrho::d2::PolygonShapeConf::SetAsBox().

◆ GetBottomRight()

static constexpr UnitVec playrho::d2::UnitVec::GetBottomRight ( )
inlinestaticconstexprnoexcept

Gets the -45 degree unit vector.

This is the unit vector in the positive X and negative Y quadrant where |X| == |Y|.

◆ GetFwdPerpendicular()

constexpr UnitVec playrho::d2::UnitVec::GetFwdPerpendicular ( ) const
inlineconstexprnoexcept

Gets a vector clockwise (forward-clockwise) perpendicular to this vector.

This returns the unit vector (y, -x).

Returns
A clockwise 90-degree rotation of this vector.
See also
GetRevPerpendicular.

Referenced by playrho::d2::GetFwdPerpendicular().

◆ GetLeft()

static constexpr UnitVec playrho::d2::UnitVec::GetLeft ( )
inlinestaticconstexprnoexcept

Gets the left-ward oriented unit vector.

Note
This is the actual value for the 2/4 turned (180 degree angled) unit vector.
This is the reverse perpendicular unit vector of the top oriented vector.
This is the forward perpendicular unit vector of the bottom oriented vector.
Examples
WorldBody.cpp.

Referenced by playrho::d2::RayCast(), and playrho::d2::PolygonShapeConf::SetAsBox().

◆ GetRevPerpendicular()

constexpr UnitVec playrho::d2::UnitVec::GetRevPerpendicular ( ) const
inlineconstexprnoexcept

Gets a vector counter-clockwise (reverse-clockwise) perpendicular to this vector.

This returns the unit vector (-y, x).

Returns
A counter-clockwise 90-degree rotation of this vector.
See also
GetFwdPerpendicular.

Referenced by playrho::d2::GetRevPerpendicular(), and playrho::d2::GetYAxis().

◆ GetRight()

static constexpr UnitVec playrho::d2::UnitVec::GetRight ( )
inlinestaticconstexprnoexcept

Gets the right-ward oriented unit vector.

Note
This is the value for the 0/4 turned (0 angled) unit vector.
This is the reverse perpendicular unit vector of the bottom oriented vector.
This is the forward perpendicular unit vector of the top oriented vector.
Examples
PrismaticJoint.cpp, Shape.cpp, WheelJoint.cpp, World.cpp, WorldBody.cpp, and WorldContact.cpp.

Referenced by playrho::d2::RayCast(), and playrho::d2::PolygonShapeConf::SetAsBox().

◆ GetTop()

static constexpr UnitVec playrho::d2::UnitVec::GetTop ( )
inlinestaticconstexprnoexcept

Gets the top-ward oriented unit vector.

Note
This is the actual value for the 1/4 turned (90 degree angled) unit vector.
This is the reverse perpendicular unit vector of the right oriented vector.
This is the forward perpendicular unit vector of the left oriented vector.
Examples
GearJoint.cpp.

Referenced by playrho::d2::RayCast(), and playrho::d2::PolygonShapeConf::SetAsBox().

◆ GetTopRight()

static constexpr UnitVec playrho::d2::UnitVec::GetTopRight ( )
inlinestaticconstexprnoexcept

Gets the 45 degree unit vector.

This is the unit vector in the positive X and Y quadrant where X == Y.

Examples
WorldBody.cpp.

◆ operator[]()

constexpr const_reference playrho::d2::UnitVec::operator[] ( size_type  pos) const
inlineconstexprnoexcept

Gets a constant reference to the requested element.

Note
No bounds checking is performed.
Warning
Behavior is undefined if given a position equal to or greater than size().

◆ Rotate()

constexpr UnitVec playrho::d2::UnitVec::Rotate ( UnitVec  amount) const
inlineconstexprnoexcept

Rotates the unit vector by the given amount.

Parameters
amountExpresses the angular difference from the right-ward oriented unit vector to rotate this unit vector by.
Returns
Result of rotating this unit vector by the given amount.

The documentation for this class was generated from the following files: