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::Matrix< MatrixComponentType, Cols, Rows, typename > Class Template Reference

M x N matrix class inheriting from glm::mat<Cols, Rows, Type>. More...

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

Inheritance diagram for utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >:
Collaboration diagram for utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >:

Public Member Functions

 Matrix (void)
 Default constructor initializing square matrices to identity and non-square matrices to zero.
 
 Matrix (std::initializer_list< MatrixComponentType > values)
 Construct from initializer list of Cols*Rows values (row-major order).
 
 Matrix (MatrixComponentType value)
 Construct by filling all components with the same value.
 
 Matrix (const glm::mat< Cols, Rows, MatrixComponentType > &value)
 Construct from a GLM matrix.
 
 Matrix (const Matrix &other)=default
 Copy constructor.
 
 Matrix (Matrix &&other) noexcept=default
 Move constructor.
 
 ~Matrix (void)=default
 Default destructor for Matrix.
 
Matrixoperator= (const Matrix &other)=default
 Copy assignment operator.
 
Matrixoperator= (Matrix &&other) noexcept=default
 Move assignment operator.
 
Matrix operator+ (const Matrix &rhs) const noexcept
 Matrix addition.
 
Matrixoperator+= (const Matrix &rhs) noexcept
 Matrix addition assignment.
 
Matrix operator- (const Matrix &rhs) const noexcept
 Matrix subtraction.
 
Matrixoperator-= (const Matrix &rhs) noexcept
 Matrix subtraction assignment.
 
Matrix operator* (MatrixComponentType scalar) const noexcept
 Scalar multiplication.
 
Matrixoperator*= (MatrixComponentType scalar) noexcept
 Scalar multiplication assignment.
 
Matrix operator/ (MatrixComponentType scalar) const
 Scalar division.
 
Matrixoperator/= (MatrixComponentType scalar)
 Scalar division assignment.
 
template<std::size_t RhsCols, std::size_t RhsRows>
requires (Cols == RhsRows)
Matrix< MatrixComponentType, RhsCols, Rows > operator* (const Matrix< MatrixComponentType, RhsCols, RhsRows > &rhs) const noexcept
 Matrix multiplication.
 
Matrixoperator*= (const Matrix &rhs) noexcept
 Matrix multiplication assignment (square matrices only).
 
bool operator== (const Matrix &rhs) const noexcept
 Equality comparison.
 
bool equalsEpsilon (const Matrix &rhs, MatrixComponentType epsilon=MatrixComponentType { 1e-5 }) const
 Approximate equality using an epsilon threshold.
 
bool operator!= (const Matrix &rhs) const noexcept
 Inequality comparison.
 
Matrix operator- (void) const noexcept
 Unary negation.
 

Friends

Matrix operator* (MatrixComponentType scalar, const Matrix &mat)
 Friend function for scalar multiplication with scalar on the left.
 

Detailed Description

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
class utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >

M x N matrix class inheriting from glm::mat<Cols, Rows, Type>.

Template Parameters
MatrixComponentTypeFloating-point type for matrix components.
ColsNumber of columns (must be 2, 3, or 4).
RowsNumber of rows (must be 2, 3, or 4).

Definition at line 91 of file matrix.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/6]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::Matrix ( void  )
inline

Default constructor initializing square matrices to identity and non-square matrices to zero.

Definition at line 98 of file matrix.hpp.

Here is the caller graph for this function:

◆ Matrix() [2/6]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::Matrix ( std::initializer_list< MatrixComponentType >  values)
inline

Construct from initializer list of Cols*Rows values (row-major order).

Parameters
valuesThe initializer list containing matrix components.
Exceptions
std::invalid_argumentif the list size is not Cols*Rows.

Definition at line 116 of file matrix.hpp.

◆ Matrix() [3/6]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::Matrix ( MatrixComponentType  value)
inlineexplicit

Construct by filling all components with the same value.

Parameters
valueThe value to fill all components with.

Definition at line 135 of file matrix.hpp.

◆ Matrix() [4/6]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::Matrix ( const glm::mat< Cols, Rows, MatrixComponentType > &  value)
inlineexplicit

Construct from a GLM matrix.

Parameters
valueSource matrix.

Definition at line 144 of file matrix.hpp.

◆ Matrix() [5/6]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::Matrix ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  other)
default

Copy constructor.

Parameters
otherThe Matrix object to copy from.

◆ Matrix() [6/6]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::Matrix ( Matrix< MatrixComponentType, Cols, Rows, typename > &&  other)
defaultnoexcept

Move constructor.

Parameters
otherThe Matrix object to move from.

Member Function Documentation

◆ equalsEpsilon()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
bool utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::equalsEpsilon ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs,
MatrixComponentType  epsilon = MatrixComponentType { 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 matrix to compare with.
epsilonThe maximum allowed difference per component.
Returns
True if the matrices are equal within epsilon.

Definition at line 355 of file matrix.hpp.

◆ operator!=()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
bool utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator!= ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs) const
inlinenoexcept

Inequality comparison.

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

Definition at line 374 of file matrix.hpp.

◆ operator*() [1/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
template<std::size_t RhsCols, std::size_t RhsRows>
requires (Cols == RhsRows)
Matrix< MatrixComponentType, RhsCols, Rows > utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator* ( const Matrix< MatrixComponentType, RhsCols, RhsRows > &  rhs) const
inlinenoexcept

Matrix multiplication.

Template Parameters
RhsColsNumber of columns of the RHS matrix.
RhsRowsNumber of rows of the RHS matrix.
Parameters
rhsThe matrix to multiply with.
Returns
The resulting matrix with shape (Rows, RhsCols).
Note
Requires this matrix's column count to equal the RHS row count (Cols == RhsRows).

Definition at line 304 of file matrix.hpp.

◆ operator*() [2/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator* ( MatrixComponentType  scalar) const
inlinenoexcept

Scalar multiplication.

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

Definition at line 239 of file matrix.hpp.

Here is the call graph for this function:

◆ operator*=() [1/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator*= ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs)
inlinenoexcept

Matrix multiplication assignment (square matrices only).

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

Definition at line 319 of file matrix.hpp.

◆ operator*=() [2/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator*= ( MatrixComponentType  scalar)
inlinenoexcept

Scalar multiplication assignment.

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

Definition at line 252 of file matrix.hpp.

◆ operator+()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator+ ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs) const
inlinenoexcept

Matrix addition.

Parameters
rhsThe matrix to add.
Returns
The resulting matrix.

Definition at line 185 of file matrix.hpp.

Here is the call graph for this function:

◆ operator+=()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator+= ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs)
inlinenoexcept

Matrix addition assignment.

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

Definition at line 199 of file matrix.hpp.

◆ operator-() [1/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator- ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs) const
inlinenoexcept

Matrix subtraction.

Parameters
rhsThe matrix to subtract.
Returns
The resulting matrix.

Definition at line 212 of file matrix.hpp.

Here is the call graph for this function:

◆ operator-() [2/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator- ( void  ) const
inlinenoexcept

Unary negation.

Returns
The negated matrix.

Definition at line 383 of file matrix.hpp.

Here is the call graph for this function:

◆ operator-=()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator-= ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs)
inlinenoexcept

Matrix subtraction assignment.

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

Definition at line 226 of file matrix.hpp.

◆ operator/()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator/ ( MatrixComponentType  scalar) const
inline

Scalar division.

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

Definition at line 265 of file matrix.hpp.

Here is the call graph for this function:

◆ operator/=()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator/= ( MatrixComponentType  scalar)
inline

Scalar division assignment.

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

Definition at line 282 of file matrix.hpp.

◆ operator=() [1/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator= ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  other)
default

Copy assignment operator.

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

◆ operator=() [2/2]

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix & utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator= ( Matrix< MatrixComponentType, Cols, Rows, typename > &&  other)
defaultnoexcept

Move assignment operator.

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

◆ operator==()

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
bool utility::math::Matrix< MatrixComponentType, Cols, Rows, typename >::operator== ( const Matrix< MatrixComponentType, Cols, Rows, typename > &  rhs) const
inlinenoexcept

Equality comparison.

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

Parameters
rhsThe matrix to compare with.
Returns
True if the matrices are equal, false otherwise.

Definition at line 338 of file matrix.hpp.

Friends And Related Symbol Documentation

◆ operator*

template<CanBeMatrixComponent MatrixComponentType, std::size_t Cols, std::size_t Rows, typename = std::enable_if_t<(Cols >= 2) && (Cols <= 4) && (Rows >= 2) && (Rows <= 4)>>
Matrix operator* ( MatrixComponentType  scalar,
const Matrix< MatrixComponentType, Cols, Rows, typename > &  mat 
)
friend

Friend function for scalar multiplication with scalar on the left.

Parameters
scalarThe scalar value to multiply with.
matThe matrix to multiply.
Returns
The resulting matrix.

Definition at line 397 of file matrix.hpp.


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