Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Matrix.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21#ifndef GF_MATRIX_H
22#define GF_MATRIX_H
23
24#include <cstddef>
25#include <algorithm>
26
27#include "CoreApi.h"
28#include "Vector.h"
29#include "Types.h"
30
31namespace gf {
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33inline namespace v1 {
34#endif
35
59 template<typename T, std::size_t ROWS, std::size_t COLS>
60 struct Matrix {
61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62 static_assert(ROWS > 0, "ROWS must be strictly positive");
63 static_assert(COLS > 0, "COLS must be strictly positive");
64 #endif
65
69 using value_type = T;
70
74 static constexpr std::size_t Rows = ROWS;
75
79 static constexpr std::size_t Cols = COLS;
80
84 Matrix() = default;
85
86 constexpr Matrix(ZeroType) noexcept
87 {
88 zero();
89 }
90
94 explicit Matrix(T val) noexcept
95 {
96 std::fill_n(data, ROWS * COLS, val);
97 }
98
99 explicit Matrix(const T *array)
100 {
101 std::copy_n(array, ROWS * COLS, data);
102 }
103
104 T operator()(std::size_t row, std::size_t col) const {
105 return grid[row][col];
106 }
107
108 T& operator()(std::size_t row, std::size_t col) {
109 return grid[row][col];
110 }
111
115 constexpr void zero() noexcept {
116 for (std::size_t i = 0; i < ROWS * COLS; ++i) {
117 data[i] = T{};
118 }
119 }
120
124 union {
125 T grid[ROWS][COLS];
126 T data[ROWS * COLS];
127 };
128 };
129
147 template<typename T>
148 struct Matrix<T, 2, 2> {
152 using value_type = T;
153
157 static constexpr std::size_t Rows = 2;
158
162 static constexpr std::size_t Cols = 2;
163
167 Matrix() = default;
168
169 constexpr Matrix(ZeroType) noexcept
170 {
171 zero();
172 }
173
174 explicit constexpr Matrix(T val) noexcept
175 : m11(val), m12(val)
176 , m21(val), m22(val)
177 {
178 }
179
180 explicit constexpr Matrix(const T *array)
181 : m11(array[0]), m12(array[1])
182 , m21(array[2]), m22(array[3])
183 {
184 }
185
194 constexpr Matrix(T e11, T e12, T e21, T e22) noexcept
195 : m11(e11), m12(e12)
196 , m21(e21), m22(e22)
197 {
198 }
199
200 const T *getData() const noexcept {
201 return &m11;
202 }
203
204 T *getData() noexcept {
205 return &m11;
206 }
207
208 T operator()(std::size_t row, std::size_t col) const {
209 const T *grid[Rows][Cols] = {
210 { &m11, &m12 },
211 { &m21, &m22 }
212 };
213 return *grid[row][col];
214 }
215
216 T& operator()(std::size_t row, std::size_t col) {
217 T *grid[Rows][Cols] = {
218 { &m11, &m12 },
219 { &m21, &m22 }
220 };
221 return *grid[row][col];
222 }
223
224 constexpr void zero() noexcept {
225 m11 = m12 = T{};
226 m21 = m22 = T{};
227 }
228
229 union {
232 };
233
234 union {
237 };
238
239 union {
242 };
243
244 union {
247 };
248 };
249
267 template<typename T>
268 struct Matrix<T, 3, 3> {
272 using value_type = T;
273
277 static constexpr std::size_t Rows = 3;
278
282 static constexpr std::size_t Cols = 3;
283
287 Matrix() = default;
288
289 constexpr Matrix(ZeroType) noexcept
290 {
291 zero();
292 }
293
294 explicit constexpr Matrix(T val) noexcept
295 : m11(val), m12(val), m13(val)
296 , m21(val), m22(val), m23(val)
297 , m31(val), m32(val), m33(val)
298 {
299 }
300
301 explicit constexpr Matrix(const T *array)
302 : m11(array[0]), m12(array[1]), m13(array[2])
303 , m21(array[3]), m22(array[4]), m23(array[5])
304 , m31(array[6]), m32(array[7]), m33(array[8])
305 {
306 }
307
321 constexpr Matrix(T e11, T e12, T e13, T e21, T e22, T e23, T e31, T e32, T e33) noexcept
322 : m11(e11), m12(e12), m13(e13)
323 , m21(e21), m22(e22), m23(e23)
324 , m31(e31), m32(e32), m33(e33)
325 {
326 }
327
328 const T *getData() const noexcept {
329 return &m11;
330 }
331
332 T *getData() noexcept {
333 return &m11;
334 }
335
336 T operator()(std::size_t row, std::size_t col) const {
337 const T *grid[Rows][Cols] = {
338 { &m11, &m12, &m13 },
339 { &m21, &m22, &m23 },
340 { &m31, &m32, &m33 }
341 };
342 return *grid[row][col];
343 }
344
345 T& operator()(std::size_t row, std::size_t col) {
346 T *grid[Rows][Cols] = {
347 { &m11, &m12, &m13 },
348 { &m21, &m22, &m23 },
349 { &m31, &m32, &m33 }
350 };
351 return *grid[row][col];
352 }
353
354 constexpr void zero() noexcept {
355 m11 = m12 = m13 = T{};
356 m21 = m22 = m23 = T{};
357 m31 = m32 = m33 = T{};
358 }
359
360 union {
363 };
364
365 union {
368 };
369
370 union {
373 };
374
375 union {
378 };
379
380 union {
383 };
384
385 union {
388 };
389
390 union {
393 };
394
395 union {
398 };
399
400 union {
403 };
404 };
405
421 template<typename T>
422 struct Matrix<T, 4, 4> {
426 using value_type = T;
427
431 static constexpr std::size_t Rows = 4;
432
436 static constexpr std::size_t Cols = 4;
437
441 Matrix() = default;
442
443 constexpr Matrix(ZeroType) noexcept
444 {
445 zero();
446 }
447
448 explicit constexpr Matrix(T val) noexcept
449 : m11(val), m12(val), m13(val), m14(val)
450 , m21(val), m22(val), m23(val), m24(val)
451 , m31(val), m32(val), m33(val), m34(val)
452 , m41(val), m42(val), m43(val), m44(val)
453 {
454 }
455
456 explicit constexpr Matrix(const T *array)
457 : m11(array[ 0]), m12(array[ 1]), m13(array[ 2]), m14(array[ 3])
458 , m21(array[ 4]), m22(array[ 5]), m23(array[ 6]), m24(array[ 7])
459 , m31(array[ 8]), m32(array[ 9]), m33(array[10]), m34(array[11])
460 , m41(array[12]), m42(array[13]), m43(array[14]), m44(array[15])
461 {
462 }
463
484 constexpr Matrix(T e11, T e12, T e13, T e14, T e21, T e22, T e23, T e24, T e31, T e32, T e33, T e34, T e41, T e42, T e43, T e44) noexcept
485 : m11(e11), m12(e12), m13(e13), m14(e14)
486 , m21(e21), m22(e22), m23(e23), m24(e24)
487 , m31(e31), m32(e32), m33(e33), m34(e34)
488 , m41(e41), m42(e42), m43(e43), m44(e44)
489 {
490 }
491
492 const T *getData() const noexcept {
493 return &m11;
494 }
495
496 T *getData() noexcept {
497 return &m11;
498 }
499
500 T operator()(std::size_t row, std::size_t col) const {
501 const T *grid[Rows][Cols] = {
502 { &m11, &m12, &m13, &m14 },
503 { &m21, &m22, &m23, &m24 },
504 { &m31, &m32, &m33, &m34 },
505 { &m41, &m42, &m43, &m44 }
506 };
507 return *grid[row][col];
508 }
509
510 T& operator()(std::size_t row, std::size_t col) {
511 T *grid[Rows][Cols] = {
512 { &m11, &m12, &m13, &m14 },
513 { &m21, &m22, &m23, &m24 },
514 { &m31, &m32, &m33, &m34 },
515 { &m41, &m42, &m43, &m44 }
516 };
517 return *grid[row][col];
518 }
519
520 constexpr void zero() noexcept {
521 m11 = m12 = m13 = m14 = T{};
522 m21 = m22 = m23 = m24 = T{};
523 m31 = m32 = m33 = m34 = T{};
524 m41 = m42 = m43 = m44 = T{};
525 }
526
527 union {
530 };
531
532 union {
535 };
536
537 union {
540 };
541
542 union {
545 };
546
547 union {
550 };
551
552 union {
555 };
556
557 union {
560 };
561
562 union {
565 };
566
567 union {
570 };
571
572 union {
575 };
576
577 union {
580 };
581
582 union {
585 };
586
587 union {
590 };
591
592 union {
595 };
596
597 union {
600 };
601
602 union {
605 };
606 };
607
615
623
631
639
647
655
656// MSVC does not like extern template
657#ifndef _MSC_VER
658 extern template struct GF_CORE_API Matrix<float, 2, 2>;
659 extern template struct GF_CORE_API Matrix<float, 3, 3>;
660 extern template struct GF_CORE_API Matrix<float, 4, 4>;
661
662 extern template struct GF_CORE_API Matrix<double, 2, 2>;
663 extern template struct GF_CORE_API Matrix<double, 3, 3>;
664 extern template struct GF_CORE_API Matrix<double, 4, 4>;
665#endif
666
667 /*
668 * equality operations
669 */
670
675 template<typename T, std::size_t ROWS, std::size_t COLS>
676 constexpr
678 for (std::size_t i = 0; i < ROWS; ++i) {
679 for (std::size_t j = 0; j < COLS; ++j) {
680 if (lhs(i,j) != rhs(i,j)) {
681 return false;
682 }
683 }
684 }
685
686 return true;
687 }
688
693 template<typename T, std::size_t ROWS, std::size_t COLS>
694 constexpr
696 return !(lhs == rhs);
697 }
698
699 /*
700 * unary operators
701 */
702
707 template<typename T, std::size_t ROWS, std::size_t COLS>
708 constexpr
711
712 for (std::size_t i = 0; i < ROWS; ++i) {
713 for (std::size_t j = 0; j < COLS; ++j) {
714 out(i,j) = - val(i,j);
715 }
716 }
717
718 return out;
719 }
720
721 /*
722 * arithmetic component-wise operations
723 */
724
729 template<typename T, std::size_t ROWS, std::size_t COLS>
730 constexpr
733
734 for (std::size_t i = 0; i < ROWS; ++i) {
735 for (std::size_t j = 0; j < COLS; ++j) {
736 out(i,j) = lhs(i,j) + rhs(i,j);
737 }
738 }
739
740 return out;
741 }
742
747 template<typename T, std::size_t ROWS, std::size_t COLS>
748 constexpr
750 for (std::size_t i = 0; i < ROWS; ++i) {
751 for (std::size_t j = 0; j < COLS; ++j) {
752 lhs(i,j) += rhs(i,j);
753 }
754 }
755
756 return lhs;
757 }
758
759
764 template<typename T, std::size_t ROWS, std::size_t COLS>
765 constexpr
768
769 for (std::size_t i = 0; i < ROWS; ++i) {
770 for (std::size_t j = 0; j < COLS; ++j) {
771 out(i,j) = lhs(i,j) - rhs(i,j);
772 }
773 }
774
775 return out;
776 }
777
782 template<typename T, std::size_t ROWS, std::size_t COLS>
783 constexpr
785 for (std::size_t i = 0; i < ROWS; ++i) {
786 for (std::size_t j = 0; j < COLS; ++j) {
787 lhs(i,j) -= rhs(i,j);
788 }
789 }
790
791 return lhs;
792 }
793
794 /*
795 * multiplication and division
796 */
797
802 template<typename T, std::size_t ROWS, std::size_t COLS>
803 constexpr
806
807 for (std::size_t i = 0; i < ROWS; ++i) {
808 for (std::size_t j = 0; j < COLS; ++j) {
809 out(i,j) = lhs(i,j) * rhs;
810 }
811 }
812
813 return out;
814 }
815
820 template<typename T, std::size_t ROWS, std::size_t COLS>
821 constexpr
823 for (std::size_t i = 0; i < ROWS; ++i) {
824 for (std::size_t j = 0; j < COLS; ++j) {
825 lhs(i,j) *= rhs;
826 }
827 }
828
829 return lhs;
830 }
831
836 template<typename T, std::size_t ROWS, std::size_t COLS>
837 constexpr
840
841 for (std::size_t i = 0; i < ROWS; ++i) {
842 for (std::size_t j = 0; j < COLS; ++j) {
843 out(i,j) = lhs * rhs(i,j);
844 }
845 }
846
847 return out;
848 }
849
854 template<typename T, std::size_t ROWS, std::size_t COLS>
855 constexpr
858
859 for (std::size_t i = 0; i < ROWS; ++i) {
860 for (std::size_t j = 0; j < COLS; ++j) {
861 out(i,j) = lhs(i,j) / rhs;
862 }
863 }
864
865 return out;
866 }
867
872 template<typename T, std::size_t ROWS, std::size_t COLS>
873 constexpr
875 for (std::size_t i = 0; i < ROWS; ++i) {
876 for (std::size_t j = 0; j < COLS; ++j) {
877 lhs(i,j) /= rhs;
878 }
879 }
880
881 return lhs;
882 }
883
888 template<typename T, std::size_t S1, std::size_t S2>
889 constexpr
892
893 for (std::size_t i = 0; i < S1; ++i) {
894 T val{0};
895
896 for (std::size_t j = 0; j < S2; ++j) {
897 val += lhs(i,j) * rhs[j];
898 }
899
900 out[i] = val;
901 }
902
903 return out;
904 }
905
910 template<typename T, std::size_t S1, std::size_t S2>
911 constexpr
914
915 for (std::size_t j = 0; j < S2; ++j) {
916 T val{0};
917
918 for (std::size_t i = 0; i < S1; ++i) {
919 val += lhs[i] * rhs(i,j);
920 }
921
922 out[j] = val;
923 }
924
925 return out;
926 }
927
928
933 template<typename T, std::size_t S1, std::size_t S2, std::size_t S3>
934 constexpr
937
938 for (std::size_t i = 0; i < S1; ++i) {
939 for (std::size_t j = 0; j < S3; ++j) {
940 T val{0};
941
942 for (std::size_t k = 0; k < S2; ++k) {
943 val += lhs(i,k) * rhs(k,j);
944 }
945
946 out(i,j) = val;
947 }
948 }
949
950 return out;
951 }
952
959 template<typename T, std::size_t N>
960 constexpr
962 lhs = lhs * rhs;
963 return lhs;
964 }
965
966 /*
967 * usual operations
968 */
969
976 template<typename MatrixType>
977 constexpr
978 MatrixType identity() {
979 static_assert(MatrixType::Rows == MatrixType::Cols, "identity() is only defined for square matrices.");
980
981 MatrixType out = gf::Zero;
982
983 typedef typename MatrixType::value_type value_type;
984
985 for (std::size_t i = 0; i < MatrixType::Rows; ++i) {
986 for (std::size_t j = 0; j < MatrixType::Cols; ++j) {
987 out(i,j) = (i == j) ? value_type{1} : value_type{0};
988 }
989 }
990
991 return out;
992 }
993
998 template<typename T, std::size_t S1, std::size_t S2>
999 constexpr
1002
1003 for (std::size_t i = 0; i < S1; ++i) {
1004 for (std::size_t j = 0; j < S2; ++j) {
1005 out(j,i) = mat(i,j);
1006 }
1007 }
1008
1009 return out;
1010 }
1011
1012 // https://en.wikipedia.org/wiki/Invertible_matrix
1013
1018 template<typename T>
1019 constexpr
1022
1023 out.xx = mat.yy;
1024 out.xy = - mat.xy;
1025 out.yx = - mat.yx;
1026 out.yy = mat.xx;
1027
1028 T det = mat.xx * mat.yy - mat.yx * mat.xy;
1029 out /= det;
1030 return out;
1031 }
1032
1037 template<typename T>
1038 constexpr
1041
1042 out.xx = mat.yy * mat.zz - mat.zy * mat.yz;
1043 out.xy = - (mat.xy * mat.zz - mat.zy * mat.xz);
1044 out.xz = mat.xy * mat.yz - mat.yy * mat.xz;
1045 out.yx = - (mat.yx * mat.zz - mat.zx * mat.yz);
1046 out.yy = mat.xx * mat.zz - mat.zx * mat.xz;
1047 out.yz = - (mat.xx * mat.yz - mat.yx * mat.xz);
1048 out.zx = mat.yx * mat.zy - mat.zx * mat.yy;
1049 out.zy = - (mat.xx * mat.zy - mat.zx * mat.xy);
1050 out.zz = mat.xx * mat.yy - mat.yx * mat.xy;
1051
1052 T det = mat.xx * out.xx + mat.xy * out.yx + mat.xz * out.zx;
1053 out /= det;
1054 return out;
1055 }
1056
1057#ifndef DOXYGEN_SHOULD_SKIP_THIS
1058}
1059#endif
1060}
1061
1062#endif // GAME_MATRIX_H
constexpr ZeroType Zero
Constant to represent "zero".
Definition: Types.h:93
The namespace for gf classes.
A 2x2 matrix.
Definition: Matrix.h:148
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:169
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:152
T m11
Definition: Matrix.h:231
T * getData() noexcept
Definition: Matrix.h:204
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:216
T xy
Definition: Matrix.h:235
constexpr void zero() noexcept
Definition: Matrix.h:224
T m21
Definition: Matrix.h:241
constexpr Matrix(const T *array)
Definition: Matrix.h:180
constexpr Matrix(T e11, T e12, T e21, T e22) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:194
T m12
Definition: Matrix.h:236
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:208
Matrix()=default
Default constructor.
T m22
Definition: Matrix.h:246
const T * getData() const noexcept
Definition: Matrix.h:200
T xx
Definition: Matrix.h:230
constexpr Matrix(T val) noexcept
Definition: Matrix.h:174
T yy
Definition: Matrix.h:245
T yx
Definition: Matrix.h:240
A 3x3 matrix.
Definition: Matrix.h:268
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:345
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:272
T xy
Definition: Matrix.h:366
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:336
T yy
Definition: Matrix.h:381
constexpr void zero() noexcept
Definition: Matrix.h:354
T m33
Definition: Matrix.h:402
T zz
Definition: Matrix.h:401
T yx
Definition: Matrix.h:376
T m32
Definition: Matrix.h:397
T m12
Definition: Matrix.h:367
constexpr Matrix(T val) noexcept
Definition: Matrix.h:294
T m21
Definition: Matrix.h:377
T yz
Definition: Matrix.h:386
T zy
Definition: Matrix.h:396
constexpr Matrix(T e11, T e12, T e13, T e21, T e22, T e23, T e31, T e32, T e33) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:321
T * getData() noexcept
Definition: Matrix.h:332
T zx
Definition: Matrix.h:391
T m31
Definition: Matrix.h:392
T m11
Definition: Matrix.h:362
T xz
Definition: Matrix.h:371
T m23
Definition: Matrix.h:387
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:289
const T * getData() const noexcept
Definition: Matrix.h:328
T m22
Definition: Matrix.h:382
T m13
Definition: Matrix.h:372
constexpr Matrix(const T *array)
Definition: Matrix.h:301
T xx
Definition: Matrix.h:361
Matrix()=default
Default constructor.
T yx
Definition: Matrix.h:548
T xz
Definition: Matrix.h:538
T xy
Definition: Matrix.h:533
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:426
T m33
Definition: Matrix.h:579
T m23
Definition: Matrix.h:559
constexpr Matrix(T val) noexcept
Definition: Matrix.h:448
Matrix()=default
Default constructor.
constexpr Matrix(const T *array)
Definition: Matrix.h:456
T yy
Definition: Matrix.h:553
const T * getData() const noexcept
Definition: Matrix.h:492
T wz
Definition: Matrix.h:598
T yw
Definition: Matrix.h:563
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:443
T m43
Definition: Matrix.h:599
T m42
Definition: Matrix.h:594
T xw
Definition: Matrix.h:543
T m44
Definition: Matrix.h:604
T zz
Definition: Matrix.h:578
T m34
Definition: Matrix.h:584
T m11
Definition: Matrix.h:529
T zw
Definition: Matrix.h:583
T wx
Definition: Matrix.h:588
constexpr Matrix(T e11, T e12, T e13, T e14, T e21, T e22, T e23, T e24, T e31, T e32, T e33, T e34, T e41, T e42, T e43, T e44) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:484
T ww
Definition: Matrix.h:603
T m32
Definition: Matrix.h:574
T m14
Definition: Matrix.h:544
T m12
Definition: Matrix.h:534
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:500
T m41
Definition: Matrix.h:589
T * getData() noexcept
Definition: Matrix.h:496
T wy
Definition: Matrix.h:593
T yz
Definition: Matrix.h:558
T zy
Definition: Matrix.h:573
T m24
Definition: Matrix.h:564
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:510
T m31
Definition: Matrix.h:569
T xx
Definition: Matrix.h:528
T m13
Definition: Matrix.h:539
T m22
Definition: Matrix.h:554
T zx
Definition: Matrix.h:568
constexpr void zero() noexcept
Definition: Matrix.h:520
T m21
Definition: Matrix.h:549
General purpose math matrix.
Definition: Matrix.h:60
constexpr Matrix< T, ROWS, COLS > operator*(T lhs, const Matrix< T, ROWS, COLS > &rhs)
Left scalar multiplication.
Definition: Matrix.h:838
constexpr Matrix< T, ROWS, COLS > & operator-=(Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction and assignment.
Definition: Matrix.h:784
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:108
constexpr Matrix< T, ROWS, COLS > operator+(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise addition.
Definition: Matrix.h:731
constexpr bool operator==(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Equality operator between two matrices.
Definition: Matrix.h:677
constexpr Matrix< T, N, N > & operator*=(Matrix< T, N, N > &lhs, const Matrix< T, N, N > &rhs)
Matrix-matrix multiplication and assignment.
Definition: Matrix.h:961
Matrix(const T *array)
Definition: Matrix.h:99
constexpr Matrix< T, 2, 2 > invert(const Matrix< T, 2, 2 > &mat)
Inversion of a 2x2 matrix.
Definition: Matrix.h:1020
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &val)
Component-wise unary minus.
Definition: Matrix.h:709
constexpr void zero() noexcept
Zero out the matrix.
Definition: Matrix.h:115
constexpr MatrixType identity()
Identity matrix.
Definition: Matrix.h:978
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:104
constexpr Vector< T, S2 > operator*(const Vector< T, S1 > &lhs, const Matrix< T, S1, S2 > &rhs)
Vector-matrix multiplication.
Definition: Matrix.h:912
constexpr Matrix< T, 3, 3 > invert(const Matrix< T, 3, 3 > &mat)
Inversion of a 3x3 matrix.
Definition: Matrix.h:1039
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction.
Definition: Matrix.h:766
constexpr Matrix< T, ROWS, COLS > & operator+=(Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise addition and assignment.
Definition: Matrix.h:749
constexpr Vector< T, S1 > operator*(const Matrix< T, S1, S2 > &lhs, const Vector< T, S2 > &rhs)
Matrix-vector multiplication.
Definition: Matrix.h:890
constexpr Matrix< T, ROWS, COLS > & operator*=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication and assignment.
Definition: Matrix.h:822
Matrix(T val) noexcept
Constructor that fills the matrix with a value.
Definition: Matrix.h:94
constexpr Matrix< T, ROWS, COLS > operator/(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division.
Definition: Matrix.h:856
Matrix()=default
Default constructor.
constexpr Matrix< T, S2, S1 > transpose(const Matrix< T, S1, S2 > &mat)
Transposition of a matrix.
Definition: Matrix.h:1000
constexpr Matrix< T, ROWS, COLS > & operator/=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division and assignment.
Definition: Matrix.h:874
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:69
constexpr bool operator!=(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Inequality operator between two matrices.
Definition: Matrix.h:695
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:86
constexpr Matrix< T, ROWS, COLS > operator*(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication.
Definition: Matrix.h:804
constexpr Matrix< T, S1, S3 > operator*(const Matrix< T, S1, S2 > &lhs, const Matrix< T, S2, S3 > &rhs)
Matrix-matrix multiplication.
Definition: Matrix.h:935
General purpose math vector.
Definition: Vector.h:61
Semantic type to represent "zero".
Definition: Types.h:85