utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::math::Vector< VectorComponentType, VectorDimension > Class Template Reference

3D vector class inheriting from glm::vec3. More...

#include <headers/utility/math/vector.hpp>

Inheritance diagram for utility::math::Vector< VectorComponentType, VectorDimension >:
Collaboration diagram for utility::math::Vector< VectorComponentType, VectorDimension >:

Public Member Functions

 Vector (void)
 Default constructor initializing vector values to zero.
 
 Vector (const glm::vec< VectorDimension, VectorComponentType > &v)
 Construct from a GLM vector.
 
 Vector (std::initializer_list< VectorComponentType > values)
 Construct from initializer list of float values.
 
 Vector (VectorComponentType value)
 Construct by filling all components with the same float value.
 
 Vector (const Vector &other)=default
 Copy constructor.
 
 Vector (Vector &&other) noexcept=default
 Move constructor.
 
 ~Vector (void)=default
 Default destructor for Vector.
 
Vectoroperator= (const Vector &other)=default
 Copy assignment operator.
 
Vectoroperator= (Vector &&other) noexcept=default
 Move assignment operator.
 
Vector operator+ (const Vector &rhs) const noexcept
 Vector addition.
 
Vectoroperator+= (const Vector &rhs) noexcept
 Vector addition assignment.
 
Vector operator- (const Vector &rhs) const noexcept
 Vector subtraction.
 
Vectoroperator-= (const Vector &rhs) noexcept
 Vector subtraction assignment.
 
Vector operator* (VectorComponentType scalar) const noexcept
 Scalar multiplication.
 
Vectoroperator*= (VectorComponentType scalar) noexcept
 Scalar multiplication assignment.
 
Vector operator/ (VectorComponentType scalar) const
 Scalar division.
 
Vectoroperator/= (VectorComponentType scalar)
 Scalar division assignment.
 
Vector operator* (const Vector &rhs) const noexcept
 Element-wise multiplication.
 
Vectoroperator*= (const Vector &rhs) noexcept
 Element-wise multiplication assignment.
 
Vector operator/ (const Vector &rhs) const
 Element-wise division.
 
Vectoroperator/= (const Vector &rhs)
 Element-wise division assignment.
 
bool operator== (const Vector &rhs) const noexcept
 Equality comparison.
 
bool equalsEpsilon (const Vector &rhs, VectorComponentType epsilon=VectorComponentType { 1e-5 }) const
 Approximate equality using an epsilon threshold.
 
bool operator!= (const Vector &rhs) const noexcept
 Inequality comparison.
 
Vector operator- () const noexcept
 Unary negation.
 

Friends

Vector operator* (VectorComponentType scalar, const Vector &vec)
 Friend function for scalar multiplication with scalar on the left.
 

Detailed Description

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
class utility::math::Vector< VectorComponentType, VectorDimension >

3D vector class inheriting from glm::vec3.

Template Parameters
TypeFloating-point type for vector components.

Definition at line 82 of file vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/6]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
utility::math::Vector< VectorComponentType, VectorDimension >::Vector ( void  )
inline

Default constructor initializing vector values to zero.

Definition at line 88 of file vector.hpp.

Here is the caller graph for this function:

◆ Vector() [2/6]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
utility::math::Vector< VectorComponentType, VectorDimension >::Vector ( const glm::vec< VectorDimension, VectorComponentType > &  v)
inlineexplicit

Construct from a GLM vector.

Parameters
vSource GLM vector.

Definition at line 97 of file vector.hpp.

◆ Vector() [3/6]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
utility::math::Vector< VectorComponentType, VectorDimension >::Vector ( std::initializer_list< VectorComponentType >  values)
inline

Construct from initializer list of float values.

Parameters
valuesThe initializer list containing vector components.
Exceptions
std::invalid_argumentif the list size does not match the vector dimension.

Definition at line 108 of file vector.hpp.

◆ Vector() [4/6]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
utility::math::Vector< VectorComponentType, VectorDimension >::Vector ( VectorComponentType  value)
inlineexplicit

Construct by filling all components with the same float value.

Parameters
valueThe float value to fill all components with.

Definition at line 125 of file vector.hpp.

◆ Vector() [5/6]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
utility::math::Vector< VectorComponentType, VectorDimension >::Vector ( const Vector< VectorComponentType, VectorDimension > &  other)
default

Copy constructor.

Parameters
otherThe Vector object to copy from.

◆ Vector() [6/6]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
utility::math::Vector< VectorComponentType, VectorDimension >::Vector ( Vector< VectorComponentType, VectorDimension > &&  other)
defaultnoexcept

Move constructor.

Parameters
otherThe Vector object to move from.

Member Function Documentation

◆ equalsEpsilon()

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
bool utility::math::Vector< VectorComponentType, VectorDimension >::equalsEpsilon ( const Vector< VectorComponentType, VectorDimension > &  rhs,
VectorComponentType  epsilon = VectorComponentType { 1e-5 } 
) const
inline

Approximate equality using an epsilon threshold.

Returns true if each component is within epsilon of its counterpart in rhs.

Parameters
rhsThe vector to compare with.
epsilonThe maximum allowed difference per component.
Returns
True if the vectors are equal within epsilon.

Definition at line 378 of file vector.hpp.

◆ operator!=()

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
bool utility::math::Vector< VectorComponentType, VectorDimension >::operator!= ( const Vector< VectorComponentType, VectorDimension > &  rhs) const
inlinenoexcept

Inequality comparison.

Parameters
rhsThe vector to compare with.
Returns
True if the vectors are not equal, false otherwise.

Definition at line 395 of file vector.hpp.

◆ operator*() [1/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator* ( const Vector< VectorComponentType, VectorDimension > &  rhs) const
inlinenoexcept

Element-wise multiplication.

Parameters
rhsThe vector to multiply with.
Returns
The resulting vector.

Definition at line 284 of file vector.hpp.

Here is the call graph for this function:

◆ operator*() [2/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator* ( VectorComponentType  scalar) const
inlinenoexcept

Scalar multiplication.

Parameters
scalarThe scalar value to multiply with.
Returns
The resulting vector.

Definition at line 226 of file vector.hpp.

Here is the call graph for this function:

◆ operator*=() [1/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator*= ( const Vector< VectorComponentType, VectorDimension > &  rhs)
inlinenoexcept

Element-wise multiplication assignment.

Parameters
rhsThe vector to multiply with.
Returns
A reference to this vector after multiplication.

Definition at line 299 of file vector.hpp.

◆ operator*=() [2/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator*= ( VectorComponentType  scalar)
inlinenoexcept

Scalar multiplication assignment.

Parameters
scalarThe scalar value to multiply with.
Returns
A reference to this vector after multiplication.

Definition at line 239 of file vector.hpp.

◆ operator+()

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator+ ( const Vector< VectorComponentType, VectorDimension > &  rhs) const
inlinenoexcept

Vector addition.

Parameters
rhsThe vector to add.
Returns
The resulting vector.

Definition at line 166 of file vector.hpp.

Here is the call graph for this function:

◆ operator+=()

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator+= ( const Vector< VectorComponentType, VectorDimension > &  rhs)
inlinenoexcept

Vector addition assignment.

Parameters
rhsThe vector to add.
Returns
A reference to this vector after addition.

Definition at line 181 of file vector.hpp.

◆ operator-() [1/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator- ( ) const
inlinenoexcept

Unary negation.

Returns
The negated vector.

Definition at line 404 of file vector.hpp.

Here is the call graph for this function:

◆ operator-() [2/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator- ( const Vector< VectorComponentType, VectorDimension > &  rhs) const
inlinenoexcept

Vector subtraction.

Parameters
rhsThe vector to subtract.
Returns
The resulting vector.

Definition at line 196 of file vector.hpp.

Here is the call graph for this function:

◆ operator-=()

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator-= ( const Vector< VectorComponentType, VectorDimension > &  rhs)
inlinenoexcept

Vector subtraction assignment.

Parameters
rhsThe vector to subtract.
Returns
A reference to this vector after subtraction.

Definition at line 211 of file vector.hpp.

◆ operator/() [1/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator/ ( const Vector< VectorComponentType, VectorDimension > &  rhs) const
inline

Element-wise division.

Parameters
rhsThe vector to divide by.
Returns
The resulting vector.
Exceptions
std::invalid_argumentif any component of rhs is zero.

Definition at line 315 of file vector.hpp.

Here is the call graph for this function:

◆ operator/() [2/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector utility::math::Vector< VectorComponentType, VectorDimension >::operator/ ( VectorComponentType  scalar) const
inline

Scalar division.

Parameters
scalarThe scalar value to divide by.
Returns
The resulting vector.
Exceptions
std::invalid_argumentif scalar is zero.

Definition at line 252 of file vector.hpp.

Here is the call graph for this function:

◆ operator/=() [1/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator/= ( const Vector< VectorComponentType, VectorDimension > &  rhs)
inline

Element-wise division assignment.

Parameters
rhsThe vector to divide by.
Returns
A reference to this vector after division.
Exceptions
std::invalid_argumentif any component of rhs is zero.

Definition at line 336 of file vector.hpp.

◆ operator/=() [2/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator/= ( VectorComponentType  scalar)
inline

Scalar division assignment.

Parameters
scalarThe scalar value to divide by.
Returns
A reference to this vector after division.
Exceptions
std::invalid_argumentif scalar is zero.

Definition at line 269 of file vector.hpp.

◆ operator=() [1/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator= ( const Vector< VectorComponentType, VectorDimension > &  other)
default

Copy assignment operator.

Parameters
otherThe Vector object to copy from.
Returns
A reference to this Vector object.

◆ operator=() [2/2]

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector & utility::math::Vector< VectorComponentType, VectorDimension >::operator= ( Vector< VectorComponentType, VectorDimension > &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherThe Vector object to move from.
Returns
A reference to this Vector object.

◆ operator==()

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
bool utility::math::Vector< VectorComponentType, VectorDimension >::operator== ( const Vector< VectorComponentType, VectorDimension > &  rhs) const
inlinenoexcept

Equality comparison.

Uses exact component-wise equality. For floating-point types prefer equalsEpsilon to tolerate rounding error.

Parameters
rhsThe vector to compare with.
Returns
True if the vectors are equal, false otherwise.

Definition at line 359 of file vector.hpp.

Friends And Related Symbol Documentation

◆ operator*

template<CanBeVectorComponent VectorComponentType, std::size_t VectorDimension>
Vector operator* ( VectorComponentType  scalar,
const Vector< VectorComponentType, VectorDimension > &  vec 
)
friend

Friend function for scalar multiplication with scalar on the left.

Parameters
scalarThe scalar value to multiply with.
vecThe vector to multiply.
Returns
The resulting vector.

Definition at line 419 of file vector.hpp.


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