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/vector3.hpp>
17#include <libsbx/math/vector4.hpp>
18#include <libsbx/math/matrix.hpp>
19#include <libsbx/math/angle.hpp>
20
21namespace sbx::math {
22
23template<scalar Type>
24class basic_matrix3x3 : public basic_matrix<3u, 3u, Type> {
25
27
28 template<scalar Other>
30
31 inline static constexpr auto x_axis = std::size_t{0u};
32 inline static constexpr auto y_axis = std::size_t{1u};
33 inline static constexpr auto z_axis = std::size_t{2u};
34
35public:
36
37 using value_type = base_type::value_type;
38 using reference = base_type::reference;
39 using const_reference = base_type::const_reference;
40 using size_type = base_type::size_type;
42
43 inline static constexpr basic_matrix3x3 identity{base_type::identity()};
44
45 inline static constexpr basic_matrix3x3 zero{base_type{value_type{0}}};
46
47 using base_type::base_type;
48
49 constexpr basic_matrix3x3(const base_type& base) noexcept;
50
51 template<scalar Other>
52 constexpr basic_matrix3x3(
53 const column_type_for<Other>& column0,
54 const column_type_for<Other>& column1,
55 const column_type_for<Other>& column2
56 ) noexcept;
57
58 template<scalar Other>
59 constexpr basic_matrix3x3(
60 Other x0, Other x1, Other x2,
61 Other y0, Other y1, Other y2,
62 Other z0, Other z1, Other z2
63 ) noexcept;
64
65 template<scalar Other>
66 constexpr basic_matrix3x3(const Other v00, const Other v11, const Other v22) noexcept;
67
68// // -- Static member functions --
69
70 // [[nodiscard]] constexpr static auto transposed(const basic_matrix3x3& matrix) noexcept -> basic_matrix3x3;
71
72 // [[nodiscard]] constexpr static auto inverted(const basic_matrix3x3& matrix) -> basic_matrix3x3;
73
74 // [[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;
75
76 // [[nodiscard]] constexpr static auto translated(const basic_matrix3x3& matrix, const basic_vector3<value_type>& vector) noexcept -> basic_matrix3x3;
77
78 // [[nodiscard]] constexpr static auto scaled(const basic_matrix3x3& matrix, const basic_vector3<value_type>& vector) noexcept -> basic_matrix3x3;
79
80 // [[nodiscard]] constexpr static auto rotated(const basic_matrix3x3& matrix, const basic_vector3<value_type>& axis, const basic_angle<value_type>& angle) noexcept -> basic_matrix3x3;
81
82 // [[nodiscard]] constexpr static auto rotation_from_euler_angles(const basic_vector3<value_type>& euler_angles) noexcept -> basic_matrix3x3;
83
84 constexpr auto operator[](size_type index) const noexcept -> const column_type&;
85
86 constexpr auto operator[](size_type index) noexcept -> column_type&;
87
88}; // class basic_matrix3x3
89
90// template<scalar Lhs, scalar Rhs>
91// [[nodiscard]] constexpr auto operator+(basic_matrix3x3<Lhs> lhs, const basic_matrix3x3<Rhs>& rhs) noexcept -> basic_matrix3x3<Lhs>;
92
93// template<scalar Lhs, scalar Rhs>
94// [[nodiscard]] constexpr auto operator-(basic_matrix3x3<Lhs> lhs, const basic_matrix3x3<Rhs>& rhs) noexcept -> basic_matrix3x3<Lhs>;
95
96// template<scalar Lhs, scalar Rhs>
97// [[nodiscard]] constexpr auto operator*(basic_matrix3x3<Lhs> lhs, Rhs scalar) noexcept -> basic_matrix3x3<Lhs>;
98
99template<scalar Lhs, scalar Rhs>
100[[nodiscard]] constexpr auto operator*(basic_matrix3x3<Lhs> lhs, const basic_vector3<Rhs>& rhs) noexcept -> basic_vector3<Lhs>;
101
102// template<scalar Lhs, scalar Rhs>
103// [[nodiscard]] constexpr auto operator*(basic_matrix3x3<Lhs> lhs, const basic_matrix3x3<Rhs>& rhs) noexcept -> basic_matrix3x3<Lhs>;
104
105// template<scalar Lhs, scalar Rhs>
106// [[nodiscard]] constexpr auto operator/(basic_matrix3x3<Lhs> lhs, Rhs scalar) noexcept -> basic_matrix3x3<Lhs>;
107
109
111
112using matrix3x3 = matrix3x3f;
113
114} // namespace sbx::math
115
116template<sbx::math::scalar Type>
117struct fmt::formatter<sbx::math::basic_matrix3x3<Type>> {
118
119 template<typename ParseContext>
120 constexpr auto parse(ParseContext& context) -> decltype(context.begin()) {
121 return context.begin();
122 }
123
124 template<typename FormatContext>
125 auto format(const sbx::math::basic_matrix3x3<Type>& matrix, FormatContext& context) -> decltype(context.out()) {
126 if constexpr (sbx::math::is_floating_point_v<Type>) {
127 return fmt::format_to(context.out(),
128 "\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}",
129 matrix[0][0], matrix[1][0], matrix[2][0],
130 matrix[0][1], matrix[1][1], matrix[2][1],
131 matrix[0][2], matrix[1][2], matrix[2][2]
132 );
133 } else {
134 return fmt::format_to(context.out(),
135 "\n{}, {}, {}\n{}, {}, {}\n{}, {}, {}\n{}, {}, {}",
136 matrix[0][0], matrix[1][0], matrix[2][0],
137 matrix[0][1], matrix[1][1], matrix[2][1],
138 matrix[0][2], matrix[1][2], matrix[2][2]
139 );
140 }
141 }
142
143}; // struct fmt::formatter
144
145#include <libsbx/math/matrix3x3.ipp>
146
147#endif // LIBSBX_MATH_MATRIX3X3_HPP_
Definition: matrix3x3.hpp:24
Definition: matrix.hpp:13
Definition: vector3.hpp:22