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 using value_type = Type;
18 using reference = value_type&;
19 using const_reference = const value_type&;
20 using size_type = std::size_t;
22
23 template<scalar Other = value_type>
24 constexpr basic_matrix(Other value = Other{0}) noexcept;
25
26 [[nodiscard]] constexpr auto operator[](size_type index) noexcept -> column_type&;
27
28 [[nodiscard]] constexpr auto operator[](size_type index) const noexcept -> const column_type&;
29
30 template<scalar Other>
31 constexpr auto operator+=(const basic_matrix<Columns, Rows, Other>& other) noexcept -> basic_matrix&;
32
33 template<scalar Other>
34 constexpr auto operator-=(const basic_matrix<Columns, Rows, Other>& other) noexcept -> basic_matrix&;
35
36 template<scalar Other>
37 constexpr auto operator*=(Other scalar) noexcept -> basic_matrix&;
38
39 template<scalar Other>
40 constexpr auto operator/=(Other scalar) noexcept -> basic_matrix&;
41
42protected:
43
44 template<scalar Other>
46
47 template<typename... Args>
48 constexpr basic_matrix(Args&&... args) noexcept;
49
50 constexpr static auto identity() noexcept -> basic_matrix;
51
52private:
53
54 std::array<column_type, Columns> _columns;
55
56}; // class basic_matrix
57
58template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
59[[nodiscard]] constexpr auto operator==(const basic_matrix<Columns, Rows, Lhs>& lhs, const basic_matrix<Columns, Rows, Rhs>& rhs) noexcept -> bool;
60
61template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
62[[nodiscard]] constexpr auto operator+(basic_matrix<Columns, Rows, Lhs> lhs, const basic_matrix<Columns, Rows, Rhs>& rhs) noexcept -> basic_matrix<Columns, Rows, Lhs>;
63
64template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
65[[nodiscard]] constexpr auto operator-(basic_matrix<Columns, Rows, Lhs> lhs, const basic_matrix<Columns, Rows, Rhs>& rhs) noexcept -> basic_matrix<Columns, Rows, Lhs>;
66
67template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
68[[nodiscard]] constexpr auto operator*(basic_matrix<Columns, Rows, Lhs> lhs, Rhs rhs) noexcept -> basic_matrix<Columns, Rows, Lhs>;
69
70template<std::size_t Columns, std::size_t Rows, scalar Lhs, scalar Rhs>
71[[nodiscard]] constexpr auto operator*(Lhs lhs, basic_matrix<Columns, Rows, Rhs> rhs) noexcept -> basic_matrix<Columns, Rows, Rhs>;
72
73} // namespace sbx::math
74
75#include <libsbx/math/matrix.ipp>
76
77#endif // LIBSBX_MATH_MATRIX_HPP_
Definition: matrix.hpp:13
Definition: vector.hpp:19