LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::Math::Vector< T, DIM > Struct Template Reference

An algebraic vector type. More...

#include <vector.hpp>

Public Types

using scalar_type = T
 The type of the vector elements.
 
using vec_type = Vector<scalar_type, vec_size>
 The type of the vector itself.
 

Public Member Functions

constexpr Vector () noexcept=default
 Initializes an empty vector.
 
constexpr Vector (Vector &&_other) noexcept=default
 Initializes a vector by taking over another vector.
 
constexpr Vector (const Vector &_other)=default
 Initializes a vector with the values provided by another vector.
 
constexpr Vectoroperator= (Vector &&_other) noexcept=default
 Moves the elements of the other vector to the current vector.
 
constexpr Vectoroperator= (const Vector &_other)=default
 Copys the elements of another vector into the current vector.
 
constexpr ~Vector () noexcept=default
 Destroys the vector.
 
constexpr Vector (T val) noexcept
 Initializes a vector where all elements take the value provided by val .
 
constexpr Vector (T x, T y) noexcept
 Initializes a 2D vector using the values provided by x and y .
 
constexpr Vector (T x, T y, T z) noexcept
 Initializes a 3D vector using the values provided by x , y and z .
 
constexpr Vector (T x, T y, T z, T w) noexcept
 Initializes a 4D vector using the values provided by x , y , z and w .
 
constexpr Vector (std::ranges::input_range auto &&input) noexcept
 Initializes the vector from an arbitrary input range.
 
constexpr auto & operator= (std::ranges::input_range auto &&input) noexcept
 Copies the values from an arbitrary input range into the current vector instance.
 
constexpr T operator[] (unsigned int i) const noexcept
 Returns a value from the vector, indexed by the parameter i .
 
constexpr T & operator[] (unsigned int i) noexcept
 Returns a reference to a value from the vector, indexed by the parameter i .
 
constexpr auto begin () noexcept
 Returns an interator for that addresses the begin of the vector elements.
 
constexpr auto end () noexcept
 Returns an interator for that addresses the end of the vector elements.
 
constexpr auto cbegin () const noexcept
 Returns a constant interator for that addresses the begin of the vector elements.
 
constexpr auto cend () const noexcept
 Returns a constant interator for that addresses the end of the vector elements.
 
constexpr const scalar_typeelements () const noexcept
 Returns a pointer to the elements of the vector.
 
constexpr operator std::array< T, DIM > () const noexcept
 Converts the vector to an instance of std::array.
 
constexpr operator std::vector< T > () const
 Converts the vector into an instance of type std::vector.
 
constexpr int size () const noexcept
 Returns the number of dimensions of the vector.
 
constexpr scalar_type x () const noexcept
 Returns the value of the x component of the vector.
 
constexpr scalar_typex () noexcept
 Returns a reference of the value of the x component of the vector.
 
constexpr scalar_type y () const noexcept
 Returns the value of the y component of the vector.
 
constexpr scalar_typey () noexcept
 Returns a reference of the value of the y component of the vector.
 
constexpr scalar_type z () const noexcept
 Returns the value of the z component of the vector.
 
constexpr scalar_typez () noexcept
 Returns a reference of the value of the z component of the vector.
 
constexpr scalar_type w () const noexcept
 Returns the value of the w component of the vector.
 
constexpr scalar_typew () noexcept
 Returns a reference of the value of the w component of the vector.
 

Static Public Attributes

static constexpr size_t vec_size = DIM
 Stores the size of the vector.
 

Protected Types

using array_type = std::array<scalar_type, vec_size>
 

Protected Attributes

array_type m_elements = { }
 

Detailed Description

template<typename T, unsigned DIM>
requires (DIM > 0) && std::is_standard_layout_v<T> && std::is_trivially_copyable_v<T>
struct LiteFX::Math::Vector< T, DIM >

An algebraic vector type.

The value type of a vector must be in standard layout (i.e., std::is_standard_layout_v<T> must evaluate to true). This constraint is enforced at compile time and ensures that vector types can be binary marshalled. For example, the

See also
LiteFX::Graphics::Vertex

type stores nothing more than a series of vectors. The standard layout constraint ensures that a set of vertices can be converted into a plain byte array and back.

Template Parameters
TThe type of the vector scalar elements. Must be in standard layout (i.e., std::is_standard_layout_v<T> must evaluate to true).
DIMThe number of dimensions of the vector.

Member Typedef Documentation

◆ array_type

template<typename T , unsigned DIM>
using LiteFX::Math::Vector< T, DIM >::array_type = std::array<scalar_type, vec_size>
protected

◆ scalar_type

template<typename T , unsigned DIM>
using LiteFX::Math::Vector< T, DIM >::scalar_type = T

The type of the vector elements.

◆ vec_type

template<typename T , unsigned DIM>
using LiteFX::Math::Vector< T, DIM >::vec_type = Vector<scalar_type, vec_size>

The type of the vector itself.

Constructor & Destructor Documentation

◆ Vector() [1/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( )
constexprdefaultnoexcept

Initializes an empty vector.

◆ Vector() [2/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( Vector< T, DIM > && _other)
constexprdefaultnoexcept

Initializes a vector by taking over another vector.

Parameters
_otherThe vector to take over.

◆ Vector() [3/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( const Vector< T, DIM > & _other)
constexprdefault

Initializes a vector with the values provided by another vector.

Parameters
_otherThe other vector to copy the values from.

◆ ~Vector()

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::~Vector ( )
constexprdefaultnoexcept

Destroys the vector.

◆ Vector() [4/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( T val)
inlineconstexprnoexcept

Initializes a vector where all elements take the value provided by val .

Parameters
valThe value to initialize all elements of the vector with.

◆ Vector() [5/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( T x,
T y )
inlineconstexprnoexcept

Initializes a 2D vector using the values provided by x and y .

Parameters
xThe value to initialize the x-component of the vector with.
yThe value to initialize the y-component of the vector with.

◆ Vector() [6/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( T x,
T y,
T z )
inlineconstexprnoexcept

Initializes a 3D vector using the values provided by x , y and z .

Parameters
xThe value to initialize the x-component of the vector with.
yThe value to initialize the y-component of the vector with.
zThe value to initialize the z-component of the vector with.

◆ Vector() [7/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( T x,
T y,
T z,
T w )
inlineconstexprnoexcept

Initializes a 4D vector using the values provided by x , y , z and w .

Parameters
xThe value to initialize the x-component of the vector with.
yThe value to initialize the y-component of the vector with.
zThe value to initialize the z-component of the vector with.
wThe value to initialize the w-component of the vector with.

◆ Vector() [8/8]

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::Vector ( std::ranges::input_range auto && input)
inlineexplicitconstexprnoexcept

Initializes the vector from an arbitrary input range.

Parameters
inputThe range to initialize the vector with.

Member Function Documentation

◆ begin()

template<typename T , unsigned DIM>
auto LiteFX::Math::Vector< T, DIM >::begin ( )
inlineconstexprnoexcept

Returns an interator for that addresses the begin of the vector elements.

Returns
An interator for that addresses the begin of the vector elements.

◆ cbegin()

template<typename T , unsigned DIM>
auto LiteFX::Math::Vector< T, DIM >::cbegin ( ) const
inlineconstexprnoexcept

Returns a constant interator for that addresses the begin of the vector elements.

Returns
A constant interator for that addresses the begin of the vector elements.

◆ cend()

template<typename T , unsigned DIM>
auto LiteFX::Math::Vector< T, DIM >::cend ( ) const
inlineconstexprnoexcept

Returns a constant interator for that addresses the end of the vector elements.

Returns
A constant interator for that addresses the end of the vector elements.

◆ elements()

template<typename T , unsigned DIM>
const scalar_type * LiteFX::Math::Vector< T, DIM >::elements ( ) const
inlineconstexprnoexcept

Returns a pointer to the elements of the vector.

Returns
A pointer to the elements of the vector.

◆ end()

template<typename T , unsigned DIM>
auto LiteFX::Math::Vector< T, DIM >::end ( )
inlineconstexprnoexcept

Returns an interator for that addresses the end of the vector elements.

Returns
An interator for that addresses the end of the vector elements.

◆ operator std::array< T, DIM >()

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::operator std::array< T, DIM > ( ) const
inlineconstexprnoexcept

Converts the vector to an instance of std::array.

◆ operator std::vector< T >()

template<typename T , unsigned DIM>
LiteFX::Math::Vector< T, DIM >::operator std::vector< T > ( ) const
inlineconstexpr

Converts the vector into an instance of type std::vector.

◆ operator=() [1/3]

template<typename T , unsigned DIM>
Vector & LiteFX::Math::Vector< T, DIM >::operator= ( const Vector< T, DIM > & _other)
constexprdefault

Copys the elements of another vector into the current vector.

Parameters
_otherThe vector to copy the elements from.
Returns
A reference to the current vector instance.

◆ operator=() [2/3]

template<typename T , unsigned DIM>
auto & LiteFX::Math::Vector< T, DIM >::operator= ( std::ranges::input_range auto && input)
inlineconstexprnoexcept

Copies the values from an arbitrary input range into the current vector instance.

Parameters
inputThe input range to copy the values from.
Returns
A reference to the current vector instance.

◆ operator=() [3/3]

template<typename T , unsigned DIM>
Vector & LiteFX::Math::Vector< T, DIM >::operator= ( Vector< T, DIM > && _other)
constexprdefaultnoexcept

Moves the elements of the other vector to the current vector.

Parameters
_otherThe vector to take over.
Returns
A reference to the current vector instance.

◆ operator[]() [1/2]

template<typename T , unsigned DIM>
T LiteFX::Math::Vector< T, DIM >::operator[] ( unsigned int i) const
inlineconstexprnoexcept

Returns a value from the vector, indexed by the parameter i .

Note that this method wraps the index if it is out of range, i.e., calling the method with index 4 on a 4D vector will return the element at index 0.

Parameters
iThe index of the element to return.
Returns
The value of the element at the provided index.

◆ operator[]() [2/2]

template<typename T , unsigned DIM>
T & LiteFX::Math::Vector< T, DIM >::operator[] ( unsigned int i)
inlineconstexprnoexcept

Returns a reference to a value from the vector, indexed by the parameter i .

Note that this method wraps the index if it is out of range, i.e., calling the method with index 4 on a 4D vector will return the element at index 0.

Parameters
iThe index of the element to return.
Returns
A reference to a value of the element at the provided index.

◆ size()

template<typename T , unsigned DIM>
int LiteFX::Math::Vector< T, DIM >::size ( ) const
inlineconstexprnoexcept

Returns the number of dimensions of the vector.

Returns
The number of dimensions of the vector.

◆ w() [1/2]

template<typename T , unsigned DIM>
scalar_type LiteFX::Math::Vector< T, DIM >::w ( ) const
inlineconstexprnoexcept

Returns the value of the w component of the vector.

Returns
The value of the w component of the vector.

◆ w() [2/2]

template<typename T , unsigned DIM>
scalar_type & LiteFX::Math::Vector< T, DIM >::w ( )
inlineconstexprnoexcept

Returns a reference of the value of the w component of the vector.

Returns
The a reference of the value of the w component of the vector.

◆ x() [1/2]

template<typename T , unsigned DIM>
scalar_type LiteFX::Math::Vector< T, DIM >::x ( ) const
inlineconstexprnoexcept

Returns the value of the x component of the vector.

Returns
The value of the x component of the vector.

◆ x() [2/2]

template<typename T , unsigned DIM>
scalar_type & LiteFX::Math::Vector< T, DIM >::x ( )
inlineconstexprnoexcept

Returns a reference of the value of the x component of the vector.

Returns
The a reference of the value of the x component of the vector.

◆ y() [1/2]

template<typename T , unsigned DIM>
scalar_type LiteFX::Math::Vector< T, DIM >::y ( ) const
inlineconstexprnoexcept

Returns the value of the y component of the vector.

Returns
The value of the y component of the vector.

◆ y() [2/2]

template<typename T , unsigned DIM>
scalar_type & LiteFX::Math::Vector< T, DIM >::y ( )
inlineconstexprnoexcept

Returns a reference of the value of the y component of the vector.

Returns
The a reference of the value of the y component of the vector.

◆ z() [1/2]

template<typename T , unsigned DIM>
scalar_type LiteFX::Math::Vector< T, DIM >::z ( ) const
inlineconstexprnoexcept

Returns the value of the z component of the vector.

Returns
The value of the z component of the vector.

◆ z() [2/2]

template<typename T , unsigned DIM>
scalar_type & LiteFX::Math::Vector< T, DIM >::z ( )
inlineconstexprnoexcept

Returns a reference of the value of the z component of the vector.

Returns
The a reference of the value of the z component of the vector.

Member Data Documentation

◆ m_elements

template<typename T , unsigned DIM>
array_type LiteFX::Math::Vector< T, DIM >::m_elements = { }
protected

◆ vec_size

template<typename T , unsigned DIM>
size_t LiteFX::Math::Vector< T, DIM >::vec_size = DIM
staticconstexpr

Stores the size of the vector.