sandbox
Loading...
Searching...
No Matches
matrix.hpp File Reference

Generic fixed-size matrix type. More...

#include <array>
#include <cstddef>
#include <cstdint>
#include <span>
#include <libsbx/math/concepts.hpp>
#include <libsbx/math/vector.hpp>
#include <libsbx/math/matrix.ipp>

Go to the source code of this file.

Classes

class  sbx::math::basic_matrix< Columns, Rows, Type >
 Fixed-size column-major matrix. More...
 

Namespaces

namespace  libsbx
 

Functions

template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator== (const basic_matrix< Columns, Rows, Lhs > &lhs, const basic_matrix< Columns, Rows, Rhs > &rhs) noexcept -> bool
 Equality comparison for matrices. More...
 
template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator+ (basic_matrix< Columns, Rows, Lhs > lhs, const basic_matrix< Columns, Rows, Rhs > &rhs) noexcept -> basic_matrix< Columns, Rows, Lhs >
 Matrix addition. More...
 
template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator- (basic_matrix< Columns, Rows, Lhs > lhs, const basic_matrix< Columns, Rows, Rhs > &rhs) noexcept -> basic_matrix< Columns, Rows, Lhs >
 Matrix subtraction. More...
 
template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator* (basic_matrix< Columns, Rows, Lhs > lhs, Rhs rhs) noexcept -> basic_matrix< Columns, Rows, Lhs >
 Scalar multiplication. More...
 
template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator* (Lhs lhs, basic_matrix< Columns, Rows, Rhs > rhs) noexcept -> basic_matrix< Columns, Rows, Rhs >
 Scalar multiplication (reversed). More...
 
template<typename Matrix >
constexpr auto sbx::math::from_array (std::span< typename Matrix::value_type, Matrix::columns *Matrix::rows > array) -> Matrix
 Constructs a matrix from a contiguous array. More...
 

Detailed Description

Generic fixed-size matrix type.

This header defines a statically sized, column-major matrix template parameterized by column count, row count, and scalar type.

The matrix is implemented as an array of column vectors and supports element access, arithmetic operations, row extraction, and identity construction. It is intended as a low-level building block for higher- level math types such as transforms and projections.

Author
KAJ

Function Documentation

◆ from_array()

template<typename Matrix >
constexpr auto sbx::math::from_array ( std::span< typename Matrix::value_type, Matrix::columns *Matrix::rows >  array) -> Matrix
inlineconstexpr

Constructs a matrix from a contiguous array.

Template Parameters
MatrixTarget matrix type.
Parameters
arraySource array containing matrix elements.
Returns
Constructed matrix.

◆ operator*() [1/2]

template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator* ( basic_matrix< Columns, Rows, Lhs >  lhs,
Rhs  rhs 
) -> basic_matrix<Columns, Rows, Lhs>
inlineconstexprnoexcept

Scalar multiplication.

Template Parameters
ColumnsColumn count.
RowsRow count.
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsLeft-hand side matrix.
rhsScalar multiplier.
Returns
Scaled matrix.

◆ operator*() [2/2]

template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator* ( Lhs  lhs,
basic_matrix< Columns, Rows, Rhs >  rhs 
) -> basic_matrix<Columns, Rows, Rhs>
inlineconstexprnoexcept

Scalar multiplication (reversed).

Template Parameters
ColumnsColumn count.
RowsRow count.
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsScalar multiplier.
rhsRight-hand side matrix.
Returns
Scaled matrix.

◆ operator+()

template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator+ ( basic_matrix< Columns, Rows, Lhs >  lhs,
const basic_matrix< Columns, Rows, Rhs > &  rhs 
) -> basic_matrix<Columns, Rows, Lhs>
inlineconstexprnoexcept

Matrix addition.

Template Parameters
ColumnsColumn count.
RowsRow count.
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsLeft-hand side matrix.
rhsRight-hand side matrix.
Returns
Sum of both matrices.

◆ operator-()

template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator- ( basic_matrix< Columns, Rows, Lhs >  lhs,
const basic_matrix< Columns, Rows, Rhs > &  rhs 
) -> basic_matrix<Columns, Rows, Lhs>
inlineconstexprnoexcept

Matrix subtraction.

Template Parameters
ColumnsColumn count.
RowsRow count.
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsLeft-hand side matrix.
rhsRight-hand side matrix.
Returns
Difference of both matrices.

◆ operator==()

template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
constexpr auto sbx::math::operator== ( const basic_matrix< Columns, Rows, Lhs > &  lhs,
const basic_matrix< Columns, Rows, Rhs > &  rhs 
) -> bool
inlineconstexprnoexcept

Equality comparison for matrices.

Template Parameters
ColumnsColumn count.
RowsRow count.
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsLeft-hand side matrix.
rhsRight-hand side matrix.
Returns
True if all elements are equal.