1#ifndef TOPAZ_CORE_MATRIX_HPP
2#define TOPAZ_CORE_MATRIX_HPP
13 template<
typename T,
int N>
14 requires std::integral<T> || std::floating_point<T>
27 for(std::size_t i = 0; i < N; i++)
29 ret.mat[i * N + i] = T{1};
38 std::fill(ret.mat.begin(), ret.mat.end(), t);
48 const T& operator[](std::size_t idx)
const;
49 T& operator[](std::size_t idx);
51 const T& operator()(std::size_t x, std::size_t y)
const;
52 T& operator()(std::size_t x, std::size_t y);
61 matrix<T, N> operator+(T scalar)
const{
auto cpy = *
this;
return cpy += scalar;}
63 matrix<T, N> operator-(T scalar)
const{
auto cpy = *
this;
return cpy -= scalar;}
64 matrix<T, N>& operator*=(T scalar);
65 matrix<T, N> operator*(T scalar)
const{
auto cpy = *
this;
return cpy *= scalar;}
66 matrix<T, N>& operator/=(T scalar);
67 matrix<T, N> operator/(T scalar)
const{
auto cpy = *
this;
return cpy /= scalar;}
70 matrix<T, N>& operator*=(
const matrix<T, N>& rhs);
71 matrix<T, N> operator*(
const matrix<T, N>& rhs)
const{
auto cpy = *
this;
return cpy *= rhs;}
73 bool operator==(
const matrix<T, N>& rhs)
const =
default;
76 std::array<T, N*N> mat;
79 using m2i = matrix<int, 2>;
80 using m3i = matrix<int, 3>;
81 using m4i = matrix<int, 4>;
82 using m2u = matrix<unsigned int, 2>;
83 using m3u = matrix<unsigned int, 3>;
84 using m4u = matrix<unsigned int, 4>;
85 using m2f = matrix<float, 2>;
86 using m3f = matrix<float, 3>;
87 using m4f = matrix<float, 4>;
88 using m2d = matrix<double, 2>;
89 using m3d = matrix<double, 3>;
90 using m4d = matrix<double, 4>;
Represents the generic matrix.
Definition matrix.hpp:16
static constexpr matrix< T, N > filled(T t)
Retrieve a matrix filled with the given value.
Definition matrix.hpp:35
static constexpr matrix< T, N > zero()
Retrieve a matrix filled with zeroes.
Definition matrix.hpp:18
matrix< T, N > inverse() const
Create a matrix that causes the inverse transformation. Such that the product of this and the result ...
static constexpr matrix< T, N > iden()
Retrieve an identity matrix that represents no transform.
Definition matrix.hpp:24
matrix< T, N > transpose() const
Retrieve a copy of this matrix but with its rows and columns swapped.