windows_numerics/
matrix3x2.rs1use super::*;
2
3impl Matrix3x2 {
4 pub const fn identity() -> Self {
5 Self {
6 M11: 1.0,
7 M12: 0.0,
8 M21: 0.0,
9 M22: 1.0,
10 M31: 0.0,
11 M32: 0.0,
12 }
13 }
14 pub const fn translation(x: f32, y: f32) -> Self {
15 Self {
16 M11: 1.0,
17 M12: 0.0,
18 M21: 0.0,
19 M22: 1.0,
20 M31: x,
21 M32: y,
22 }
23 }
24 pub fn rotation(angle: f32, x: f32, y: f32) -> Self {
25 #[repr(C)]
26 pub struct D2D_POINT_2F {
27 pub x: f32,
28 pub y: f32,
29 }
30 windows_link::link!("d2d1.dll" "system" fn D2D1MakeRotateMatrix(angle: f32, center: D2D_POINT_2F, matrix: *mut Matrix3x2));
31 let mut matrix = Self::default();
32 unsafe {
33 D2D1MakeRotateMatrix(angle, D2D_POINT_2F { x, y }, &mut matrix);
34 }
35 matrix
36 }
37 fn impl_add(&self, rhs: &Self) -> Self {
38 Self {
39 M11: self.M11 + rhs.M11,
40 M12: self.M12 + rhs.M12,
41 M21: self.M21 + rhs.M21,
42 M22: self.M22 + rhs.M22,
43 M31: self.M31 + rhs.M31,
44 M32: self.M32 + rhs.M32,
45 }
46 }
47 fn impl_sub(&self, rhs: &Self) -> Self {
48 Self {
49 M11: self.M11 - rhs.M11,
50 M12: self.M12 - rhs.M12,
51 M21: self.M21 - rhs.M21,
52 M22: self.M22 - rhs.M22,
53 M31: self.M31 - rhs.M31,
54 M32: self.M32 - rhs.M32,
55 }
56 }
57 fn impl_mul(&self, rhs: &Self) -> Self {
58 Self {
59 M11: self.M11 * rhs.M11 + self.M12 * rhs.M21,
60 M12: self.M11 * rhs.M12 + self.M12 * rhs.M22,
61 M21: self.M21 * rhs.M11 + self.M22 * rhs.M21,
62 M22: self.M21 * rhs.M12 + self.M22 * rhs.M22,
63 M31: self.M31 * rhs.M11 + self.M32 * rhs.M21 + rhs.M31,
64 M32: self.M31 * rhs.M12 + self.M32 * rhs.M22 + rhs.M32,
65 }
66 }
67 fn impl_mul_f32(&self, rhs: f32) -> Self {
68 Self {
69 M11: self.M11 * rhs,
70 M12: self.M12 * rhs,
71 M21: self.M21 * rhs,
72 M22: self.M22 * rhs,
73 M31: self.M31 * rhs,
74 M32: self.M32 * rhs,
75 }
76 }
77}
78
79impl core::ops::Add<Matrix3x2> for Matrix3x2 {
80 type Output = Matrix3x2;
81 fn add(self, rhs: Matrix3x2) -> Matrix3x2 {
82 self.impl_add(&rhs)
83 }
84}
85impl core::ops::Add<&Matrix3x2> for Matrix3x2 {
86 type Output = Matrix3x2;
87 fn add(self, rhs: &Matrix3x2) -> Matrix3x2 {
88 self.impl_add(rhs)
89 }
90}
91impl core::ops::Add<Matrix3x2> for &Matrix3x2 {
92 type Output = Matrix3x2;
93 fn add(self, rhs: Matrix3x2) -> Matrix3x2 {
94 self.impl_add(&rhs)
95 }
96}
97impl core::ops::Add<&Matrix3x2> for &Matrix3x2 {
98 type Output = Matrix3x2;
99 fn add(self, rhs: &Matrix3x2) -> Matrix3x2 {
100 self.impl_add(rhs)
101 }
102}
103impl core::ops::Sub<Matrix3x2> for Matrix3x2 {
104 type Output = Matrix3x2;
105 fn sub(self, rhs: Matrix3x2) -> Matrix3x2 {
106 self.impl_sub(&rhs)
107 }
108}
109impl core::ops::Sub<&Matrix3x2> for Matrix3x2 {
110 type Output = Matrix3x2;
111 fn sub(self, rhs: &Matrix3x2) -> Matrix3x2 {
112 self.impl_sub(rhs)
113 }
114}
115impl core::ops::Sub<Matrix3x2> for &Matrix3x2 {
116 type Output = Matrix3x2;
117 fn sub(self, rhs: Matrix3x2) -> Matrix3x2 {
118 self.impl_sub(&rhs)
119 }
120}
121impl core::ops::Sub<&Matrix3x2> for &Matrix3x2 {
122 type Output = Matrix3x2;
123 fn sub(self, rhs: &Matrix3x2) -> Matrix3x2 {
124 self.impl_sub(rhs)
125 }
126}
127impl core::ops::Mul<Matrix3x2> for Matrix3x2 {
128 type Output = Matrix3x2;
129 fn mul(self, rhs: Matrix3x2) -> Matrix3x2 {
130 self.impl_mul(&rhs)
131 }
132}
133impl core::ops::Mul<&Matrix3x2> for Matrix3x2 {
134 type Output = Matrix3x2;
135 fn mul(self, rhs: &Matrix3x2) -> Matrix3x2 {
136 self.impl_mul(rhs)
137 }
138}
139impl core::ops::Mul<Matrix3x2> for &Matrix3x2 {
140 type Output = Matrix3x2;
141 fn mul(self, rhs: Matrix3x2) -> Matrix3x2 {
142 self.impl_mul(&rhs)
143 }
144}
145impl core::ops::Mul<&Matrix3x2> for &Matrix3x2 {
146 type Output = Matrix3x2;
147 fn mul(self, rhs: &Matrix3x2) -> Matrix3x2 {
148 self.impl_mul(rhs)
149 }
150}
151impl core::ops::Mul<f32> for Matrix3x2 {
152 type Output = Matrix3x2;
153 fn mul(self, rhs: f32) -> Matrix3x2 {
154 self.impl_mul_f32(rhs)
155 }
156}
157impl core::ops::Mul<f32> for &Matrix3x2 {
158 type Output = Matrix3x2;
159 fn mul(self, rhs: f32) -> Matrix3x2 {
160 self.impl_mul_f32(rhs)
161 }
162}