Debian Codegraph @

debian/missing-sources/glam-0.28.0/src/f32/sse2/mat3a.rs

raw symbols SCIP
1 // Generated from mat.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{f32::math, swizzles::*, DMat3, EulerRot, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A};
4 #[cfg(not(target_arch = "spirv"))]
5 use core::fmt;
6 use core::iter::{Product, Sum};
7 use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
8
9 #[cfg(target_arch = "x86")]
10 use core::arch::x86::*;
11 #[cfg(target_arch = "x86_64")]
12 use core::arch::x86_64::*;
13
14 /// Creates a 3x3 matrix from three column vectors.
15 #[inline(always)]
16 #[must_use]
17 pub const fn mat3a(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Mat3A {
18 Mat3A::from_cols(x_axis, y_axis, z_axis)
19 }
20
21 /// A 3x3 column major matrix.
22 ///
23 /// This 3x3 matrix type features convenience methods for creating and using linear and
24 /// affine transformations. If you are primarily dealing with 2D affine transformations the
25 /// [`Affine2`](crate::Affine2) type is much faster and more space efficient than
26 /// using a 3x3 matrix.
27 ///
28 /// Linear transformations including 3D rotation and scale can be created using methods
29 /// such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`],
30 /// [`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or
31 /// [`Self::from_rotation_z()`].
32 ///
33 /// The resulting matrices can be use to transform 3D vectors using regular vector
34 /// multiplication.
35 ///
36 /// Affine transformations including 2D translation, rotation and scale can be created
37 /// using methods such as [`Self::from_translation()`], [`Self::from_angle()`],
38 /// [`Self::from_scale()`] and [`Self::from_scale_angle_translation()`].
39 ///
40 /// The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods
41 /// are provided for performing affine transforms on 2D vectors and points. These multiply
42 /// 2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for
43 /// vectors respectively. These methods assume that `Self` contains a valid affine
44 /// transform.
45 #[derive(Clone, Copy)]
46 #[repr(C)]
47 pub struct Mat3A {
48 pub x_axis: Vec3A,
49 pub y_axis: Vec3A,
50 pub z_axis: Vec3A,
51 }
52
53 impl Mat3A {
54 /// A 3x3 matrix with all elements set to `0.0`.
55 pub const ZERO: Self = Self::from_cols(Vec3A::ZERO, Vec3A::ZERO, Vec3A::ZERO);
56
57 /// A 3x3 identity matrix, where all diagonal elements are `1`, and all off-diagonal elements are `0`.
58 pub const IDENTITY: Self = Self::from_cols(Vec3A::X, Vec3A::Y, Vec3A::Z);
59
60 /// All NAN:s.
61 pub const NAN: Self = Self::from_cols(Vec3A::NAN, Vec3A::NAN, Vec3A::NAN);
62
63 #[allow(clippy::too_many_arguments)]
64 #[inline(always)]
65 #[must_use]
66 const fn new(
67 m00: f32,
68 m01: f32,
69 m02: f32,
70 m10: f32,
71 m11: f32,
72 m12: f32,
73 m20: f32,
74 m21: f32,
75 m22: f32,
76 ) -> Self {
77 Self {
78 x_axis: Vec3A::new(m00, m01, m02),
79 y_axis: Vec3A::new(m10, m11, m12),
80 z_axis: Vec3A::new(m20, m21, m22),
81 }
82 }
83
84 /// Creates a 3x3 matrix from three column vectors.
85 #[inline(always)]
86 #[must_use]
87 pub const fn from_cols(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Self {
88 Self {
89 x_axis,
90 y_axis,
91 z_axis,
92 }
93 }
94
95 /// Creates a 3x3 matrix from a `[f32; 9]` array stored in column major order.
96 /// If your data is stored in row major you will need to `transpose` the returned
97 /// matrix.
98 #[inline]
99 #[must_use]
100 pub const fn from_cols_array(m: &[f32; 9]) -> Self {
101 Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
102 }
103
104 /// Creates a `[f32; 9]` array storing data in column major order.
105 /// If you require data in row major order `transpose` the matrix first.
106 #[inline]
107 #[must_use]
108 pub const fn to_cols_array(&self) -> [f32; 9] {
109 let [x_axis_x, x_axis_y, x_axis_z] = self.x_axis.to_array();
110 let [y_axis_x, y_axis_y, y_axis_z] = self.y_axis.to_array();
111 let [z_axis_x, z_axis_y, z_axis_z] = self.z_axis.to_array();
112
113 [
114 x_axis_x, x_axis_y, x_axis_z, y_axis_x, y_axis_y, y_axis_z, z_axis_x, z_axis_y,
115 z_axis_z,
116 ]
117 }
118
119 /// Creates a 3x3 matrix from a `[[f32; 3]; 3]` 3D array stored in column major order.
120 /// If your data is in row major order you will need to `transpose` the returned
121 /// matrix.
122 #[inline]
123 #[must_use]
124 pub const fn from_cols_array_2d(m: &[[f32; 3]; 3]) -> Self {
125 Self::from_cols(
126 Vec3A::from_array(m[0]),
127 Vec3A::from_array(m[1]),
128 Vec3A::from_array(m[2]),
129 )
130 }
131
132 /// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order.
133 /// If you require data in row major order `transpose` the matrix first.
134 #[inline]
135 #[must_use]
136 pub const fn to_cols_array_2d(&self) -> [[f32; 3]; 3] {
137 [
138 self.x_axis.to_array(),
139 self.y_axis.to_array(),
140 self.z_axis.to_array(),
141 ]
142 }
143
144 /// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0.
145 #[doc(alias = "scale")]
146 #[inline]
147 #[must_use]
148 pub const fn from_diagonal(diagonal: Vec3) -> Self {
149 Self::new(
150 diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
151 )
152 }
153
154 /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column.
155 #[inline]
156 #[must_use]
157 pub fn from_mat4(m: Mat4) -> Self {
158 Self::from_cols(
159 Vec3A::from_vec4(m.x_axis),
160 Vec3A::from_vec4(m.y_axis),
161 Vec3A::from_vec4(m.z_axis),
162 )
163 }
164
165 /// Creates a 3D rotation matrix from the given quaternion.
166 ///
167 /// # Panics
168 ///
169 /// Will panic if `rotation` is not normalized when `glam_assert` is enabled.
170 #[inline]
171 #[must_use]
172 pub fn from_quat(rotation: Quat) -> Self {
173 glam_assert!(rotation.is_normalized());
174
175 let x2 = rotation.x + rotation.x;
176 let y2 = rotation.y + rotation.y;
177 let z2 = rotation.z + rotation.z;
178 let xx = rotation.x * x2;
179 let xy = rotation.x * y2;
180 let xz = rotation.x * z2;
181 let yy = rotation.y * y2;
182 let yz = rotation.y * z2;
183 let zz = rotation.z * z2;
184 let wx = rotation.w * x2;
185 let wy = rotation.w * y2;
186 let wz = rotation.w * z2;
187
188 Self::from_cols(
189 Vec3A::new(1.0 - (yy + zz), xy + wz, xz - wy),
190 Vec3A::new(xy - wz, 1.0 - (xx + zz), yz + wx),
191 Vec3A::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
192 )
193 }
194
195 /// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in
196 /// radians).
197 ///
198 /// # Panics
199 ///
200 /// Will panic if `axis` is not normalized when `glam_assert` is enabled.
201 #[inline]
202 #[must_use]
203 pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self {
204 glam_assert!(axis.is_normalized());
205
206 let (sin, cos) = math::sin_cos(angle);
207 let (xsin, ysin, zsin) = axis.mul(sin).into();
208 let (x, y, z) = axis.into();
209 let (x2, y2, z2) = axis.mul(axis).into();
210 let omc = 1.0 - cos;
211 let xyomc = x * y * omc;
212 let xzomc = x * z * omc;
213 let yzomc = y * z * omc;
214 Self::from_cols(
215 Vec3A::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
216 Vec3A::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
217 Vec3A::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
218 )
219 }
220
221 /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in
222 /// radians).
223 #[inline]
224 #[must_use]
225 pub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Self {
226 let quat = Quat::from_euler(order, a, b, c);
227 Self::from_quat(quat)
228 }
229
230 /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
231 #[inline]
232 #[must_use]
233 pub fn from_rotation_x(angle: f32) -> Self {
234 let (sina, cosa) = math::sin_cos(angle);
235 Self::from_cols(
236 Vec3A::X,
237 Vec3A::new(0.0, cosa, sina),
238 Vec3A::new(0.0, -sina, cosa),
239 )
240 }
241
242 /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis.
243 #[inline]
244 #[must_use]
245 pub fn from_rotation_y(angle: f32) -> Self {
246 let (sina, cosa) = math::sin_cos(angle);
247 Self::from_cols(
248 Vec3A::new(cosa, 0.0, -sina),
249 Vec3A::Y,
250 Vec3A::new(sina, 0.0, cosa),
251 )
252 }
253
254 /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis.
255 #[inline]
256 #[must_use]
257 pub fn from_rotation_z(angle: f32) -> Self {
258 let (sina, cosa) = math::sin_cos(angle);
259 Self::from_cols(
260 Vec3A::new(cosa, sina, 0.0),
261 Vec3A::new(-sina, cosa, 0.0),
262 Vec3A::Z,
263 )
264 }
265
266 /// Creates an affine transformation matrix from the given 2D `translation`.
267 ///
268 /// The resulting matrix can be used to transform 2D points and vectors. See
269 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
270 #[inline]
271 #[must_use]
272 pub fn from_translation(translation: Vec2) -> Self {
273 Self::from_cols(
274 Vec3A::X,
275 Vec3A::Y,
276 Vec3A::new(translation.x, translation.y, 1.0),
277 )
278 }
279
280 /// Creates an affine transformation matrix from the given 2D rotation `angle` (in
281 /// radians).
282 ///
283 /// The resulting matrix can be used to transform 2D points and vectors. See
284 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
285 #[inline]
286 #[must_use]
287 pub fn from_angle(angle: f32) -> Self {
288 let (sin, cos) = math::sin_cos(angle);
289 Self::from_cols(
290 Vec3A::new(cos, sin, 0.0),
291 Vec3A::new(-sin, cos, 0.0),
292 Vec3A::Z,
293 )
294 }
295
296 /// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in
297 /// radians) and `translation`.
298 ///
299 /// The resulting matrix can be used to transform 2D points and vectors. See
300 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
301 #[inline]
302 #[must_use]
303 pub fn from_scale_angle_translation(scale: Vec2, angle: f32, translation: Vec2) -> Self {
304 let (sin, cos) = math::sin_cos(angle);
305 Self::from_cols(
306 Vec3A::new(cos * scale.x, sin * scale.x, 0.0),
307 Vec3A::new(-sin * scale.y, cos * scale.y, 0.0),
308 Vec3A::new(translation.x, translation.y, 1.0),
309 )
310 }
311
312 /// Creates an affine transformation matrix from the given non-uniform 2D `scale`.
313 ///
314 /// The resulting matrix can be used to transform 2D points and vectors. See
315 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
316 ///
317 /// # Panics
318 ///
319 /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled.
320 #[inline]
321 #[must_use]
322 pub fn from_scale(scale: Vec2) -> Self {
323 // Do not panic as long as any component is non-zero
324 glam_assert!(scale.cmpne(Vec2::ZERO).any());
325
326 Self::from_cols(
327 Vec3A::new(scale.x, 0.0, 0.0),
328 Vec3A::new(0.0, scale.y, 0.0),
329 Vec3A::Z,
330 )
331 }
332
333 /// Creates an affine transformation matrix from the given 2x2 matrix.
334 ///
335 /// The resulting matrix can be used to transform 2D points and vectors. See
336 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
337 #[inline]
338 pub fn from_mat2(m: Mat2) -> Self {
339 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), Vec3A::Z)
340 }
341
342 /// Creates a 3x3 matrix from the first 9 values in `slice`.
343 ///
344 /// # Panics
345 ///
346 /// Panics if `slice` is less than 9 elements long.
347 #[inline]
348 #[must_use]
349 pub const fn from_cols_slice(slice: &[f32]) -> Self {
350 Self::new(
351 slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
352 slice[8],
353 )
354 }
355
356 /// Writes the columns of `self` to the first 9 elements in `slice`.
357 ///
358 /// # Panics
359 ///
360 /// Panics if `slice` is less than 9 elements long.
361 #[inline]
362 pub fn write_cols_to_slice(self, slice: &mut [f32]) {
363 slice[0] = self.x_axis.x;
364 slice[1] = self.x_axis.y;
365 slice[2] = self.x_axis.z;
366 slice[3] = self.y_axis.x;
367 slice[4] = self.y_axis.y;
368 slice[5] = self.y_axis.z;
369 slice[6] = self.z_axis.x;
370 slice[7] = self.z_axis.y;
371 slice[8] = self.z_axis.z;
372 }
373
374 /// Returns the matrix column for the given `index`.
375 ///
376 /// # Panics
377 ///
378 /// Panics if `index` is greater than 2.
379 #[inline]
380 #[must_use]
381 pub fn col(&self, index: usize) -> Vec3A {
382 match index {
383 0 => self.x_axis,
384 1 => self.y_axis,
385 2 => self.z_axis,
386 _ => panic!("index out of bounds"),
387 }
388 }
389
390 /// Returns a mutable reference to the matrix column for the given `index`.
391 ///
392 /// # Panics
393 ///
394 /// Panics if `index` is greater than 2.
395 #[inline]
396 pub fn col_mut(&mut self, index: usize) -> &mut Vec3A {
397 match index {
398 0 => &mut self.x_axis,
399 1 => &mut self.y_axis,
400 2 => &mut self.z_axis,
401 _ => panic!("index out of bounds"),
402 }
403 }
404
405 /// Returns the matrix row for the given `index`.
406 ///
407 /// # Panics
408 ///
409 /// Panics if `index` is greater than 2.
410 #[inline]
411 #[must_use]
412 pub fn row(&self, index: usize) -> Vec3A {
413 match index {
414 0 => Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
415 1 => Vec3A::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
416 2 => Vec3A::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
417 _ => panic!("index out of bounds"),
418 }
419 }
420
421 /// Returns `true` if, and only if, all elements are finite.
422 /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
423 #[inline]
424 #[must_use]
425 pub fn is_finite(&self) -> bool {
426 self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
427 }
428
429 /// Returns `true` if any elements are `NaN`.
430 #[inline]
431 #[must_use]
432 pub fn is_nan(&self) -> bool {
433 self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
434 }
435
436 /// Returns the transpose of `self`.
437 #[inline]
438 #[must_use]
439 pub fn transpose(&self) -> Self {
440 unsafe {
441 let tmp0 = _mm_shuffle_ps(self.x_axis.0, self.y_axis.0, 0b01_00_01_00);
442 let tmp1 = _mm_shuffle_ps(self.x_axis.0, self.y_axis.0, 0b11_10_11_10);
443
444 Self {
445 x_axis: Vec3A(_mm_shuffle_ps(tmp0, self.z_axis.0, 0b00_00_10_00)),
446 y_axis: Vec3A(_mm_shuffle_ps(tmp0, self.z_axis.0, 0b01_01_11_01)),
447 z_axis: Vec3A(_mm_shuffle_ps(tmp1, self.z_axis.0, 0b10_10_10_00)),
448 }
449 }
450 }
451
452 /// Returns the determinant of `self`.
453 #[inline]
454 #[must_use]
455 pub fn determinant(&self) -> f32 {
456 self.z_axis.dot(self.x_axis.cross(self.y_axis))
457 }
458
459 /// Returns the inverse of `self`.
460 ///
461 /// If the matrix is not invertible the returned matrix will be invalid.
462 ///
463 /// # Panics
464 ///
465 /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled.
466 #[inline]
467 #[must_use]
468 pub fn inverse(&self) -> Self {
469 let tmp0 = self.y_axis.cross(self.z_axis);
470 let tmp1 = self.z_axis.cross(self.x_axis);
471 let tmp2 = self.x_axis.cross(self.y_axis);
472 let det = self.z_axis.dot(tmp2);
473 glam_assert!(det != 0.0);
474 let inv_det = Vec3A::splat(det.recip());
475 Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose()
476 }
477
478 /// Transforms the given 2D vector as a point.
479 ///
480 /// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`.
481 ///
482 /// This method assumes that `self` contains a valid affine transform.
483 ///
484 /// # Panics
485 ///
486 /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled.
487 #[inline]
488 #[must_use]
489 pub fn transform_point2(&self, rhs: Vec2) -> Vec2 {
490 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
491 Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
492 }
493
494 /// Rotates the given 2D vector.
495 ///
496 /// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`.
497 ///
498 /// This method assumes that `self` contains a valid affine transform.
499 ///
500 /// # Panics
501 ///
502 /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled.
503 #[inline]
504 #[must_use]
505 pub fn transform_vector2(&self, rhs: Vec2) -> Vec2 {
506 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
507 Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
508 }
509
510 /// Transforms a 3D vector.
511 #[inline]
512 #[must_use]
513 pub fn mul_vec3(&self, rhs: Vec3) -> Vec3 {
514 self.mul_vec3a(rhs.into()).into()
515 }
516
517 /// Transforms a [`Vec3A`].
518 #[inline]
519 #[must_use]
520 pub fn mul_vec3a(&self, rhs: Vec3A) -> Vec3A {
521 let mut res = self.x_axis.mul(rhs.xxx());
522 res = res.add(self.y_axis.mul(rhs.yyy()));
523 res = res.add(self.z_axis.mul(rhs.zzz()));
524 res
525 }
526
527 /// Multiplies two 3x3 matrices.
528 #[inline]
529 #[must_use]
530 pub fn mul_mat3(&self, rhs: &Self) -> Self {
531 Self::from_cols(
532 self.mul(rhs.x_axis),
533 self.mul(rhs.y_axis),
534 self.mul(rhs.z_axis),
535 )
536 }
537
538 /// Adds two 3x3 matrices.
539 #[inline]
540 #[must_use]
541 pub fn add_mat3(&self, rhs: &Self) -> Self {
542 Self::from_cols(
543 self.x_axis.add(rhs.x_axis),
544 self.y_axis.add(rhs.y_axis),
545 self.z_axis.add(rhs.z_axis),
546 )
547 }
548
549 /// Subtracts two 3x3 matrices.
550 #[inline]
551 #[must_use]
552 pub fn sub_mat3(&self, rhs: &Self) -> Self {
553 Self::from_cols(
554 self.x_axis.sub(rhs.x_axis),
555 self.y_axis.sub(rhs.y_axis),
556 self.z_axis.sub(rhs.z_axis),
557 )
558 }
559
560 /// Multiplies a 3x3 matrix by a scalar.
561 #[inline]
562 #[must_use]
563 pub fn mul_scalar(&self, rhs: f32) -> Self {
564 Self::from_cols(
565 self.x_axis.mul(rhs),
566 self.y_axis.mul(rhs),
567 self.z_axis.mul(rhs),
568 )
569 }
570
571 /// Divides a 3x3 matrix by a scalar.
572 #[inline]
573 #[must_use]
574 pub fn div_scalar(&self, rhs: f32) -> Self {
575 let rhs = Vec3A::splat(rhs);
576 Self::from_cols(
577 self.x_axis.div(rhs),
578 self.y_axis.div(rhs),
579 self.z_axis.div(rhs),
580 )
581 }
582
583 /// Returns true if the absolute difference of all elements between `self` and `rhs`
584 /// is less than or equal to `max_abs_diff`.
585 ///
586 /// This can be used to compare if two matrices contain similar elements. It works best
587 /// when comparing with a known value. The `max_abs_diff` that should be used used
588 /// depends on the values being compared against.
589 ///
590 /// For more see
591 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
592 #[inline]
593 #[must_use]
594 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
595 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
596 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
597 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
598 }
599
600 /// Takes the absolute value of each element in `self`
601 #[inline]
602 #[must_use]
603 pub fn abs(&self) -> Self {
604 Self::from_cols(self.x_axis.abs(), self.y_axis.abs(), self.z_axis.abs())
605 }
606
607 #[inline]
608 pub fn as_dmat3(&self) -> DMat3 {
609 DMat3::from_cols(
610 self.x_axis.as_dvec3(),
611 self.y_axis.as_dvec3(),
612 self.z_axis.as_dvec3(),
613 )
614 }
615 }
616
617 impl Default for Mat3A {
618 #[inline]
619 fn default() -> Self {
620 Self::IDENTITY
621 }
622 }
623
624 impl Add<Mat3A> for Mat3A {
625 type Output = Self;
626 #[inline]
627 fn add(self, rhs: Self) -> Self::Output {
628 self.add_mat3(&rhs)
629 }
630 }
631
632 impl AddAssign<Mat3A> for Mat3A {
633 #[inline]
634 fn add_assign(&mut self, rhs: Self) {
635 *self = self.add_mat3(&rhs);
636 }
637 }
638
639 impl Sub<Mat3A> for Mat3A {
640 type Output = Self;
641 #[inline]
642 fn sub(self, rhs: Self) -> Self::Output {
643 self.sub_mat3(&rhs)
644 }
645 }
646
647 impl SubAssign<Mat3A> for Mat3A {
648 #[inline]
649 fn sub_assign(&mut self, rhs: Self) {
650 *self = self.sub_mat3(&rhs);
651 }
652 }
653
654 impl Neg for Mat3A {
655 type Output = Self;
656 #[inline]
657 fn neg(self) -> Self::Output {
658 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
659 }
660 }
661
662 impl Mul<Mat3A> for Mat3A {
663 type Output = Self;
664 #[inline]
665 fn mul(self, rhs: Self) -> Self::Output {
666 self.mul_mat3(&rhs)
667 }
668 }
669
670 impl MulAssign<Mat3A> for Mat3A {
671 #[inline]
672 fn mul_assign(&mut self, rhs: Self) {
673 *self = self.mul_mat3(&rhs);
674 }
675 }
676
677 impl Mul<Vec3A> for Mat3A {
678 type Output = Vec3A;
679 #[inline]
680 fn mul(self, rhs: Vec3A) -> Self::Output {
681 self.mul_vec3a(rhs)
682 }
683 }
684
685 impl Mul<Mat3A> for f32 {
686 type Output = Mat3A;
687 #[inline]
688 fn mul(self, rhs: Mat3A) -> Self::Output {
689 rhs.mul_scalar(self)
690 }
691 }
692
693 impl Mul<f32> for Mat3A {
694 type Output = Self;
695 #[inline]
696 fn mul(self, rhs: f32) -> Self::Output {
697 self.mul_scalar(rhs)
698 }
699 }
700
701 impl MulAssign<f32> for Mat3A {
702 #[inline]
703 fn mul_assign(&mut self, rhs: f32) {
704 *self = self.mul_scalar(rhs);
705 }
706 }
707
708 impl Div<Mat3A> for f32 {
709 type Output = Mat3A;
710 #[inline]
711 fn div(self, rhs: Mat3A) -> Self::Output {
712 rhs.div_scalar(self)
713 }
714 }
715
716 impl Div<f32> for Mat3A {
717 type Output = Self;
718 #[inline]
719 fn div(self, rhs: f32) -> Self::Output {
720 self.div_scalar(rhs)
721 }
722 }
723
724 impl DivAssign<f32> for Mat3A {
725 #[inline]
726 fn div_assign(&mut self, rhs: f32) {
727 *self = self.div_scalar(rhs);
728 }
729 }
730
731 impl Mul<Vec3> for Mat3A {
732 type Output = Vec3;
733 #[inline]
734 fn mul(self, rhs: Vec3) -> Vec3 {
735 self.mul_vec3a(rhs.into()).into()
736 }
737 }
738
739 impl From<Mat3> for Mat3A {
740 #[inline]
741 fn from(m: Mat3) -> Self {
742 Self {
743 x_axis: m.x_axis.into(),
744 y_axis: m.y_axis.into(),
745 z_axis: m.z_axis.into(),
746 }
747 }
748 }
749
750 impl Sum<Self> for Mat3A {
751 fn sum<I>(iter: I) -> Self
752 where
753 I: Iterator<Item = Self>,
754 {
755 iter.fold(Self::ZERO, Self::add)
756 }
757 }
758
759 impl<'a> Sum<&'a Self> for Mat3A {
760 fn sum<I>(iter: I) -> Self
761 where
762 I: Iterator<Item = &'a Self>,
763 {
764 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
765 }
766 }
767
768 impl Product for Mat3A {
769 fn product<I>(iter: I) -> Self
770 where
771 I: Iterator<Item = Self>,
772 {
773 iter.fold(Self::IDENTITY, Self::mul)
774 }
775 }
776
777 impl<'a> Product<&'a Self> for Mat3A {
778 fn product<I>(iter: I) -> Self
779 where
780 I: Iterator<Item = &'a Self>,
781 {
782 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
783 }
784 }
785
786 impl PartialEq for Mat3A {
787 #[inline]
788 fn eq(&self, rhs: &Self) -> bool {
789 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
790 }
791 }
792
793 #[cfg(not(target_arch = "spirv"))]
794 impl fmt::Debug for Mat3A {
795 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
796 fmt.debug_struct(stringify!(Mat3A))
797 .field("x_axis", &self.x_axis)
798 .field("y_axis", &self.y_axis)
799 .field("z_axis", &self.z_axis)
800 .finish()
801 }
802 }
803
804 #[cfg(not(target_arch = "spirv"))]
805 impl fmt::Display for Mat3A {
806 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
807 if let Some(p) = f.precision() {
808 write!(
809 f,
810 "[{:.*}, {:.*}, {:.*}]",
811 p, self.x_axis, p, self.y_axis, p, self.z_axis
812 )
813 } else {
814 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
815 }
816 }
817 }