1use core::ops::{Add, AddAssign, Sub, SubAssign, Neg, Mul, MulAssign, Div, DivAssign};
4use super::{quat, QuaternionWrapper, Vector3Wrapper, ScalarWrapper};
5use super::Float;
6
7
8impl<T: Float> Add for QuaternionWrapper<T> {
11 type Output = Self;
12 fn add(self, other: QuaternionWrapper<T>) -> Self {
13 Self( quat::add(self.0, other.0) )
14 }
15}
16
17impl<T: Float + Copy> AddAssign for QuaternionWrapper<T> {
19 fn add_assign(&mut self, other: QuaternionWrapper<T>) {
20 *self = Self( quat::add(self.0, other.0) );
21 }
22}
23
24impl<T: Float> Add<Vector3Wrapper<T>> for QuaternionWrapper<T> {
26 type Output = Self;
27 fn add(self, other: Vector3Wrapper<T>) -> Self {
28 Self(( (self.0).0, quat::add((self.0).1, other.0) ))
29 }
30}
31
32impl<T: Float> Add<ScalarWrapper<T>> for QuaternionWrapper<T> {
34 type Output = Self;
35 fn add(self, other: ScalarWrapper<T>) -> Self {
36 Self(( (self.0).0 + other.0, (self.0).1 ))
37 }
38}
39
40impl<T: Float> Sub for QuaternionWrapper<T> {
42 type Output = Self;
43 fn sub(self, other: QuaternionWrapper<T>) -> Self {
44 Self( quat::sub(self.0, other.0) )
45 }
46}
47
48impl<T: Float + Copy> SubAssign for QuaternionWrapper<T> {
50 fn sub_assign(&mut self, other: QuaternionWrapper<T>) {
51 *self = Self( quat::sub(self.0, other.0) );
52 }
53}
54
55impl<T: Float> Neg for QuaternionWrapper<T> {
57 type Output = Self;
58 fn neg(self) -> Self {
59 Self( quat::negate(self.0) )
60 }
61}
62
63impl<T: Float> Sub<Vector3Wrapper<T>> for QuaternionWrapper<T> {
65 type Output = Self;
66 fn sub(self, other: Vector3Wrapper<T>) -> Self {
67 Self(( (self.0).0, quat::sub((self.0).1, other.0) ))
68 }
69}
70
71impl<T: Float> Sub<ScalarWrapper<T>> for QuaternionWrapper<T> {
73 type Output = Self;
74 fn sub(self, other: ScalarWrapper<T>) -> Self {
75 Self(( (self.0).0 - other.0, (self.0).1 ))
76 }
77}
78
79impl<T: Float> Mul for QuaternionWrapper<T> {
81 type Output = Self;
82 fn mul(self, other: QuaternionWrapper<T>) -> Self {
83 Self( quat::mul(self.0, other.0) )
84 }
85}
86
87impl<T: Float> MulAssign for QuaternionWrapper<T> {
89 fn mul_assign(&mut self, other: QuaternionWrapper<T>) {
90 *self = Self( quat::mul(self.0, other.0) );
91 }
92}
93
94impl<T: Float> Mul<Vector3Wrapper<T>> for QuaternionWrapper<T> {
96 type Output = Self;
97 fn mul(self, other: Vector3Wrapper<T>) -> Self {
98 Self((
99 -quat::dot((self.0).1, other.0),
100 quat::scale_add((self.0).0, other.0, quat::cross((self.0).1, other.0))
101 ))
102 }
103}
104
105impl<T: Float> Mul<ScalarWrapper<T>> for QuaternionWrapper<T> {
107 type Output = Self;
108 fn mul(self, other: ScalarWrapper<T>) -> Self {
109 Self( quat::scale(other.0, self.0) )
110 }
111}
112
113impl<T: Float> Div<ScalarWrapper<T>> for QuaternionWrapper<T> {
115 type Output = Self;
116 fn div(self, other: ScalarWrapper<T>) -> Self {
117 Self( quat::scale(other.0.recip(), self.0) )
118 }
119}
120
121impl<T: Float> Add for Vector3Wrapper<T> {
124 type Output = Self;
125 fn add(self, other: Vector3Wrapper<T>) -> Self {
126 Self( quat::add(self.0, other.0) )
127 }
128}
129
130impl<T: Float> AddAssign for Vector3Wrapper<T> {
132 fn add_assign(&mut self, other: Vector3Wrapper<T>) {
133 *self = Self( quat::add(self.0, other.0) )
134 }
135}
136
137impl<T: Float> Add<QuaternionWrapper<T>> for Vector3Wrapper<T> {
139 type Output = QuaternionWrapper<T>;
140 fn add(self, other: QuaternionWrapper<T>) -> QuaternionWrapper<T> {
141 QuaternionWrapper(( (other.0).0, quat::add(self.0, (other.0).1) ))
142 }
143}
144
145impl<T: Float> Add<ScalarWrapper<T>> for Vector3Wrapper<T> {
147 type Output = QuaternionWrapper<T>;
148 fn add(self, other: ScalarWrapper<T>) -> QuaternionWrapper<T> {
149 QuaternionWrapper(( other.0, self.0 ))
150 }
151}
152
153impl<T: Float> Sub for Vector3Wrapper<T> {
155 type Output = Self;
156 fn sub(self, other: Vector3Wrapper<T>) -> Self {
157 Self( quat::sub(self.0, other.0) )
158 }
159}
160
161impl<T: Float> SubAssign for Vector3Wrapper<T> {
163 fn sub_assign(&mut self, other: Vector3Wrapper<T>) {
164 *self = Self( quat::sub(self.0, other.0) )
165 }
166}
167
168impl<T: Float> Neg for Vector3Wrapper<T> {
170 type Output = Self;
171 fn neg(self) -> Self {
172 Self( quat::negate(self.0) )
173 }
174}
175
176impl<T: Float> Sub<QuaternionWrapper<T>> for Vector3Wrapper<T> {
178 type Output = QuaternionWrapper<T>;
179 fn sub(self, other: QuaternionWrapper<T>) -> QuaternionWrapper<T> {
180 QuaternionWrapper(( -(other.0).0, quat::sub(self.0, (other.0).1) ))
181 }
182}
183
184impl<T: Float> Sub<ScalarWrapper<T>> for Vector3Wrapper<T> {
186 type Output = QuaternionWrapper<T>;
187 fn sub(self, other: ScalarWrapper<T>) -> QuaternionWrapper<T> {
188 QuaternionWrapper(( -other.0, self.0 ))
189 }
190}
191
192impl<T: Float> Mul for Vector3Wrapper<T> {
194 type Output = QuaternionWrapper<T>;
195 fn mul(self, other: Vector3Wrapper<T>) -> QuaternionWrapper<T> {
196 QuaternionWrapper( quat::mul(self.0, other.0) )
197 }
198}
199
200impl<T: Float> Mul<QuaternionWrapper<T>> for Vector3Wrapper<T> {
202 type Output = QuaternionWrapper<T>;
203 fn mul(self, other: QuaternionWrapper<T>) -> QuaternionWrapper<T> {
204 QuaternionWrapper((
205 -quat::dot(self.0, (other.0).1),
206 quat::scale_add( (other.0).0, self.0, quat::cross(self.0, (other.0).1) )
207 ))
208 }
209}
210
211impl<T: Float> Mul<ScalarWrapper<T>> for Vector3Wrapper<T> {
213 type Output = Self;
214 fn mul(self, other: ScalarWrapper<T>) -> Self {
215 Self( quat::scale(other.0, self.0) )
216 }
217}
218
219impl<T: Float> Div<ScalarWrapper<T>> for Vector3Wrapper<T> {
221 type Output = Self;
222 fn div(self, other: ScalarWrapper<T>) -> Self {
223 Self( quat::scale(other.0.recip(), self.0) )
224 }
225}
226
227impl<T: Float> Add for ScalarWrapper<T> {
230 type Output = Self;
231 fn add(self, other: ScalarWrapper<T>) -> Self {
232 Self(self.0 + other.0)
233 }
234}
235
236impl<T: Float> AddAssign for ScalarWrapper<T> {
238 fn add_assign(&mut self, other: ScalarWrapper<T>) {
239 *self = Self(self.0 + other.0)
240 }
241}
242
243impl<T: Float> Sub for ScalarWrapper<T> {
245 type Output = Self;
246 fn sub(self, other: ScalarWrapper<T>) -> Self {
247 Self(self.0 - other.0)
248 }
249}
250
251impl<T: Float> Neg for ScalarWrapper<T> {
253 type Output = Self;
254 fn neg(self) -> Self {
255 Self(-self.0)
256 }
257}
258
259impl<T: Float> SubAssign for ScalarWrapper<T> {
261 fn sub_assign(&mut self, other: ScalarWrapper<T>) {
262 *self = Self(self.0 - other.0)
263 }
264}
265
266impl<T: Float> Mul for ScalarWrapper<T> {
268 type Output = Self;
269 fn mul(self, other: ScalarWrapper<T>) -> Self {
270 Self(self.0 * other.0)
271 }
272}
273
274impl<T: Float> MulAssign for ScalarWrapper<T> {
276 fn mul_assign(&mut self, other: ScalarWrapper<T>) {
277 *self = Self(self.0 * other.0)
278 }
279}
280
281impl<T: Float> Div for ScalarWrapper<T> {
283 type Output = Self;
284 fn div(self, other: ScalarWrapper<T>) -> Self {
285 Self(self.0 / other.0)
286 }
287}
288
289impl<T: Float> DivAssign for ScalarWrapper<T> {
291 fn div_assign(&mut self, other: ScalarWrapper<T>) {
292 *self = Self(self.0 / other.0)
293 }
294}
295
296impl<T: Float> Add<QuaternionWrapper<T>> for ScalarWrapper<T> {
298 type Output = QuaternionWrapper<T>;
299 fn add(self, other: QuaternionWrapper<T>) -> QuaternionWrapper<T> {
300 QuaternionWrapper(( self.0 + (other.0).0, (other.0).1 ))
301 }
302}
303
304impl<T: Float> Sub<QuaternionWrapper<T>> for ScalarWrapper<T> {
306 type Output = QuaternionWrapper<T>;
307 fn sub(self, other: QuaternionWrapper<T>) -> QuaternionWrapper<T> {
308 QuaternionWrapper(( self.0 - (other.0).0, quat::negate((other.0).1) ))
309 }
310}
311
312impl<T: Float> Mul<QuaternionWrapper<T>> for ScalarWrapper<T> {
314 type Output = QuaternionWrapper<T>;
315 fn mul(self, other: QuaternionWrapper<T>) -> QuaternionWrapper<T> {
316 QuaternionWrapper( quat::scale(self.0, other.0) )
317 }
318}
319
320impl<T: Float> Add<Vector3Wrapper<T>> for ScalarWrapper<T> {
322 type Output = QuaternionWrapper<T>;
323 fn add(self, other: Vector3Wrapper<T>) -> QuaternionWrapper<T> {
324 QuaternionWrapper( (self.0, other.0) )
325 }
326}
327
328impl<T: Float> Sub<Vector3Wrapper<T>> for ScalarWrapper<T> {
330 type Output = QuaternionWrapper<T>;
331 fn sub(self, other: Vector3Wrapper<T>) -> QuaternionWrapper<T> {
332 QuaternionWrapper( (self.0, quat::negate(other.0)) )
333 }
334}
335
336impl<T: Float> Mul<Vector3Wrapper<T>> for ScalarWrapper<T> {
338 type Output = Vector3Wrapper<T>;
339 fn mul(self, other: Vector3Wrapper<T>) -> Vector3Wrapper<T> {
340 Vector3Wrapper( quat::scale(self.0, other.0) )
341 }
342}