LiteFX 0.4.1.2025
Computer Graphics Engine
|
An algebraic matrix type. More...
#include <matrix.hpp>
Public Types | |
using | scalar_type = T |
The type of the matrix elements. | |
using | mat_type = Matrix<scalar_type, mat_rows, mat_cols> |
The type of the matrix itself. | |
template<unsigned rows, unsigned cols> | |
using | generic_mat_type = Matrix<scalar_type, rows, cols> |
The type of the matrix, but without pre-defined dimensions. | |
Public Member Functions | |
constexpr | Matrix () noexcept=default |
Initializes an empty matrix. | |
constexpr | Matrix (T val) noexcept |
Initializes a matrix where all elements take the value provided by val . | |
constexpr | Matrix (array_type &&array) noexcept |
Initializes a matrix with an array of values. | |
constexpr | Matrix (std::initializer_list< scalar_type > elements) noexcept |
Initializes the matrix with a set of values. | |
template<unsigned rows, unsigned cols> | |
constexpr | Matrix (const Matrix< scalar_type, rows, cols > &_other) |
Initializes a copy from another matrix, that might have different dimensions. | |
constexpr | Matrix (Matrix &&_other) noexcept=default |
Initializes a matrix by taking over another matrix. | |
constexpr | Matrix (const Matrix &_other)=default |
Initializes a matrix with the values provided by another matrix. | |
constexpr Matrix & | operator= (Matrix &&_other) noexcept=default |
Moves the elements of the other matrix to the current matrix. | |
constexpr Matrix & | operator= (const Matrix &_other)=default |
Copies the elements of another matrix into the current matrix. | |
constexpr | ~Matrix () noexcept=default |
Destroys the matrix instance. | |
constexpr const scalar_type * | elements () const noexcept |
Returns a pointer to the raw data of the matrix. | |
constexpr scalar_type * | elements () noexcept |
Returns a pointer to the raw data of the matrix. | |
consteval size_t | size () const noexcept |
Returns the number of elements of the matrix. | |
constexpr auto | begin () noexcept |
Returns an iterator for that addresses the begin of the matrix elements. | |
constexpr auto | end () noexcept |
Returns an iterator for that addresses the end of the matrix elements. | |
constexpr auto | cbegin () const noexcept |
Returns a constant iterator for that addresses the begin of the matrix elements. | |
constexpr auto | cend () const noexcept |
Returns a constant iterator for that addresses the end of the matrix elements. | |
constexpr scalar_type | at (size_t row, size_t col) const noexcept |
Returns the element at a specified position. | |
constexpr scalar_type & | at (size_t row, size_t col) noexcept |
Returns the element at a specified position. | |
constexpr std::span< const scalar_type > | row (size_t row) const noexcept |
Returns a view over a row of the matrix. | |
constexpr std::span< scalar_type > | row (size_t row) noexcept |
Returns a view over a row of the matrix. | |
constexpr std::array< scalar_type, mat_cols > | column (size_t col) const noexcept |
Returns a copy of a column over the matrix. | |
constexpr scalar_type | operator[] (std::pair< size_t, size_t > position) const noexcept |
Returns an element of the matrix. | |
constexpr scalar_type & | operator[] (std::pair< size_t, size_t > position) noexcept |
Returns an element of the matrix. | |
constexpr | operator std::array< T, mat_rows *mat_cols > () const noexcept |
Converts the matrix to an instance of std::array . | |
constexpr | operator std::vector< T > () const noexcept |
Converts the matrix into an instance of type std::vector . | |
constexpr | operator std::span< const scalar_type > () const noexcept |
Converts the matrix into a linear view over the elements. | |
constexpr | operator std::span< scalar_type > () noexcept |
Converts the matrix into a linear view over the elements. | |
constexpr generic_mat_type< mat_cols, mat_rows > | transpose () const noexcept |
Returns a copy of the matrix where the elements are transposed. | |
consteval bool | symmetric () const noexcept |
Returns whether or not the matrix is symmetric, that is the number of rows and columns are equal. | |
Static Public Member Functions | |
static constexpr mat_type | identity () noexcept |
Returns an identity matrix. | |
Static Public Attributes | |
static constexpr size_t | mat_rows = ROWS |
Stores the number of rows of the matrix. | |
static constexpr size_t | mat_cols = COLS |
Stores the number of columns of the matrix. | |
Protected Types | |
using | array_type = std::array<scalar_type, mat_rows * mat_cols> |
Protected Attributes | |
array_type | m_elements = { } |
An algebraic matrix type.
Note that matrices in the engine are row-major by convention.
Matrices act as optimized storage containers only. All algebraic operations are not part of the library itself, but rather covered by supported linear algebra libraries.
T | The type of the matrix scalar elements. Must be in standard layout (i.e., std::is_standard_layout_v<T> must evaluate to true ). |
ROWS | The number of rows of the matrix. Must be greater than 1. |
COLS | The number of columns of the matrix. Must be greater than 1. |
|
protected |
using LiteFX::Math::Matrix< T, ROWS, COLS >::generic_mat_type = Matrix<scalar_type, rows, cols> |
The type of the matrix, but without pre-defined dimensions.
rows | The number of rows of the matrix. |
cols | The number of columns of the matrix. |
using LiteFX::Math::Matrix< T, ROWS, COLS >::mat_type = Matrix<scalar_type, mat_rows, mat_cols> |
The type of the matrix itself.
using LiteFX::Math::Matrix< T, ROWS, COLS >::scalar_type = T |
The type of the matrix elements.
|
constexprdefaultnoexcept |
Initializes an empty matrix.
|
inlineconstexprnoexcept |
Initializes a matrix where all elements take the value provided by val .
val | The value to initialize all elements of the matrix with. |
|
inlineconstexprnoexcept |
Initializes a matrix with an array of values.
array | The array of values to take over by the matrix. |
|
inlineconstexprnoexcept |
Initializes the matrix with a set of values.
elements | The values to initialize the matrix with. |
|
inlineconstexpr |
Initializes a copy from another matrix, that might have different dimensions.
rows | The rows of the other matrix. |
cols | The columns of the other matrix. |
_other | The other matrix. |
|
constexprdefaultnoexcept |
Initializes a matrix by taking over another matrix.
_other | The matrix to take over. |
|
constexprdefault |
Initializes a matrix with the values provided by another matrix.
_other | The other matrix to copy the values from. |
|
constexprdefaultnoexcept |
Destroys the matrix instance.
|
inlineconstexprnoexcept |
Returns the element at a specified position.
row | The row of the element. |
col | The column of the element. |
|
inlineconstexprnoexcept |
Returns the element at a specified position.
row | The row of the element. |
col | The column of the element. |
|
inlineconstexprnoexcept |
Returns an iterator for that addresses the begin of the matrix elements.
|
inlineconstexprnoexcept |
Returns a constant iterator for that addresses the begin of the matrix elements.
|
inlineconstexprnoexcept |
Returns a constant iterator for that addresses the end of the matrix elements.
|
inlineconstexprnoexcept |
Returns a copy of a column over the matrix.
Note that this call involves a copy, which may be inefficient if done frequently. Prefer converting the matrix into an std::mdspan
instead, if supported.
col | The index of the column of the matrix. |
|
inlineconstexprnoexcept |
Returns a pointer to the raw data of the matrix.
|
inlineconstexprnoexcept |
Returns a pointer to the raw data of the matrix.
|
inlineconstexprnoexcept |
Returns an iterator for that addresses the end of the matrix elements.
|
inlinestaticconstexprnoexcept |
Returns an identity matrix.
|
inlineconstexprnoexcept |
Converts the matrix to an instance of std::array
.
|
inlineconstexprnoexcept |
Converts the matrix into a linear view over the elements.
|
inlineconstexprnoexcept |
Converts the matrix into a linear view over the elements.
|
inlineconstexprnoexcept |
Converts the matrix into an instance of type std::vector
.
|
constexprdefault |
Copies the elements of another matrix into the current matrix.
_other | The matrix to copy the elements from. |
|
constexprdefaultnoexcept |
Moves the elements of the other matrix to the current matrix.
_other | The matrix to take over. |
|
inlineconstexprnoexcept |
Returns an element of the matrix.
position | The row and column position of the matrix element. |
|
inlineconstexprnoexcept |
Returns an element of the matrix.
position | The row and column position of the matrix element. |
|
inlineconstexprnoexcept |
Returns a view over a row of the matrix.
row | The index of the row to view. |
|
inlineconstexprnoexcept |
Returns a view over a row of the matrix.
row | The index of the row to view. |
|
inlineconstevalnoexcept |
Returns the number of elements of the matrix.
|
inlineconstevalnoexcept |
Returns whether or not the matrix is symmetric, that is the number of rows and columns are equal.
true
, if the matrix is symmetric and false
otherwise.
|
inlineconstexprnoexcept |
Returns a copy of the matrix where the elements are transposed.
You can use this operations, if you want to iterate all columns of the matrix in a more efficient way. Transposing effectively turns a row-major matrix into a column-major one.
|
protected |
|
staticconstexpr |
Stores the number of columns of the matrix.
|
staticconstexpr |
Stores the number of rows of the matrix.