utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
matrix.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "utility/math/matrix.hpp"
24
25namespace utility::math
26{
27 std::ostream &operator<<(std::ostream &stream, const Matrix2x2F &matrix)
28 {
29 stream << "Matrix2x2F(";
30 for (std::size_t row = 0; row < 2; ++row) {
31 stream << "[";
32 for (std::size_t col = 0; col < 2; ++col) {
33 stream << matrix[col][row];
34 if (col < 1) {
35 stream << ", ";
36 }
37 }
38 stream << "]";
39 if (row < 1) {
40 stream << ", ";
41 }
42 }
43 stream << ")";
44 return stream;
45 }
46
47 std::ostream &operator<<(std::ostream &stream, const Matrix2x2D &matrix)
48 {
49 stream << "Matrix2x2D(";
50 for (std::size_t row = 0; row < 2; ++row) {
51 stream << "[";
52 for (std::size_t col = 0; col < 2; ++col) {
53 stream << matrix[col][row];
54 if (col < 1) {
55 stream << ", ";
56 }
57 }
58 stream << "]";
59 if (row < 1) {
60 stream << ", ";
61 }
62 }
63 stream << ")";
64 return stream;
65 }
66
67 std::ostream &operator<<(std::ostream &stream, const Matrix2x3F &matrix)
68 {
69 stream << "Matrix2x3F(";
70 for (std::size_t row = 0; row < 2; ++row) {
71 stream << "[";
72 for (std::size_t col = 0; col < 3; ++col) {
73 stream << matrix[col][row];
74 if (col < 2) {
75 stream << ", ";
76 }
77 }
78 stream << "]";
79 if (row < 1) {
80 stream << ", ";
81 }
82 }
83 stream << ")";
84 return stream;
85 }
86
87 std::ostream &operator<<(std::ostream &stream, const Matrix2x3D &matrix)
88 {
89 stream << "Matrix2x3D(";
90 for (std::size_t row = 0; row < 2; ++row) {
91 stream << "[";
92 for (std::size_t col = 0; col < 3; ++col) {
93 stream << matrix[col][row];
94 if (col < 2) {
95 stream << ", ";
96 }
97 }
98 stream << "]";
99 if (row < 1) {
100 stream << ", ";
101 }
102 }
103 stream << ")";
104 return stream;
105 }
106
107 std::ostream &operator<<(std::ostream &stream, const Matrix3x2F &matrix)
108 {
109 stream << "Matrix3x2F(";
110 for (std::size_t row = 0; row < 3; ++row) {
111 stream << "[";
112 for (std::size_t col = 0; col < 2; ++col) {
113 stream << matrix[col][row];
114 if (col < 1) {
115 stream << ", ";
116 }
117 }
118 stream << "]";
119 if (row < 2) {
120 stream << ", ";
121 }
122 }
123 stream << ")";
124 return stream;
125 }
126
127 std::ostream &operator<<(std::ostream &stream, const Matrix3x2D &matrix)
128 {
129 stream << "Matrix3x2D(";
130 for (std::size_t row = 0; row < 3; ++row) {
131 stream << "[";
132 for (std::size_t col = 0; col < 2; ++col) {
133 stream << matrix[col][row];
134 if (col < 1) {
135 stream << ", ";
136 }
137 }
138 stream << "]";
139 if (row < 2) {
140 stream << ", ";
141 }
142 }
143 stream << ")";
144 return stream;
145 }
146
147 std::ostream &operator<<(std::ostream &stream, const Matrix3x3F &matrix)
148 {
149 stream << "Matrix3x3F(";
150 for (std::size_t row = 0; row < 3; ++row) {
151 stream << "[";
152 for (std::size_t col = 0; col < 3; ++col) {
153 stream << matrix[col][row];
154 if (col < 2) {
155 stream << ", ";
156 }
157 }
158 stream << "]";
159 if (row < 2) {
160 stream << ", ";
161 }
162 }
163 stream << ")";
164 return stream;
165 }
166
167 std::ostream &operator<<(std::ostream &stream, const Matrix3x3D &matrix)
168 {
169 stream << "Matrix3x3D(";
170 for (std::size_t row = 0; row < 3; ++row) {
171 stream << "[";
172 for (std::size_t col = 0; col < 3; ++col) {
173 stream << matrix[col][row];
174 if (col < 2) {
175 stream << ", ";
176 }
177 }
178 stream << "]";
179 if (row < 2) {
180 stream << ", ";
181 }
182 }
183 stream << ")";
184 return stream;
185 }
186
187 std::ostream &operator<<(std::ostream &stream, const Matrix3x4F &matrix)
188 {
189 stream << "Matrix3x4F(";
190 for (std::size_t row = 0; row < 3; ++row) {
191 stream << "[";
192 for (std::size_t col = 0; col < 4; ++col) {
193 stream << matrix[col][row];
194 if (col < 3) {
195 stream << ", ";
196 }
197 }
198 stream << "]";
199 if (row < 2) {
200 stream << ", ";
201 }
202 }
203 stream << ")";
204 return stream;
205 }
206
207 std::ostream &operator<<(std::ostream &stream, const Matrix3x4D &matrix)
208 {
209 stream << "Matrix3x4D(";
210 for (std::size_t row = 0; row < 3; ++row) {
211 stream << "[";
212 for (std::size_t col = 0; col < 4; ++col) {
213 stream << matrix[col][row];
214 if (col < 3) {
215 stream << ", ";
216 }
217 }
218 stream << "]";
219 if (row < 2) {
220 stream << ", ";
221 }
222 }
223 stream << ")";
224 return stream;
225 }
226
227 std::ostream &operator<<(std::ostream &stream, const Matrix4x2F &matrix)
228 {
229 stream << "Matrix4x2F(";
230 for (std::size_t row = 0; row < 4; ++row) {
231 stream << "[";
232 for (std::size_t col = 0; col < 2; ++col) {
233 stream << matrix[col][row];
234 if (col < 1) {
235 stream << ", ";
236 }
237 }
238 stream << "]";
239 if (row < 3) {
240 stream << ", ";
241 }
242 }
243 stream << ")";
244 return stream;
245 }
246
247 std::ostream &operator<<(std::ostream &stream, const Matrix4x2D &matrix)
248 {
249 stream << "Matrix4x2D(";
250 for (std::size_t row = 0; row < 4; ++row) {
251 stream << "[";
252 for (std::size_t col = 0; col < 2; ++col) {
253 stream << matrix[col][row];
254 if (col < 1) {
255 stream << ", ";
256 }
257 }
258 stream << "]";
259 if (row < 3) {
260 stream << ", ";
261 }
262 }
263 stream << ")";
264 return stream;
265 }
266
267 std::ostream &operator<<(std::ostream &stream, const Matrix4x3F &matrix)
268 {
269 stream << "Matrix4x3F(";
270 for (std::size_t row = 0; row < 4; ++row) {
271 stream << "[";
272 for (std::size_t col = 0; col < 3; ++col) {
273 stream << matrix[col][row];
274 if (col < 2) {
275 stream << ", ";
276 }
277 }
278 stream << "]";
279 if (row < 3) {
280 stream << ", ";
281 }
282 }
283 stream << ")";
284 return stream;
285 }
286
287 std::ostream &operator<<(std::ostream &stream, const Matrix4x3D &matrix)
288 {
289 stream << "Matrix4x3D(";
290 for (std::size_t row = 0; row < 4; ++row) {
291 stream << "[";
292 for (std::size_t col = 0; col < 3; ++col) {
293 stream << matrix[col][row];
294 if (col < 2) {
295 stream << ", ";
296 }
297 }
298 stream << "]";
299 if (row < 3) {
300 stream << ", ";
301 }
302 }
303 stream << ")";
304 return stream;
305 }
306
307 std::ostream &operator<<(std::ostream &stream, const Matrix4x4F &matrix)
308 {
309 stream << "Matrix4x4F(";
310 for (std::size_t row = 0; row < 4; ++row) {
311 stream << "[";
312 for (std::size_t col = 0; col < 4; ++col) {
313 stream << matrix[col][row];
314 if (col < 3) {
315 stream << ", ";
316 }
317 }
318 stream << "]";
319 if (row < 3) {
320 stream << ", ";
321 }
322 }
323 stream << ")";
324 return stream;
325 }
326
327 std::ostream &operator<<(std::ostream &stream, const Matrix4x4D &matrix)
328 {
329 stream << "Matrix4x4D(";
330 for (std::size_t row = 0; row < 4; ++row) {
331 stream << "[";
332 for (std::size_t col = 0; col < 4; ++col) {
333 stream << matrix[col][row];
334 if (col < 3) {
335 stream << ", ";
336 }
337 }
338 stream << "]";
339 if (row < 3) {
340 stream << ", ";
341 }
342 }
343 stream << ")";
344 return stream;
345 }
346
347} // namespace utility::math