acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
matrix.h
1// From draw2d_matrix by camilo on
2// 2023-09-12 11:54 <3ThomasBorregaardSorensen!!
3#pragma once
4
5
6#include "size.h"
7
8
9namespace geometry2d
10{
11
12
13 class CLASS_DECL_ACME matrix
14 {
15 public:
16
17
18 enum e_mode
19 {
20
21 mode_append,
22 mode_prepend,
23
24 };
25
26
27 union
28 {
29 struct
30 {
31
32 ::f64 a1;
33 ::f64 a2;
34 ::f64 a3;
35 ::f64 b1;
36 ::f64 b2;
37 ::f64 b3;
38 ::f64 c1;
39 ::f64 c2;
40 ::f64 c3;
41
42 };
43
44 ::f64 da[9];
45
46 ::f64 a[3][3];
47
48 };
49
50
51 matrix();
52 matrix(const matrix&) = default;
53
54
55 matrix& operator = (const matrix&) = default;
56
57 static matrix translation(::f64_point point) { return translation(point.x, point.y); }
58 static matrix translation(::f64 x, ::f64 y);
59 static matrix rotation(::f64 dAngleRadians);
60 static matrix scaling(::f64 dRateX, ::f64 dRateY);
61 static matrix scaling(::f64_point point) { return scaling(point.x, point.y); }
62 static matrix scaling(f64_size size) { return scaling(size.cx, size.cy); }
63
64
65 matrix& translate(::f64_point point, e_mode emode = mode_append) { return translate(point.x, point.y, emode); }
66 matrix& translate(::f64 x, ::f64 y, e_mode emode = mode_append);
67 matrix& rotate(::f64 dAngleRadians, e_mode emode = mode_append);
68 matrix& scale(::f64 dRateX, ::f64 dRateY, e_mode emode = mode_append);
69 matrix& scale(const ::i32_point& point, e_mode emode = mode_append) { return scale(point.x, point.y, emode); }
70
71
72 matrix& prepend(const matrix& m);
73 matrix& append(const matrix& m);
74
75
76 ::f64 determinant() const;
77
78 static bool invert(matrix& aDst, const matrix& aSrc);
79
80 bool invert()
81 {
82
83 matrix m(*this);
84
85 if (!invert(*this, m))
86 {
87
88 return false;
89
90 }
91
92 return true;
93
94 }
95
96 matrix& operator * (const matrix& m);
97
98 // 6 (six) elements
99 virtual void SetElements(::f32* fa);
100
101
102 void transform(i32_sequence2& point);
103
104 void transform(f64_sequence2& point);
105 void transform(f64_sequence2 * ppoint, ::collection::count c);
106
107 template < prototype_container CONTAINER >
108 void transform(CONTAINER& container)
109 { for (auto& item : container) transform(item); }
110
111 };
112
113
114 inline matrix multiplication(const matrix& m1, const matrix& m2)
115 {
116
117 matrix m;
118
119 m.a1 = m1.a1 * m2.a1 + m1.a2 * m2.b1 + m1.a3 * m2.c1;
120 m.a2 = m1.a1 * m2.a2 + m1.a2 * m2.b2 + m1.a3 * m2.c2;
121 m.a3 = m1.a1 * m2.a3 + m1.a2 * m2.b3 + m1.a3 * m2.c3;
122 m.b1 = m1.b1 * m2.a1 + m1.b2 * m2.b1 + m1.b3 * m2.c1;
123 m.b2 = m1.b1 * m2.a2 + m1.b2 * m2.b2 + m1.b3 * m2.c2;
124 m.b3 = m1.b1 * m2.a3 + m1.b2 * m2.b3 + m1.b3 * m2.c3;
125 m.c1 = m1.c1 * m2.a1 + m1.c2 * m2.b1 + m1.c3 * m2.c1;
126 m.c2 = m1.c1 * m2.a2 + m1.c2 * m2.b2 + m1.c3 * m2.c2;
127 m.c3 = m1.c1 * m2.a3 + m1.c2 * m2.b3 + m1.c3 * m2.c3;
128
129 return m;
130
131 }
132
133 inline matrix operator*(const matrix& m1, const matrix& m2)
134 {
135 return multiplication(m1, m2);
136 }
137
138
139} // namespace draw2d
140
141
142
Definition item copy.h:48
Definition matrix.h:14