sandbox
Loading...
Searching...
No Matches
matrix.hpp
1#ifndef LIBSBX_MATH_MATRIX_HPP_
2#define LIBSBX_MATH_MATRIX_HPP_
3
4#include <array>
5
6#include <libsbx/math/concepts.hpp>
7#include <libsbx/math/vector.hpp>
8
9namespace sbx::math {
10
11template<std::size_t Columns, std::size_t Rows, scalar Type>
12requires (Columns > 1u && Rows > 1u)
14
15public:
16
17 enum class direction : std::uint8_t {
18 column = 0u,
19 row = 1u
20 }; // enum class direction
21
22 inline static constexpr auto columns = Columns;
23 inline static constexpr auto rows = Rows;
24
25 using value_type = Type;
26 using reference = value_type&;
27 using const_reference = const value_type&;
28 using size_type = std::size_t;
30
31 template<scalar Other = value_type>
32 constexpr basic_matrix(Other value = Other{0}) noexcept;
33
34 template<scalar Other = value_type>
35 constexpr basic_matrix(const basic_matrix<Columns, Rows, Other>& other) noexcept;
36
37 constexpr basic_matrix(const basic_matrix& other) noexcept = default;
38
39 constexpr basic_matrix(basic_matrix&& other) noexcept = default;
40
41 auto operator=(const basic_matrix& other) noexcept -> basic_matrix& = default;
42
43 auto operator=(basic_matrix&& other) noexcept -> basic_matrix& = default;
44
45 [[nodiscard]] constexpr auto operator[](size_type index) noexcept -> column_type&;
46
47 [[nodiscard]] constexpr auto operator[](size_type index) const noexcept -> const column_type&;
48
49 template<scalar Other>
50 constexpr auto operator+=(const basic_matrix<Columns, Rows, Other>& other) noexcept -> basic_matrix&;
51
52 template<scalar Other>
53 constexpr auto operator-=(const basic_matrix<Columns, Rows, Other>& other) noexcept -> basic_matrix&;
54
55 template<scalar Other>
56 constexpr auto operator*=(Other scalar) noexcept -> basic_matrix&;
57
58 template<scalar Other>
59 constexpr auto operator/=(Other scalar) noexcept -> basic_matrix&;
60
61 constexpr auto row(const size_type row) const noexcept -> basic_vector<Columns, value_type>;
62
63protected:
64
65 template<scalar Other>
67
68 template<typename... Args>
69 constexpr basic_matrix(Args&&... args) noexcept;
70
71 constexpr static auto identity() noexcept -> basic_matrix;
72
73private:
74
75 std::array<column_type, Columns> _columns;
76
77}; // class basic_matrix
78
79template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
80[[nodiscard]] constexpr auto operator==(const basic_matrix<Columns, Rows, Lhs>& lhs, const basic_matrix<Columns, Rows, Rhs>& rhs) noexcept -> bool;
81
82template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
83[[nodiscard]] constexpr auto operator+(basic_matrix<Columns, Rows, Lhs> lhs, const basic_matrix<Columns, Rows, Rhs>& rhs) noexcept -> basic_matrix<Columns, Rows, Lhs>;
84
85template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
86[[nodiscard]] constexpr auto operator-(basic_matrix<Columns, Rows, Lhs> lhs, const basic_matrix<Columns, Rows, Rhs>& rhs) noexcept -> basic_matrix<Columns, Rows, Lhs>;
87
88template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
89[[nodiscard]] constexpr auto operator*(basic_matrix<Columns, Rows, Lhs> lhs, Rhs rhs) noexcept -> basic_matrix<Columns, Rows, Lhs>;
90
91template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
92[[nodiscard]] constexpr auto operator*(Lhs lhs, basic_matrix<Columns, Rows, Rhs> rhs) noexcept -> basic_matrix<Columns, Rows, Rhs>;
93
94template<typename Matrix>
95[[nodiscard]] constexpr auto from_array(std::span<typename Matrix::value_type, Matrix::columns * Matrix::rows> array) -> Matrix;
96
97} // namespace sbx::math
98
99#include <libsbx/math/matrix.ipp>
100
101#endif // LIBSBX_MATH_MATRIX_HPP_
Definition: matrix.hpp:13
Definition: vector.hpp:22