Debian Codegraph @

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

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