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

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

Constant reference type.

Definition at line 59 of file UnitVec.hpp.

◆ const_pointer

Constant pointer type.

Definition at line 62 of file UnitVec.hpp.

◆ const_iterator

Constant iterator type.

Definition at line 65 of file UnitVec.hpp.

◆ const_reverse_iterator

Constant reverse iterator type.

Definition at line 68 of file UnitVec.hpp.

◆ 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.

Definition at line 122 of file UnitVec.hpp.

Constructor & Destructor Documentation

◆ UnitVec()

PLAYRHO_CONSTEXPR playrho::d2::UnitVec::UnitVec ( )
inlinedefaultnoexcept

Member Function Documentation

◆ GetRight()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::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()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::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()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::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()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::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()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::GetZero ( )
inlinestaticnoexcept

Gets the non-oriented unit vector.

Definition at line 95 of file UnitVec.hpp.

◆ GetTopRight()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::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()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::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()

static PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::GetDefaultFallback ( )
inlinestaticnoexcept

Gets the default fallback.

Definition at line 115 of file UnitVec.hpp.

◆ Get() [1/2]

template<typename T >
static PolarCoord<T> playrho::d2::UnitVec::Get ( const T  x,
const T  y,
const UnitVec  fallback = GetDefaultFallback() 
)
inlinestaticnoexcept

Gets the unit vector & magnitude from the given parameters.

Definition at line 126 of file UnitVec.hpp.

◆ Get() [2/2]

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.

Definition at line 27 of file UnitVec.cpp.

◆ max_size()

PLAYRHO_CONSTEXPR size_type playrho::d2::UnitVec::max_size ( ) const
inlinenoexcept

Gets the max size.

Definition at line 161 of file UnitVec.hpp.

◆ size()

PLAYRHO_CONSTEXPR size_type playrho::d2::UnitVec::size ( ) const
inlinenoexcept

Gets the size.

Definition at line 164 of file UnitVec.hpp.

◆ empty()

PLAYRHO_CONSTEXPR bool playrho::d2::UnitVec::empty ( ) const
inlinenoexcept

Whether empty.

Note
Always false for N > 0.

Definition at line 168 of file UnitVec.hpp.

◆ begin()

const_iterator playrho::d2::UnitVec::begin ( ) const
inlinenoexcept

Gets a "begin" iterator.

Definition at line 171 of file UnitVec.hpp.

◆ end()

const_iterator playrho::d2::UnitVec::end ( ) const
inlinenoexcept

Gets an "end" iterator.

Definition at line 174 of file UnitVec.hpp.

◆ cbegin()

const_iterator playrho::d2::UnitVec::cbegin ( ) const
inlinenoexcept

Gets a "begin" iterator.

Definition at line 177 of file UnitVec.hpp.

◆ cend()

const_iterator playrho::d2::UnitVec::cend ( ) const
inlinenoexcept

Gets an "end" iterator.

Definition at line 180 of file UnitVec.hpp.

◆ crbegin()

const_reverse_iterator playrho::d2::UnitVec::crbegin ( ) const
inlinenoexcept

Gets a reverse "begin" iterator.

Definition at line 183 of file UnitVec.hpp.

◆ crend()

const_reverse_iterator playrho::d2::UnitVec::crend ( ) const
inlinenoexcept

Gets a reverse "end" iterator.

Definition at line 189 of file UnitVec.hpp.

◆ rbegin()

const_reverse_iterator playrho::d2::UnitVec::rbegin ( ) const
inlinenoexcept

Gets a reverse "begin" iterator.

Definition at line 195 of file UnitVec.hpp.

◆ rend()

const_reverse_iterator playrho::d2::UnitVec::rend ( ) const
inlinenoexcept

Gets a reverse "end" iterator.

Definition at line 201 of file UnitVec.hpp.

◆ operator[]()

PLAYRHO_CONSTEXPR const_reference playrho::d2::UnitVec::operator[] ( size_type  pos) const
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()

PLAYRHO_CONSTEXPR const_reference playrho::d2::UnitVec::at ( size_type  pos) const
inline

Gets a constant reference to the requested element.

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

Definition at line 217 of file UnitVec.hpp.

◆ data()

PLAYRHO_CONSTEXPR const_pointer playrho::d2::UnitVec::data ( ) const
inlinenoexcept

Direct access to data.

Definition at line 227 of file UnitVec.hpp.

◆ GetX()

PLAYRHO_CONSTEXPR auto playrho::d2::UnitVec::GetX ( ) const
inlinenoexcept

Gets the "X" value.

Definition at line 233 of file UnitVec.hpp.

◆ GetY()

PLAYRHO_CONSTEXPR auto playrho::d2::UnitVec::GetY ( ) const
inlinenoexcept

Gets the "Y" value.

Definition at line 236 of file UnitVec.hpp.

◆ FlipXY()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::FlipXY ( ) const
inlinenoexcept

Flips the X and Y values.

Definition at line 239 of file UnitVec.hpp.

◆ FlipX()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::FlipX ( ) const
inlinenoexcept

Flips the X value.

Definition at line 242 of file UnitVec.hpp.

◆ FlipY()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::FlipY ( ) const
inlinenoexcept

Flips the Y value.

Definition at line 245 of file UnitVec.hpp.

◆ Rotate()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::Rotate ( UnitVec  amount) const
inlinenoexcept

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.

Definition at line 254 of file UnitVec.hpp.

◆ GetRevPerpendicular()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::GetRevPerpendicular ( ) const
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()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::GetFwdPerpendicular ( ) const
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-()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::operator- ( ) const
inlinenoexcept

Negation operator.

Definition at line 281 of file UnitVec.hpp.

◆ operator+()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::operator+ ( ) const
inlinenoexcept

Positive operator.

Definition at line 284 of file UnitVec.hpp.

◆ Absolute()

PLAYRHO_CONSTEXPR UnitVec playrho::d2::UnitVec::Absolute ( ) const
inlinenoexcept

Gets the absolute value.

Definition at line 287 of file UnitVec.hpp.


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