SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
SA::Vec2< T > Struct Template Reference

Vector 2 Sapphire's class. More...

#include <Vector2.hpp>

Public Types

using Type = T
 Scalar type of the Vector.
 

Public Member Functions

 Vec2 ()=default
 Default constructor.
 
constexpr Vec2 (T _x, T _y) noexcept
 Value constructor.
 
constexpr Vec2 (T _scale) noexcept
 Scale Value constructor.
 
 Vec2 (Vec2 &&)=default
 Default move constructor.
 
 Vec2 (const Vec2 &)=default
 Default copy constructor.
 
template<typename TIn >
constexpr Vec2 (const Vec2< TIn > &_other) noexcept
 Value constructor from another Vec2 type.
 
template<typename TIn >
constexpr Vec2 (const Vec3< TIn > &_other) noexcept
 Value constructor from Vec3.
 
constexpr bool IsZero () const noexcept
 Whether this vector is a zero vector.
 
constexpr bool Equals (const Vec2 &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
 Compare 2 vector.
 
constexpr bool operator== (const Vec2 &_rhs) const noexcept
 Compare 2 vector equality.
 
constexpr bool operator!= (const Vec2 &_rhs) const noexcept
 Compare 2 vector inequality.
 
T * Data () noexcept
 Getter of vector data
 
const T * Data () const noexcept
  Const Getter of vector data
 
T & operator[] (uint32_t _index)
 Access operator by index: x, y using 0, 1.
 
const T & operator[] (uint32_t _index) const
  Const Access operator by index: x, y using 0, 1.
 
constexpr T Length () const
 Getter of the /b length of this vector.
 
constexpr T SqrLength () const noexcept
 Getter of the Squared Length of this vector.
 
Vec2Normalize ()
 Normalize this vector.
 
Vec2 GetNormalized () const
 Normalize this vector.
 
constexpr bool IsNormalized () const noexcept
 Whether this vector is normalized.
 
Vec2 Reflect (const Vec2 &_normal, float _elasticity=1.0f) const noexcept
 Reflect this vector over the normal.
 
Vec2 ProjectOnTo (const Vec2 &_other) const noexcept
 Project this vector onto an other vector.
 
Vec2 ProjectOnToNormal (const Vec2 &_normal) const noexcept
 Project this vector onto s normal.
 
Vec2 Perpendicular () const noexcept
 Compute the perpendicular vector to this vector.
 
Vec2operator= (Vec2 &&)=default
 Default assignment move operator.
 
Vec2operator= (const Vec2 &)=default
 Default assignment copy operator.
 
constexpr Vec2 operator- () const noexcept
 Getter of the opposite signed vector.
 
constexpr Vec2 operator* (T _scale) const noexcept
 Scale each vector axis by _scale.
 
Vec2 operator/ (T _scale) const
  Inverse Scale each vector axis by _scale.
 
constexpr Vec2 operator+ (const Vec2 &_rhs) const noexcept
 Add term by term vector values.
 
constexpr Vec2 operator- (const Vec2 &_rhs) const noexcept
 Subtract term by term vector values.
 
constexpr Vec2 operator* (const Vec2 &_rhs) const noexcept
 Multiply term by term vector values.
 
Vec2 operator/ (const Vec2 &_rhs) const
 Divide term by term vector values.
 
constexpr T operator| (const Vec2 &_rhs) const noexcept
 Compute the Dot product between this and _rhs.
 
constexpr T operator^ (const Vec2 &_rhs) const noexcept
 Compute the Cross product between this and _rhs.
 
Vec2operator*= (T _scale) noexcept
 Scale each vector axis by _scale.
 
Vec2operator/= (T _scale)
  Inverse Scale each vector axis by _scale.
 
Vec2operator+= (const Vec2 &_rhs) noexcept
 Add term by term vector values.
 
Vec2operator-= (const Vec2 &_rhs) noexcept
 Substract term by term vector values.
 
Vec2 operator*= (const Vec2 &_rhs) noexcept
 Multiply term by term vector values.
 
Vec2 operator/= (const Vec2 &_rhs)
 Divide term by term vector values.
 

Static Public Member Functions

static constexpr T Dot (const Vec2 &_lhs, const Vec2 &_rhs) noexcept
 Compute the Dot product between _lhs and _rhs.
 
static constexpr T Cross (const Vec2 &_lhs, const Vec2 &_rhs) noexcept
 Compute the Cross product between _lhs and _rhs.
 
static Deg< T > Angle (const Vec2 &_start, const Vec2 &_end) noexcept
 Compute the Signed Angle between _start and _end.
 
static Deg< T > AngleUnsigned (const Vec2 &_start, const Vec2 &_end) noexcept
 Compute the Unsigned Angle between _start and _end.
 
static constexpr T Dist (const Vec2 &_start, const Vec2 &_end)
 Compute the Distance between _start and _end.
 
static constexpr T SqrDist (const Vec2 &_start, const Vec2 &_end) noexcept
 Compute the Squared Distance between _start and _end.
 
static constexpr Vec2 Dir (const Vec2 &_start, const Vec2 &_end) noexcept
 Compute the Non-Normalized Direction from _start to _end.
 
static constexpr Vec2 DirN (const Vec2 &_start, const Vec2 &_end)
 Compute the Normalized Direction from _start to _end.
 
static Vec2 Lerp (const Vec2 &_start, const Vec2 &_end, float _alpha) noexcept
  Clamped Lerp from _start to _end at _alpha.
 
static Vec2 LerpUnclamped (const Vec2 &_start, const Vec2 &_end, float _alpha) noexcept
  Unclamped Lerp from _start to _end at _alpha.
 
static Vec2 SLerp (const Vec2 &_start, const Vec2 &_end, float _alpha) noexcept
  Clamped SLerp from _start to _end at _alpha.
 
static Vec2 SLerpUnclamped (const Vec2 &_start, const Vec2 &_end, float _alpha) noexcept
  Unclamped SLerp from _start to _end at _alpha.
 

Public Attributes

x = T()
 Vector's X component (axis value).
 
y = T()
 Vector's Y component (axis value).
 

Static Public Attributes

static const Vec2 Zero
 Zero vector constant { 0, 0 }.
 
static const Vec2 One
 One vector constant { 1, 1 }.
 
static const Vec2 Right
 Right vector constant { 1, 0 }.
 
static const Vec2 Left
 Left vector constant { -1, 0 }.
 
static const Vec2 Up
 Up vector constant { 0, 1 }.
 
static const Vec2 Down
 Down vector constant { 0, -1 }.
 

Detailed Description

template<typename T>
struct SA::Vec2< T >

Vector 2 Sapphire's class.

Template Parameters
TType of the vector.

Constructor & Destructor Documentation

◆ Vec2() [1/4]

template<typename T >
constexpr SA::Vec2< T >::Vec2 ( T _x,
T _y )
constexprnoexcept

Value constructor.

Parameters
[in]_xX axis value.
[in]_yY axis value.

◆ Vec2() [2/4]

template<typename T >
constexpr SA::Vec2< T >::Vec2 ( T _scale)
constexprnoexcept

Scale Value constructor.

Parameters
[in]_scaleAxis value to apply on all axis.

◆ Vec2() [3/4]

template<typename T >
template<typename TIn >
constexpr SA::Vec2< T >::Vec2 ( const Vec2< TIn > & _other)
constexprnoexcept

Value constructor from another Vec2 type.

Template Parameters
TInType of the input Vec2.
Parameters
[in]_otherVec2 to construct from.

◆ Vec2() [4/4]

template<typename T >
template<typename TIn >
constexpr SA::Vec2< T >::Vec2 ( const Vec3< TIn > & _other)
constexprnoexcept

Value constructor from Vec3.

Template Parameters
TInType of the input Vec3.
Parameters
[in]_otherVec3 to construct from.

Member Function Documentation

◆ Angle()

template<typename T >
static Deg< T > SA::Vec2< T >::Angle ( const Vec2< T > & _start,
const Vec2< T > & _end )
staticnoexcept

Compute the Signed Angle between _start and _end.

Parameters
[in]_startStarting point to compute angle from.
[in]_endEnding point to compute angle to.
Returns
Signed Angle between _start and _end.

◆ AngleUnsigned()

template<typename T >
static Deg< T > SA::Vec2< T >::AngleUnsigned ( const Vec2< T > & _start,
const Vec2< T > & _end )
staticnoexcept

Compute the Unsigned Angle between _start and _end.

Parameters
[in]_startStarting point to compute angle from.
[in]_endEnding point to compute angle to.
Returns
Unsigned Angle between _start and _end.

◆ Cross()

template<typename T >
static constexpr T SA::Vec2< T >::Cross ( const Vec2< T > & _lhs,
const Vec2< T > & _rhs )
staticconstexprnoexcept

Compute the Cross product between _lhs and _rhs.

Parameters
[in]_lhsLeft hand side operand to compute cross product with.
[in]_rhsRight hand side operand to compute cross product with.
Returns
Cross product between _lhs and _rhs.

◆ Data() [1/2]

template<typename T >
const T * SA::Vec2< T >::Data ( ) const
noexcept

Const Getter of vector data

Returns
this vector as a const T*.

◆ Data() [2/2]

template<typename T >
T * SA::Vec2< T >::Data ( )
noexcept

Getter of vector data

Returns
this vector as a T*.

◆ Dir()

template<typename T >
static constexpr Vec2 SA::Vec2< T >::Dir ( const Vec2< T > & _start,
const Vec2< T > & _end )
staticconstexprnoexcept

Compute the Non-Normalized Direction from _start to _end.

Direction get not normalized. Use DirN instead.

Parameters
[in]_startStarting point to compute direction from.
[in]_endending point to compute direction to.
Returns
Non-Normalized Direction from _start to _end.

◆ DirN()

template<typename T >
static constexpr Vec2 SA::Vec2< T >::DirN ( const Vec2< T > & _start,
const Vec2< T > & _end )
staticconstexpr

Compute the Normalized Direction from _start to _end.

Parameters
[in]_startStarting point to compute direction from.
[in]_endending point to compute direction to.
Returns
Normalized Direction from _start to _end.

◆ Dist()

template<typename T >
static constexpr T SA::Vec2< T >::Dist ( const Vec2< T > & _start,
const Vec2< T > & _end )
staticconstexpr

Compute the Distance between _start and _end.

Parameters
[in]_startLeft hand side operand to compute distance with.
[in]_endRight hand side operand to compute distance with.
Returns
Distance between _start and _end.

◆ Dot()

template<typename T >
static constexpr T SA::Vec2< T >::Dot ( const Vec2< T > & _lhs,
const Vec2< T > & _rhs )
staticconstexprnoexcept

Compute the Dot product between _lhs and _rhs.

Parameters
[in]_lhsLeft hand side operand to compute dot product with.
[in]_rhsRight hand side operand to compute dot product with.
Returns
Dot product between _lhs and _rhs.

◆ Equals()

template<typename T >
constexpr bool SA::Vec2< T >::Equals ( const Vec2< T > & _other,
T _epsilon = std::numeric_limits< T >::epsilon() ) const
constexprnoexcept

Compare 2 vector.

Parameters
[in]_otherOther vector to compare to.
[in]_epsilonEpsilon value for threshold comparison.
Returns
Whether this and _other are equal.

◆ GetNormalized()

template<typename T >
Vec2 SA::Vec2< T >::GetNormalized ( ) const

Normalize this vector.

Returns
new normalized vector.

◆ IsNormalized()

template<typename T >
constexpr bool SA::Vec2< T >::IsNormalized ( ) const
constexprnoexcept

Whether this vector is normalized.

Returns
True if this vector is normalized, otherwise false.

◆ IsZero()

template<typename T >
constexpr bool SA::Vec2< T >::IsZero ( ) const
constexprnoexcept

Whether this vector is a zero vector.

Returns
True if this is a zero vector.

◆ Length()

template<typename T >
constexpr T SA::Vec2< T >::Length ( ) const
constexpr

Getter of the /b length of this vector.

Returns
Length of this vector.

◆ Lerp()

template<typename T >
static Vec2 SA::Vec2< T >::Lerp ( const Vec2< T > & _start,
const Vec2< T > & _end,
float _alpha )
staticnoexcept

Clamped Lerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Linear_interpolation

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ LerpUnclamped()

template<typename T >
static Vec2 SA::Vec2< T >::LerpUnclamped ( const Vec2< T > & _start,
const Vec2< T > & _end,
float _alpha )
staticnoexcept

Unclamped Lerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Linear_interpolation

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ Normalize()

template<typename T >
Vec2 & SA::Vec2< T >::Normalize ( )

Normalize this vector.

Returns
self vector normalized.

◆ operator!=()

template<typename T >
constexpr bool SA::Vec2< T >::operator!= ( const Vec2< T > & _rhs) const
constexprnoexcept

Compare 2 vector inequality.

Parameters
[in]_rhsOther vector to compare to.
Returns
Whether this and _rhs are non-equal.

◆ operator*() [1/2]

template<typename T >
constexpr Vec2 SA::Vec2< T >::operator* ( const Vec2< T > & _rhs) const
constexprnoexcept

Multiply term by term vector values.

Parameters
[in]_rhsVector to multiply.
Returns
new vector result.

◆ operator*() [2/2]

template<typename T >
constexpr Vec2 SA::Vec2< T >::operator* ( T _scale) const
constexprnoexcept

Scale each vector axis by _scale.

Parameters
[in]_scaleScale value to apply on all axis.
Returns
new vector scaled.

◆ operator*=() [1/2]

template<typename T >
Vec2 SA::Vec2< T >::operator*= ( const Vec2< T > & _rhs)
noexcept

Multiply term by term vector values.

Parameters
[in]_rhsVector to multiply.
Returns
self vector result.

◆ operator*=() [2/2]

template<typename T >
Vec2 & SA::Vec2< T >::operator*= ( T _scale)
noexcept

Scale each vector axis by _scale.

Parameters
[in]_scaleScale value to apply on all axis.
Returns
self vector scaled.

◆ operator+()

template<typename T >
constexpr Vec2 SA::Vec2< T >::operator+ ( const Vec2< T > & _rhs) const
constexprnoexcept

Add term by term vector values.

Parameters
[in]_rhsVector to add.
Returns
new vector result.

◆ operator+=()

template<typename T >
Vec2 & SA::Vec2< T >::operator+= ( const Vec2< T > & _rhs)
noexcept

Add term by term vector values.

Parameters
[in]_rhsVector to add.
Returns
self vector result.

◆ operator-() [1/2]

template<typename T >
constexpr Vec2 SA::Vec2< T >::operator- ( ) const
constexprnoexcept

Getter of the opposite signed vector.

Returns
new opposite signed vector.

◆ operator-() [2/2]

template<typename T >
constexpr Vec2 SA::Vec2< T >::operator- ( const Vec2< T > & _rhs) const
constexprnoexcept

Subtract term by term vector values.

Parameters
[in]_rhsVector to substract.
Returns
new vector result.

◆ operator-=()

template<typename T >
Vec2 & SA::Vec2< T >::operator-= ( const Vec2< T > & _rhs)
noexcept

Substract term by term vector values.

Parameters
[in]_rhsVector to substract.
Returns
self vector result.

◆ operator/() [1/2]

template<typename T >
Vec2 SA::Vec2< T >::operator/ ( const Vec2< T > & _rhs) const

Divide term by term vector values.

Parameters
[in]_rhsVector to divide.
Returns
new vector result.

◆ operator/() [2/2]

template<typename T >
Vec2 SA::Vec2< T >::operator/ ( T _scale) const

Inverse Scale each vector axis by _scale.

Parameters
[in]_scaleInverse scale value to apply on all axis.
Returns
new vector inverse-scaled.

◆ operator/=() [1/2]

template<typename T >
Vec2 SA::Vec2< T >::operator/= ( const Vec2< T > & _rhs)

Divide term by term vector values.

Parameters
[in]_rhsVector to divide.
Returns
self vector result.

◆ operator/=() [2/2]

template<typename T >
Vec2 & SA::Vec2< T >::operator/= ( T _scale)

Inverse Scale each vector axis by _scale.

Parameters
[in]_scaleScale value to apply on all axis.
Returns
self vector inverse-scaled.

◆ operator=() [1/2]

template<typename T >
Vec2 & SA::Vec2< T >::operator= ( const Vec2< T > & )
default

Default assignment copy operator.

Returns
self vector assigned.

◆ operator=() [2/2]

template<typename T >
Vec2 & SA::Vec2< T >::operator= ( Vec2< T > && )
default

Default assignment move operator.

Returns
self vector assigned.

◆ operator==()

template<typename T >
constexpr bool SA::Vec2< T >::operator== ( const Vec2< T > & _rhs) const
constexprnoexcept

Compare 2 vector equality.

Parameters
[in]_rhsOther vector to compare to.
Returns
Whether this and _rhs are equal.

◆ operator[]() [1/2]

template<typename T >
T & SA::Vec2< T >::operator[] ( uint32_t _index)

Access operator by index: x, y using 0, 1.

Parameters
[in]_indexIndex to access.
Returns
T value at index.

◆ operator[]() [2/2]

template<typename T >
const T & SA::Vec2< T >::operator[] ( uint32_t _index) const

Const Access operator by index: x, y using 0, 1.

Parameters
[in]_indexIndex to access.
Returns
T value at index.

◆ operator^()

template<typename T >
constexpr T SA::Vec2< T >::operator^ ( const Vec2< T > & _rhs) const
constexprnoexcept

Compute the Cross product between this and _rhs.

Parameters
[in]_rhsRight hand side operand vector to compute cross product with.
Returns
Cross product between this vector and _other.

◆ operator|()

template<typename T >
constexpr T SA::Vec2< T >::operator| ( const Vec2< T > & _rhs) const
constexprnoexcept

Compute the Dot product between this and _rhs.

Parameters
[in]_rhsRight hand side operand vector to compute dot product with.
Returns
Dot product between this vector and _other.

◆ Perpendicular()

template<typename T >
Vec2 SA::Vec2< T >::Perpendicular ( ) const
noexcept

Compute the perpendicular vector to this vector.

Rotate this vector 90 degrees in trigonomety direction (counter-clockwise).

Returns
new vector rotated.

◆ ProjectOnTo()

template<typename T >
Vec2 SA::Vec2< T >::ProjectOnTo ( const Vec2< T > & _other) const
noexcept

Project this vector onto an other vector.

Reference: https://en.wikipedia.org/wiki/Vector_projection

Parameters
[in]_otherVector used for projection.
Returns
new vector projected.

◆ ProjectOnToNormal()

template<typename T >
Vec2 SA::Vec2< T >::ProjectOnToNormal ( const Vec2< T > & _normal) const
noexcept

Project this vector onto s normal.

Assume _normal is normalized. Use ProjectOnTo() for non normalized vector. Reference: https://en.wikipedia.org/wiki/Vector_projection

Parameters
[in]_normalNormal used for projection.
Returns
new vector projected.

◆ Reflect()

template<typename T >
Vec2 SA::Vec2< T >::Reflect ( const Vec2< T > & _normal,
float _elasticity = 1.0f ) const
noexcept

Reflect this vector over the normal.

Parameters
[in]_normalNormal used for reflection.
[in]_elasticityElasticity reflection coefficient (use 1.0f for full reflection).
Returns
new vector reflected.

◆ SLerp()

template<typename T >
static Vec2 SA::Vec2< T >::SLerp ( const Vec2< T > & _start,
const Vec2< T > & _end,
float _alpha )
staticnoexcept

Clamped SLerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Slerp

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ SLerpUnclamped()

template<typename T >
static Vec2 SA::Vec2< T >::SLerpUnclamped ( const Vec2< T > & _start,
const Vec2< T > & _end,
float _alpha )
staticnoexcept

Unclamped SLerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Slerp

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ SqrDist()

template<typename T >
static constexpr T SA::Vec2< T >::SqrDist ( const Vec2< T > & _start,
const Vec2< T > & _end )
staticconstexprnoexcept

Compute the Squared Distance between _start and _end.

Parameters
[in]_startLeft hand side operand to compute squared distance with.
[in]_endRight hand side operand to compute squared distance with.
Returns
Squared Distance between _start and _rhs.

◆ SqrLength()

template<typename T >
constexpr T SA::Vec2< T >::SqrLength ( ) const
constexprnoexcept

Getter of the Squared Length of this vector.

Returns
Squared length of this vector.

The documentation for this struct was generated from the following file: