sandbox
Loading...
Searching...
No Matches
matrix3x3.hpp
1#ifndef LIBSBX_MATH_MATRIX3X3_HPP_
2#define LIBSBX_MATH_MATRIX3X3_HPP_
3
4#include <array>
5#include <cstddef>
6#include <cmath>
7#include <cinttypes>
8#include <concepts>
9#include <fstream>
10#include <ostream>
11#include <type_traits>
12
13#include <fmt/format.h>
14
15#include <libsbx/math/concepts.hpp>
16#include <libsbx/math/fwd.hpp>
17#include <libsbx/math/vector3.hpp>
18#include <libsbx/math/vector4.hpp>
19#include <libsbx/math/matrix.hpp>
20#include <libsbx/math/angle.hpp>
21
22namespace sbx::math {
23
24template<scalar Type>
25class basic_matrix3x3 : public basic_matrix<3u, 3u, Type> {
26
28
29 template<scalar Other>
31
32 inline static constexpr auto x_axis = std::size_t{0u};
33 inline static constexpr auto y_axis = std::size_t{1u};
34 inline static constexpr auto z_axis = std::size_t{2u};
35
36public:
37
38 using value_type = base_type::value_type;
39 using reference = base_type::reference;
40 using const_reference = base_type::const_reference;
41 using size_type = base_type::size_type;
43
44 inline static constexpr basic_matrix3x3 identity{base_type::identity()};
45
46 inline static constexpr basic_matrix3x3 zero{base_type{value_type{0}}};
47
48 using base_type::base_type;
49
50 constexpr basic_matrix3x3(const base_type& base) noexcept;
51
52 template<typename Column>
53 constexpr basic_matrix3x3(
54 Column&& column0,
55 Column&& column1,
56 Column&& column2
57 ) noexcept;
58
59 template<scalar Other>
60 constexpr basic_matrix3x3(
61 Other x0, Other x1, Other x2,
62 Other y0, Other y1, Other y2,
63 Other z0, Other z1, Other z2
64 ) noexcept;
65
66 template<scalar Other>
67 constexpr basic_matrix3x3(const Other v00, const Other v11, const Other v22) noexcept;
68
69// // -- Static member functions --
70
71 [[nodiscard]] constexpr static auto transposed(const basic_matrix3x3& matrix) noexcept -> basic_matrix3x3 {
72 auto result = basic_matrix3x3<value_type>{};
73
74 result[0][0] = matrix[0][0];
75 result[0][1] = matrix[1][0];
76 result[0][2] = matrix[2][0];
77
78 result[1][0] = matrix[0][1];
79 result[1][1] = matrix[1][1];
80 result[1][2] = matrix[2][1];
81
82 result[2][0] = matrix[0][2];
83 result[2][1] = matrix[1][2];
84 result[2][2] = matrix[2][2];
85
86 return result;
87 }
88
89 [[nodiscard]] constexpr static auto abs(const basic_matrix3x3& matrix) noexcept -> basic_matrix3x3 {
90 return basic_matrix3x3{
91 column_type::abs(matrix[0]),
92 column_type::abs(matrix[1]),
93 column_type::abs(matrix[2])
94 };
95 }
96
97 // [[nodiscard]] constexpr static auto inverted(const basic_matrix3x3& matrix) -> basic_matrix3x3;
98
99 // [[nodiscard]] constexpr static auto perspective(const basic_angle<value_type>& fov, const value_type aspect, const value_type near, const value_type far) noexcept -> basic_matrix3x3;
100
101 // [[nodiscard]] constexpr static auto translated(const basic_matrix3x3& matrix, const basic_vector3<value_type>& vector) noexcept -> basic_matrix3x3;
102
103 // [[nodiscard]] constexpr static auto scaled(const basic_matrix3x3& matrix, const basic_vector3<value_type>& vector) noexcept -> basic_matrix3x3;
104
105 // [[nodiscard]] constexpr static auto rotated(const basic_matrix3x3& matrix, const basic_vector3<value_type>& axis, const basic_angle<value_type>& angle) noexcept -> basic_matrix3x3;
106
107 // [[nodiscard]] constexpr static auto rotation_from_euler_angles(const basic_vector3<value_type>& euler_angles) noexcept -> basic_matrix3x3;
108
109 constexpr auto operator[](size_type index) const noexcept -> const column_type&;
110
111 constexpr auto operator[](size_type index) noexcept -> column_type&;
112
113}; // class basic_matrix3x3
114
115// template<scalar Lhs, scalar Rhs>
116// [[nodiscard]] constexpr auto operator+(basic_matrix3x3<Lhs> lhs, const basic_matrix3x3<Rhs>& rhs) noexcept -> basic_matrix3x3<Lhs>;
117
118// template<scalar Lhs, scalar Rhs>
119// [[nodiscard]] constexpr auto operator-(basic_matrix3x3<Lhs> lhs, const basic_matrix3x3<Rhs>& rhs) noexcept -> basic_matrix3x3<Lhs>;
120
121// template<scalar Lhs, scalar Rhs>
122// [[nodiscard]] constexpr auto operator*(basic_matrix3x3<Lhs> lhs, Rhs scalar) noexcept -> basic_matrix3x3<Lhs>;
123
124template<scalar Lhs, scalar Rhs>
125[[nodiscard]] constexpr auto operator*(basic_matrix3x3<Lhs> lhs, const basic_vector3<Rhs>& rhs) noexcept -> basic_vector3<Lhs>;
126
127template<scalar Lhs, scalar Rhs>
128[[nodiscard]] constexpr auto operator*(basic_matrix3x3<Lhs> lhs, const basic_matrix3x3<Rhs>& rhs) noexcept -> basic_matrix3x3<Lhs>;
129
130// template<scalar Lhs, scalar Rhs>
131// [[nodiscard]] constexpr auto operator/(basic_matrix3x3<Lhs> lhs, Rhs scalar) noexcept -> basic_matrix3x3<Lhs>;
132
133template<scalar Type>
134struct concrete_matrix<3, 3, Type> {
136}; // struct concrete_matrix
137
139
141
142using matrix3x3 = matrix3x3f;
143
144} // namespace sbx::math
145
146template<sbx::math::scalar Type>
147struct fmt::formatter<sbx::math::basic_matrix3x3<Type>> {
148
149 template<typename ParseContext>
150 constexpr auto parse(ParseContext& context) -> decltype(context.begin()) {
151 return context.begin();
152 }
153
154 template<typename FormatContext>
155 auto format(const sbx::math::basic_matrix3x3<Type>& matrix, FormatContext& context) -> decltype(context.out()) {
156 if constexpr (sbx::math::is_floating_point_v<Type>) {
157 return fmt::format_to(context.out(),
158 "\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}",
159 matrix[0][0], matrix[1][0], matrix[2][0],
160 matrix[0][1], matrix[1][1], matrix[2][1],
161 matrix[0][2], matrix[1][2], matrix[2][2]
162 );
163 } else {
164 return fmt::format_to(context.out(),
165 "\n{}, {}, {}\n{}, {}, {}\n{}, {}, {}\n{}, {}, {}",
166 matrix[0][0], matrix[1][0], matrix[2][0],
167 matrix[0][1], matrix[1][1], matrix[2][1],
168 matrix[0][2], matrix[1][2], matrix[2][2]
169 );
170 }
171 }
172
173}; // struct fmt::formatter
174
175#include <libsbx/math/matrix3x3.ipp>
176
177#endif // LIBSBX_MATH_MATRIX3X3_HPP_
Definition: matrix3x3.hpp:25
Definition: matrix.hpp:13
Definition: vector3.hpp:22
Definition: fwd.hpp:16