sandbox
Loading...
Searching...
No Matches
sbx::math::basic_matrix< Columns, Rows, Type > Class Template Reference

Fixed-size column-major matrix. More...

#include <matrix.hpp>

Public Types

enum class  direction : std::uint8_t { column = 0u , row = 1u }
 Matrix traversal direction.
 
using value_type = Type
 
using reference = value_type &
 
using const_reference = const value_type &
 
using size_type = std::size_t
 
using column_type = basic_vector< Rows, Type >
 

Public Member Functions

constexpr basic_matrix () noexcept
 Constructs a zero-initialized matrix.
 
template<scalar Other = value_type>
requires (Columns > 1u && Rows > 1u)
constexpr basic_matrix (const Other value) noexcept
 Constructs a matrix with all elements set to a value. More...
 
template<scalar Other = value_type>
requires (Columns > 1u && Rows > 1u)
constexpr basic_matrix (const basic_matrix< Columns, Rows, Other > &other) noexcept
 Constructs a matrix from another matrix with convertible type. More...
 
constexpr basic_matrix (const basic_matrix &other) noexcept=default
 
constexpr basic_matrix (basic_matrix &&other) noexcept=default
 
auto operator= (const basic_matrix &other) noexcept -> basic_matrix &=default
 
auto operator= (basic_matrix &&other) noexcept -> basic_matrix &=default
 
constexpr auto operator[] (size_type index) noexcept -> column_type &
 Accesses a column by index. More...
 
constexpr auto operator[] (size_type index) const noexcept -> const column_type &
 Accesses a column by index (const). More...
 
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto operator+= (const basic_matrix< Columns, Rows, Other > &other) noexcept -> basic_matrix &
 Adds another matrix to this matrix. More...
 
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto operator-= (const basic_matrix< Columns, Rows, Other > &other) noexcept -> basic_matrix &
 Subtracts another matrix from this matrix. More...
 
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto operator*= (Other scalar) noexcept -> basic_matrix &
 Multiplies this matrix by a scalar. More...
 
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto operator/= (Other scalar) noexcept -> basic_matrix &
 Divides this matrix by a scalar. More...
 
constexpr auto row (const size_type row) const noexcept -> basic_vector< Columns, value_type >
 Extracts a row as a vector. More...
 
constexpr auto data () noexcept -> value_type *
 Returns a pointer to the underlying contiguous storage. More...
 
constexpr auto data () const noexcept -> const value_type *
 Returns a pointer to the underlying contiguous storage (const). More...
 

Static Public Attributes

static constexpr auto columns = Columns
 Number of matrix columns.
 
static constexpr auto rows = Rows
 Number of matrix rows.
 

Protected Types

template<scalar Other>
using column_type_for = basic_vector< Rows, Other >
 

Protected Member Functions

template<typename... Args>
requires (Columns > 1u && Rows > 1u)
constexpr basic_matrix (Args &&... args) noexcept
 Constructs a matrix from a parameter pack of scalar values. More...
 

Static Protected Member Functions

static constexpr auto identity (const value_type value=static_cast< value_type >(1)) noexcept -> basic_matrix
 Constructs an identity matrix. More...
 

Detailed Description

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
class sbx::math::basic_matrix< Columns, Rows, Type >

Fixed-size column-major matrix.

Template Parameters
ColumnsNumber of columns.
RowsNumber of rows.
TypeScalar value type.

Constructor & Destructor Documentation

◆ basic_matrix() [1/3]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr sbx::math::basic_matrix< Columns, Rows, Type >::basic_matrix ( const Other  value)
inlineconstexprnoexcept

Constructs a matrix with all elements set to a value.

Template Parameters
OtherScalar type.
Parameters
valueInitialization value.

◆ basic_matrix() [2/3]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr sbx::math::basic_matrix< Columns, Rows, Type >::basic_matrix ( const basic_matrix< Columns, Rows, Other > &  other)
inlineconstexprnoexcept

Constructs a matrix from another matrix with convertible type.

Template Parameters
OtherSource scalar type.
Parameters
otherSource matrix.

◆ basic_matrix() [3/3]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<typename... Args>
requires (Columns > 1u && Rows > 1u)
constexpr sbx::math::basic_matrix< Columns, Rows, Type >::basic_matrix ( Args &&...  args)
inlineconstexprprotectednoexcept

Constructs a matrix from a parameter pack of scalar values.

Template Parameters
ArgsScalar argument types.
Parameters
argsScalar values used to initialize internal columns.

Member Function Documentation

◆ data() [1/2]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::data
inlineconstexprnoexcept

Returns a pointer to the underlying contiguous storage (const).

Returns
Pointer to the first scalar element.

◆ data() [2/2]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::data
inlineconstexprnoexcept

Returns a pointer to the underlying contiguous storage.

Returns
Pointer to the first scalar element.

◆ identity()

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::identity ( const value_type  value = static_cast<value_type>(1)) -> basic_matrix
inlinestaticconstexprprotectednoexcept

Constructs an identity matrix.

Parameters
valueDiagonal value.
Returns
Identity matrix.

◆ operator*=()

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::operator*= ( Other  scalar) -> basic_matrix&
inlineconstexprnoexcept

Multiplies this matrix by a scalar.

Template Parameters
OtherScalar type.
Parameters
scalarScalar multiplier.
Returns
Reference to this matrix.

◆ operator+=()

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::operator+= ( const basic_matrix< Columns, Rows, Other > &  other) -> basic_matrix&
inlineconstexprnoexcept

Adds another matrix to this matrix.

Template Parameters
OtherScalar type of the operand.
Parameters
otherRight-hand side matrix.
Returns
Reference to this matrix.

◆ operator-=()

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::operator-= ( const basic_matrix< Columns, Rows, Other > &  other) -> basic_matrix&
inlineconstexprnoexcept

Subtracts another matrix from this matrix.

Template Parameters
OtherScalar type of the operand.
Parameters
otherRight-hand side matrix.
Returns
Reference to this matrix.

◆ operator/=()

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
template<scalar Other>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::operator/= ( Other  scalar) -> basic_matrix&
inlineconstexprnoexcept

Divides this matrix by a scalar.

Template Parameters
OtherScalar type.
Parameters
scalarScalar divisor.
Returns
Reference to this matrix.

◆ operator[]() [1/2]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::operator[] ( size_type  index) const -> const column_type&
inlineconstexprnoexcept

Accesses a column by index (const).

Parameters
indexColumn index.
Returns
Const reference to the column.

◆ operator[]() [2/2]

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::operator[] ( size_type  index) -> column_type&
inlineconstexprnoexcept

Accesses a column by index.

Parameters
indexColumn index.
Returns
Reference to the column.

◆ row()

template<std::size_t Columns, std::size_t Rows, scalar Type>
requires (Columns > 1u && Rows > 1u)
constexpr auto sbx::math::basic_matrix< Columns, Rows, Type >::row ( const size_type  row) const -> basic_vector<Columns, value_type>
inlineconstexprnoexcept

Extracts a row as a vector.

Parameters
rowRow index.
Returns
Row vector.

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