RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::Maths::Vector2D< T > Struct Template Reference

2D vector; arithmetic operators work component-wise, with a vector or a scalar. More...

#include <RST/maths/Vector.hpp>

Public Member Functions

constexpr Vector2D () noexcept=default
 
constexpr Vector2D (T xValue, T yValue) noexcept
 
constexpr void set (const T &newX, const T &newY) noexcept
 
constexpr T getX () const noexcept
 
constexpr T getY () const noexcept
 
constexpr T & operator[] (std::size_t n) noexcept
 
constexpr const T & operator[] (std::size_t n) const noexcept
 
constexpr T * data () noexcept
 
constexpr const T * data () const noexcept
 
constexpr Vector2D operator+ () const noexcept
 
constexpr Vector2D operator- () const noexcept
 
constexpr Vector2D & operator+= (const Vector2D &v) noexcept
 
constexpr Vector2D & operator-= (const Vector2D &v) noexcept
 
constexpr Vector2D & operator*= (const Vector2D &v) noexcept
 
constexpr Vector2D & operator/= (const Vector2D &v) noexcept
 
constexpr Vector2D & operator*= (T s) noexcept
 
constexpr Vector2D & operator/= (T s) noexcept
 
constexpr Vector2D & operator+= (T s) noexcept
 
constexpr Vector2D & operator-= (T s) noexcept
 
constexpr bool operator== (const Vector2D &) const noexcept=default
 
constexpr T dot (const Vector2D &v) const noexcept
 
constexpr T cross (const Vector2D &v) const noexcept
 Z component of the 3D cross product, positive when v is counterclockwise from this vector.
 
constexpr Vector2D perpendicular () const noexcept
 This vector rotated by 90 degrees counterclockwise.
 
constexpr auto lengthSquared () const noexcept
 
constexpr auto length () const noexcept
 
constexpr auto distanceSquared (const Vector2D &v) const noexcept
 
constexpr auto distance (const Vector2D &v) const noexcept
 
constexpr Vector2D & normalize () noexcept
 Scales this vector to length 1; a zero vector is left unchanged.
 
constexpr Vector2D normalized () const noexcept
 
template<typename U >
constexpr Vector2D< U > to () const noexcept
 Converts the components, such as v.to<int>().
 
constexpr Vector2D min (const Vector2D &v) const noexcept
 Component-wise minimum.
 
constexpr Vector2D max (const Vector2D &v) const noexcept
 Component-wise maximum.
 

Public Attributes

T x {}
 
T y {}
 

Detailed Description

template<typename T>
struct RST::Maths::Vector2D< T >

2D vector; arithmetic operators work component-wise, with a vector or a scalar.

Examples
graphics.cpp.

Constructor & Destructor Documentation

◆ Vector2D() [1/2]

template<typename T >
constexpr RST::Maths::Vector2D< T >::Vector2D ( )
constexprdefaultnoexcept

◆ Vector2D() [2/2]

template<typename T >
constexpr RST::Maths::Vector2D< T >::Vector2D ( T  xValue,
T  yValue 
)
inlineconstexprnoexcept

Member Function Documentation

◆ set()

template<typename T >
constexpr void RST::Maths::Vector2D< T >::set ( const T &  newX,
const T &  newY 
)
inlineconstexprnoexcept

◆ getX()

template<typename T >
constexpr T RST::Maths::Vector2D< T >::getX ( ) const
inlineconstexprnoexcept

◆ getY()

template<typename T >
constexpr T RST::Maths::Vector2D< T >::getY ( ) const
inlineconstexprnoexcept

◆ operator[]() [1/2]

template<typename T >
constexpr T & RST::Maths::Vector2D< T >::operator[] ( std::size_t  n)
inlineconstexprnoexcept

◆ operator[]() [2/2]

template<typename T >
constexpr const T & RST::Maths::Vector2D< T >::operator[] ( std::size_t  n) const
inlineconstexprnoexcept

◆ data() [1/2]

template<typename T >
constexpr T * RST::Maths::Vector2D< T >::data ( )
inlineconstexprnoexcept

◆ data() [2/2]

template<typename T >
constexpr const T * RST::Maths::Vector2D< T >::data ( ) const
inlineconstexprnoexcept

◆ operator+()

template<typename T >
constexpr Vector2D RST::Maths::Vector2D< T >::operator+ ( ) const
inlineconstexprnoexcept

◆ operator-()

template<typename T >
constexpr Vector2D RST::Maths::Vector2D< T >::operator- ( ) const
inlineconstexprnoexcept

◆ operator+=() [1/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator+= ( const Vector2D< T > &  v)
inlineconstexprnoexcept

◆ operator-=() [1/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator-= ( const Vector2D< T > &  v)
inlineconstexprnoexcept

◆ operator*=() [1/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator*= ( const Vector2D< T > &  v)
inlineconstexprnoexcept

◆ operator/=() [1/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator/= ( const Vector2D< T > &  v)
inlineconstexprnoexcept

◆ operator*=() [2/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator*= ( T  s)
inlineconstexprnoexcept

◆ operator/=() [2/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator/= ( T  s)
inlineconstexprnoexcept

◆ operator+=() [2/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator+= ( T  s)
inlineconstexprnoexcept

◆ operator-=() [2/2]

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::operator-= ( T  s)
inlineconstexprnoexcept

◆ operator==()

template<typename T >
constexpr bool RST::Maths::Vector2D< T >::operator== ( const Vector2D< T > &  ) const
constexprdefaultnoexcept

◆ dot()

template<typename T >
constexpr T RST::Maths::Vector2D< T >::dot ( const Vector2D< T > &  v) const
inlineconstexprnoexcept

◆ cross()

template<typename T >
constexpr T RST::Maths::Vector2D< T >::cross ( const Vector2D< T > &  v) const
inlineconstexprnoexcept

Z component of the 3D cross product, positive when v is counterclockwise from this vector.

◆ perpendicular()

template<typename T >
constexpr Vector2D RST::Maths::Vector2D< T >::perpendicular ( ) const
inlineconstexprnoexcept

This vector rotated by 90 degrees counterclockwise.

◆ lengthSquared()

template<typename T >
constexpr auto RST::Maths::Vector2D< T >::lengthSquared ( ) const
inlineconstexprnoexcept

◆ length()

template<typename T >
constexpr auto RST::Maths::Vector2D< T >::length ( ) const
inlineconstexprnoexcept
Examples
graphics.cpp.

◆ distanceSquared()

template<typename T >
constexpr auto RST::Maths::Vector2D< T >::distanceSquared ( const Vector2D< T > &  v) const
inlineconstexprnoexcept

◆ distance()

template<typename T >
constexpr auto RST::Maths::Vector2D< T >::distance ( const Vector2D< T > &  v) const
inlineconstexprnoexcept

◆ normalize()

template<typename T >
constexpr Vector2D & RST::Maths::Vector2D< T >::normalize ( )
inlineconstexprnoexcept

Scales this vector to length 1; a zero vector is left unchanged.

◆ normalized()

template<typename T >
constexpr Vector2D RST::Maths::Vector2D< T >::normalized ( ) const
inlineconstexprnoexcept

◆ to()

template<typename T >
template<typename U >
constexpr Vector2D< U > RST::Maths::Vector2D< T >::to ( ) const
inlineconstexprnoexcept

Converts the components, such as v.to<int>().

◆ min()

template<typename T >
constexpr Vector2D RST::Maths::Vector2D< T >::min ( const Vector2D< T > &  v) const
inlineconstexprnoexcept

Component-wise minimum.

◆ max()

template<typename T >
constexpr Vector2D RST::Maths::Vector2D< T >::max ( const Vector2D< T > &  v) const
inlineconstexprnoexcept

Component-wise maximum.

Member Data Documentation

◆ x

template<typename T >
T RST::Maths::Vector2D< T >::x {}

◆ y

template<typename T >
T RST::Maths::Vector2D< T >::y {}

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