2-D unit vector. More...
#include <UnitVec.hpp>
Public Types | |
using | value_type = Real |
Value type used for the coordinate values of this vector. More... | |
using | size_type = std::size_t |
Size type. More... | |
using | const_reference = const value_type & |
Constant reference type. More... | |
using | const_pointer = const value_type * |
Constant pointer type. More... | |
using | const_iterator = const value_type * |
Constant iterator type. More... | |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Constant reverse iterator type. More... | |
template<typename T > | |
using | PolarCoord = std::enable_if_t< IsArithmetic< T >::value, std::pair< UnitVec, T > > |
Polar coordinate. More... | |
Public Member Functions | |
PLAYRHO_CONSTEXPR | UnitVec () noexcept=default |
PLAYRHO_CONSTEXPR size_type | max_size () const noexcept |
Gets the max size. More... | |
PLAYRHO_CONSTEXPR size_type | size () const noexcept |
Gets the size. More... | |
PLAYRHO_CONSTEXPR bool | empty () const noexcept |
Whether empty. More... | |
const_iterator | begin () const noexcept |
Gets a "begin" iterator. More... | |
const_iterator | end () const noexcept |
Gets an "end" iterator. More... | |
const_iterator | cbegin () const noexcept |
Gets a "begin" iterator. More... | |
const_iterator | cend () const noexcept |
Gets an "end" iterator. More... | |
const_reverse_iterator | crbegin () const noexcept |
Gets a reverse "begin" iterator. More... | |
const_reverse_iterator | crend () const noexcept |
Gets a reverse "end" iterator. More... | |
const_reverse_iterator | rbegin () const noexcept |
Gets a reverse "begin" iterator. More... | |
const_reverse_iterator | rend () const noexcept |
Gets a reverse "end" iterator. More... | |
PLAYRHO_CONSTEXPR const_reference | operator[] (size_type pos) const noexcept |
Gets a constant reference to the requested element. More... | |
PLAYRHO_CONSTEXPR const_reference | at (size_type pos) const |
Gets a constant reference to the requested element. More... | |
PLAYRHO_CONSTEXPR const_pointer | data () const noexcept |
Direct access to data. More... | |
PLAYRHO_CONSTEXPR auto | GetX () const noexcept |
Gets the "X" value. More... | |
PLAYRHO_CONSTEXPR auto | GetY () const noexcept |
Gets the "Y" value. More... | |
PLAYRHO_CONSTEXPR UnitVec | FlipXY () const noexcept |
Flips the X and Y values. More... | |
PLAYRHO_CONSTEXPR UnitVec | FlipX () const noexcept |
Flips the X value. More... | |
PLAYRHO_CONSTEXPR UnitVec | FlipY () const noexcept |
Flips the Y value. More... | |
PLAYRHO_CONSTEXPR UnitVec | Rotate (UnitVec amount) const noexcept |
Rotates the unit vector by the given amount. More... | |
PLAYRHO_CONSTEXPR UnitVec | GetRevPerpendicular () const noexcept |
Gets a vector counter-clockwise (reverse-clockwise) perpendicular to this vector. More... | |
PLAYRHO_CONSTEXPR UnitVec | GetFwdPerpendicular () const noexcept |
Gets a vector clockwise (forward-clockwise) perpendicular to this vector. More... | |
PLAYRHO_CONSTEXPR UnitVec | operator- () const noexcept |
Negation operator. More... | |
PLAYRHO_CONSTEXPR UnitVec | operator+ () const noexcept |
Positive operator. More... | |
PLAYRHO_CONSTEXPR UnitVec | Absolute () const noexcept |
Gets the absolute value. More... | |
Static Public Member Functions | |
static PLAYRHO_CONSTEXPR UnitVec | GetRight () noexcept |
Gets the right-ward oriented unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetTop () noexcept |
Gets the top-ward oriented unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetLeft () noexcept |
Gets the left-ward oriented unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetBottom () noexcept |
Gets the bottom-ward oriented unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetZero () noexcept |
Gets the non-oriented unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetTopRight () noexcept |
Gets the 45 degree unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetBottomRight () noexcept |
Gets the -45 degree unit vector. More... | |
static PLAYRHO_CONSTEXPR UnitVec | GetDefaultFallback () noexcept |
Gets the default fallback. More... | |
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. More... | |
static UnitVec | Get (const Angle angle) noexcept |
Gets the given angled unit vector. More... | |
Detailed Description
2-D unit vector.
This is a 2-dimensional directional vector.
- Examples
- World.cpp.
Definition at line 49 of file UnitVec.hpp.
Member Typedef Documentation
◆ value_type
using playrho::d2::UnitVec::value_type = Real |
Value type used for the coordinate values of this vector.
Definition at line 53 of file UnitVec.hpp.
◆ size_type
using playrho::d2::UnitVec::size_type = std::size_t |
Size type.
Definition at line 56 of file UnitVec.hpp.
◆ const_reference
using playrho::d2::UnitVec::const_reference = const value_type& |
Constant reference type.
Definition at line 59 of file UnitVec.hpp.
◆ const_pointer
using playrho::d2::UnitVec::const_pointer = const value_type* |
Constant pointer type.
Definition at line 62 of file UnitVec.hpp.
◆ const_iterator
using playrho::d2::UnitVec::const_iterator = const value_type* |
Constant iterator type.
Definition at line 65 of file UnitVec.hpp.
◆ const_reverse_iterator
using playrho::d2::UnitVec::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Constant reverse iterator type.
Definition at line 68 of file UnitVec.hpp.
◆ PolarCoord
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.
Definition at line 122 of file UnitVec.hpp.
Constructor & Destructor Documentation
◆ UnitVec()
|
inlinedefaultnoexcept |
Member Function Documentation
◆ GetRight()
|
inlinestaticnoexcept |
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.
Definition at line 74 of file UnitVec.hpp.
◆ GetTop()
|
inlinestaticnoexcept |
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.
Definition at line 80 of file UnitVec.hpp.
◆ GetLeft()
|
inlinestaticnoexcept |
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.
Definition at line 86 of file UnitVec.hpp.
◆ GetBottom()
|
inlinestaticnoexcept |
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.
Definition at line 92 of file UnitVec.hpp.
◆ GetZero()
|
inlinestaticnoexcept |
Gets the non-oriented unit vector.
Definition at line 95 of file UnitVec.hpp.
◆ GetTopRight()
|
inlinestaticnoexcept |
Gets the 45 degree unit vector.
This is the unit vector in the positive X and Y quadrant where X == Y.
Definition at line 99 of file UnitVec.hpp.
◆ GetBottomRight()
|
inlinestaticnoexcept |
Gets the -45 degree unit vector.
This is the unit vector in the positive X and negative Y quadrant where |X| == |Y|.
Definition at line 108 of file UnitVec.hpp.
◆ GetDefaultFallback()
|
inlinestaticnoexcept |
Gets the default fallback.
Definition at line 115 of file UnitVec.hpp.
◆ Get() [1/2]
|
inlinestaticnoexcept |
Gets the unit vector & magnitude from the given parameters.
Definition at line 126 of file UnitVec.hpp.
◆ Get() [2/2]
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.
Definition at line 27 of file UnitVec.cpp.
◆ max_size()
|
inlinenoexcept |
Gets the max size.
Definition at line 161 of file UnitVec.hpp.
◆ size()
|
inlinenoexcept |
Gets the size.
Definition at line 164 of file UnitVec.hpp.
◆ empty()
|
inlinenoexcept |
◆ begin()
|
inlinenoexcept |
Gets a "begin" iterator.
Definition at line 171 of file UnitVec.hpp.
◆ end()
|
inlinenoexcept |
Gets an "end" iterator.
Definition at line 174 of file UnitVec.hpp.
◆ cbegin()
|
inlinenoexcept |
Gets a "begin" iterator.
Definition at line 177 of file UnitVec.hpp.
◆ cend()
|
inlinenoexcept |
Gets an "end" iterator.
Definition at line 180 of file UnitVec.hpp.
◆ crbegin()
|
inlinenoexcept |
Gets a reverse "begin" iterator.
Definition at line 183 of file UnitVec.hpp.
◆ crend()
|
inlinenoexcept |
Gets a reverse "end" iterator.
Definition at line 189 of file UnitVec.hpp.
◆ rbegin()
|
inlinenoexcept |
Gets a reverse "begin" iterator.
Definition at line 195 of file UnitVec.hpp.
◆ rend()
|
inlinenoexcept |
Gets a reverse "end" iterator.
Definition at line 201 of file UnitVec.hpp.
◆ operator[]()
|
inlinenoexcept |
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().
Definition at line 209 of file UnitVec.hpp.
◆ at()
|
inline |
Gets a constant reference to the requested element.
- Exceptions
-
InvalidArgument if given a position that's >= size().
Definition at line 217 of file UnitVec.hpp.
◆ data()
|
inlinenoexcept |
Direct access to data.
Definition at line 227 of file UnitVec.hpp.
◆ GetX()
|
inlinenoexcept |
Gets the "X" value.
Definition at line 233 of file UnitVec.hpp.
◆ GetY()
|
inlinenoexcept |
Gets the "Y" value.
Definition at line 236 of file UnitVec.hpp.
◆ FlipXY()
|
inlinenoexcept |
Flips the X and Y values.
Definition at line 239 of file UnitVec.hpp.
◆ FlipX()
|
inlinenoexcept |
Flips the X value.
Definition at line 242 of file UnitVec.hpp.
◆ FlipY()
|
inlinenoexcept |
Flips the Y value.
Definition at line 245 of file UnitVec.hpp.
◆ Rotate()
|
inlinenoexcept |
Rotates the unit vector by the given amount.
- Parameters
-
amount Expresses 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.
Definition at line 254 of file UnitVec.hpp.
◆ GetRevPerpendicular()
|
inlinenoexcept |
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.
Definition at line 264 of file UnitVec.hpp.
◆ GetFwdPerpendicular()
|
inlinenoexcept |
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.
Definition at line 274 of file UnitVec.hpp.
◆ operator-()
|
inlinenoexcept |
Negation operator.
Definition at line 281 of file UnitVec.hpp.
◆ operator+()
|
inlinenoexcept |
Positive operator.
Definition at line 284 of file UnitVec.hpp.
◆ Absolute()
|
inlinenoexcept |
Gets the absolute value.
Definition at line 287 of file UnitVec.hpp.
The documentation for this class was generated from the following files:
- Common/UnitVec.hpp
- Common/UnitVec.cpp