Skip to main content

glam/f32/neon/
mat3a.rs

1// Generated from mat.rs.tera template. Edit the template, not the generated file.
2
3#[cfg(feature = "f64")]
4use crate::DMat3;
5
6use crate::{
7    EulerRot, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A,
8    euler::{FromEuler, ToEuler},
9    f32::math,
10    swizzles::*,
11};
12use core::fmt;
13use core::iter::{Product, Sum};
14use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
15
16use core::arch::aarch64::*;
17
18#[cfg(feature = "zerocopy-08")]
19use zerocopy_derive_08::*;
20
21/// Creates a 3x3 matrix from three column vectors.
22#[inline(always)]
23#[must_use]
24pub const fn mat3a(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Mat3A {
25    Mat3A::from_cols(x_axis, y_axis, z_axis)
26}
27
28/// A 3x3 column major matrix.
29///
30/// This 3x3 matrix type features convenience methods for creating and using linear and
31/// affine transformations. If you are primarily dealing with 2D affine transformations the
32/// [`Affine2`](crate::Affine2) type is much faster and more space efficient than
33/// using a 3x3 matrix.
34///
35/// Linear transformations including 3D rotation and scale can be created using methods
36/// such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`],
37/// [`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or
38/// [`Self::from_rotation_z()`].
39///
40/// The resulting matrices can be use to transform 3D vectors using regular vector
41/// multiplication.
42///
43/// Affine transformations including 2D translation, rotation and scale can be created
44/// using methods such as [`Self::from_translation()`], [`Self::from_angle()`],
45/// [`Self::from_scale()`] and [`Self::from_scale_angle_translation()`].
46///
47/// The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods
48/// are provided for performing affine transforms on 2D vectors and points. These multiply
49/// 2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for
50/// vectors respectively. These methods assume that `Self` contains a valid affine
51/// transform.
52///
53/// SIMD vector types are used for storage on supported platforms.
54///
55/// This type is 16 byte aligned.
56#[derive(Clone, Copy)]
57#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
58#[cfg_attr(
59    feature = "zerocopy-08",
60    derive(FromBytes, Immutable, IntoBytes, KnownLayout)
61)]
62#[repr(C)]
63pub struct Mat3A {
64    pub x_axis: Vec3A,
65    pub y_axis: Vec3A,
66    pub z_axis: Vec3A,
67}
68
69impl Mat3A {
70    /// A 3x3 matrix with all elements set to `0.0`.
71    pub const ZERO: Self = Self::from_cols(Vec3A::ZERO, Vec3A::ZERO, Vec3A::ZERO);
72
73    /// A 3x3 identity matrix, where all diagonal elements are `1`, and all off-diagonal elements are `0`.
74    pub const IDENTITY: Self = Self::from_cols(Vec3A::X, Vec3A::Y, Vec3A::Z);
75
76    /// All NAN:s.
77    pub const NAN: Self = Self::from_cols(Vec3A::NAN, Vec3A::NAN, Vec3A::NAN);
78
79    #[allow(clippy::too_many_arguments)]
80    #[inline(always)]
81    #[must_use]
82    const fn new(
83        m00: f32,
84        m01: f32,
85        m02: f32,
86        m10: f32,
87        m11: f32,
88        m12: f32,
89        m20: f32,
90        m21: f32,
91        m22: f32,
92    ) -> Self {
93        Self {
94            x_axis: Vec3A::new(m00, m01, m02),
95            y_axis: Vec3A::new(m10, m11, m12),
96            z_axis: Vec3A::new(m20, m21, m22),
97        }
98    }
99
100    /// Creates a 3x3 matrix from three column vectors.
101    ///
102    /// See also [`Self::from_rows`] when the data is in row major order.
103    #[inline(always)]
104    #[must_use]
105    pub const fn from_cols(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Self {
106        Self {
107            x_axis,
108            y_axis,
109            z_axis,
110        }
111    }
112
113    /// Creates a 3x3 matrix from three row vectors.
114    ///
115    /// Matrices are stored in column major order, so the given rows are permuted into
116    /// the matrix layout. Use [`Self::from_cols`] instead when the data is already in
117    /// column major order.
118    #[inline(always)]
119    #[must_use]
120    pub const fn from_rows(row0: Vec3A, row1: Vec3A, row2: Vec3A) -> Self {
121        let [m00, m01, m02] = row0.to_array();
122        let [m10, m11, m12] = row1.to_array();
123        let [m20, m21, m22] = row2.to_array();
124        Self::new(m00, m10, m20, m01, m11, m21, m02, m12, m22)
125    }
126
127    /// Creates a 3x3 matrix from a `[f32; 9]` array stored in column major order.
128    ///
129    /// If the data is in row major order use [`Self::from_rows_array`] instead.
130    #[inline]
131    #[must_use]
132    pub const fn from_cols_array(m: &[f32; 9]) -> Self {
133        Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
134    }
135
136    /// Creates a `[f32; 9]` array storing data in column major order.
137    ///
138    /// If you require the data in row major order use [`Self::to_rows_array`] instead.
139    #[inline]
140    #[must_use]
141    pub const fn to_cols_array(&self) -> [f32; 9] {
142        let [x_axis_x, x_axis_y, x_axis_z] = self.x_axis.to_array();
143        let [y_axis_x, y_axis_y, y_axis_z] = self.y_axis.to_array();
144        let [z_axis_x, z_axis_y, z_axis_z] = self.z_axis.to_array();
145
146        [
147            x_axis_x, x_axis_y, x_axis_z, y_axis_x, y_axis_y, y_axis_z, z_axis_x, z_axis_y,
148            z_axis_z,
149        ]
150    }
151
152    /// Creates a 3x3 matrix from a `[[f32; 3]; 3]` 3D array stored in column major order.
153    ///
154    /// If the data is in row major order `transpose` the returned matrix.
155    #[inline]
156    #[must_use]
157    pub const fn from_cols_array_2d(m: &[[f32; 3]; 3]) -> Self {
158        Self::from_cols(
159            Vec3A::from_array(m[0]),
160            Vec3A::from_array(m[1]),
161            Vec3A::from_array(m[2]),
162        )
163    }
164
165    /// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order.
166    ///
167    /// If you require row major order `transpose` the matrix first.
168    #[inline]
169    #[must_use]
170    pub const fn to_cols_array_2d(&self) -> [[f32; 3]; 3] {
171        [
172            self.x_axis.to_array(),
173            self.y_axis.to_array(),
174            self.z_axis.to_array(),
175        ]
176    }
177
178    /// Creates a 3x3 matrix from a `[f32; 9]` array stored in row major order.
179    ///
180    /// Matrices are stored in column major order, so the array is permuted into the
181    /// matrix layout. Use [`Self::from_cols_array`] instead when the data is already in
182    /// column major order.
183    #[inline]
184    #[must_use]
185    pub const fn from_rows_array(m: &[f32; 9]) -> Self {
186        Self::new(m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8])
187    }
188
189    /// Creates a `[f32; 9]` array storing data in row major order.
190    ///
191    /// Matrices are stored in column major order, so the array is permuted out of the
192    /// column major storage. Use [`Self::to_cols_array`] instead when you want data in
193    /// column major order.
194    #[inline]
195    #[must_use]
196    pub const fn to_rows_array(&self) -> [f32; 9] {
197        let m = self.to_cols_array();
198        [m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8]]
199    }
200
201    /// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0.
202    #[doc(alias = "scale")]
203    #[inline]
204    #[must_use]
205    pub const fn from_diagonal(diagonal: Vec3) -> Self {
206        Self::new(
207            diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
208        )
209    }
210
211    /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column.
212    #[inline]
213    #[must_use]
214    pub fn from_mat4(m: Mat4) -> Self {
215        Self::from_cols(
216            Vec3A::from_vec4(m.x_axis),
217            Vec3A::from_vec4(m.y_axis),
218            Vec3A::from_vec4(m.z_axis),
219        )
220    }
221
222    /// Creates a 3x3 matrix from the minor of the given 4x4 matrix, discarding the `i`th column
223    /// and `j`th row.
224    ///
225    /// # Panics
226    ///
227    /// Panics if `i` or `j` is greater than 3.
228    #[inline]
229    #[must_use]
230    #[track_caller]
231    pub fn from_mat4_minor(m: Mat4, i: usize, j: usize) -> Self {
232        match (i, j) {
233            (0, 0) => Self::from_cols(
234                Vec3A::from_vec4(m.y_axis.yzww()),
235                Vec3A::from_vec4(m.z_axis.yzww()),
236                Vec3A::from_vec4(m.w_axis.yzww()),
237            ),
238            (0, 1) => Self::from_cols(
239                Vec3A::from_vec4(m.y_axis.xzww()),
240                Vec3A::from_vec4(m.z_axis.xzww()),
241                Vec3A::from_vec4(m.w_axis.xzww()),
242            ),
243            (0, 2) => Self::from_cols(
244                Vec3A::from_vec4(m.y_axis.xyww()),
245                Vec3A::from_vec4(m.z_axis.xyww()),
246                Vec3A::from_vec4(m.w_axis.xyww()),
247            ),
248            (0, 3) => Self::from_cols(
249                Vec3A::from_vec4(m.y_axis.xyzw()),
250                Vec3A::from_vec4(m.z_axis.xyzw()),
251                Vec3A::from_vec4(m.w_axis.xyzw()),
252            ),
253            (1, 0) => Self::from_cols(
254                Vec3A::from_vec4(m.x_axis.yzww()),
255                Vec3A::from_vec4(m.z_axis.yzww()),
256                Vec3A::from_vec4(m.w_axis.yzww()),
257            ),
258            (1, 1) => Self::from_cols(
259                Vec3A::from_vec4(m.x_axis.xzww()),
260                Vec3A::from_vec4(m.z_axis.xzww()),
261                Vec3A::from_vec4(m.w_axis.xzww()),
262            ),
263            (1, 2) => Self::from_cols(
264                Vec3A::from_vec4(m.x_axis.xyww()),
265                Vec3A::from_vec4(m.z_axis.xyww()),
266                Vec3A::from_vec4(m.w_axis.xyww()),
267            ),
268            (1, 3) => Self::from_cols(
269                Vec3A::from_vec4(m.x_axis.xyzw()),
270                Vec3A::from_vec4(m.z_axis.xyzw()),
271                Vec3A::from_vec4(m.w_axis.xyzw()),
272            ),
273            (2, 0) => Self::from_cols(
274                Vec3A::from_vec4(m.x_axis.yzww()),
275                Vec3A::from_vec4(m.y_axis.yzww()),
276                Vec3A::from_vec4(m.w_axis.yzww()),
277            ),
278            (2, 1) => Self::from_cols(
279                Vec3A::from_vec4(m.x_axis.xzww()),
280                Vec3A::from_vec4(m.y_axis.xzww()),
281                Vec3A::from_vec4(m.w_axis.xzww()),
282            ),
283            (2, 2) => Self::from_cols(
284                Vec3A::from_vec4(m.x_axis.xyww()),
285                Vec3A::from_vec4(m.y_axis.xyww()),
286                Vec3A::from_vec4(m.w_axis.xyww()),
287            ),
288            (2, 3) => Self::from_cols(
289                Vec3A::from_vec4(m.x_axis.xyzw()),
290                Vec3A::from_vec4(m.y_axis.xyzw()),
291                Vec3A::from_vec4(m.w_axis.xyzw()),
292            ),
293            (3, 0) => Self::from_cols(
294                Vec3A::from_vec4(m.x_axis.yzww()),
295                Vec3A::from_vec4(m.y_axis.yzww()),
296                Vec3A::from_vec4(m.z_axis.yzww()),
297            ),
298            (3, 1) => Self::from_cols(
299                Vec3A::from_vec4(m.x_axis.xzww()),
300                Vec3A::from_vec4(m.y_axis.xzww()),
301                Vec3A::from_vec4(m.z_axis.xzww()),
302            ),
303            (3, 2) => Self::from_cols(
304                Vec3A::from_vec4(m.x_axis.xyww()),
305                Vec3A::from_vec4(m.y_axis.xyww()),
306                Vec3A::from_vec4(m.z_axis.xyww()),
307            ),
308            (3, 3) => Self::from_cols(
309                Vec3A::from_vec4(m.x_axis.xyzw()),
310                Vec3A::from_vec4(m.y_axis.xyzw()),
311                Vec3A::from_vec4(m.z_axis.xyzw()),
312            ),
313            _ => panic!("index out of bounds"),
314        }
315    }
316
317    /// Creates a 3D rotation matrix from the given quaternion.
318    ///
319    /// # Panics
320    ///
321    /// Will panic if `rotation` is not normalized when `glam_assert` is enabled.
322    #[inline]
323    #[must_use]
324    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
325    pub fn from_quat(rotation: Quat) -> Self {
326        glam_assert!(rotation.is_normalized());
327
328        let x2 = rotation.x + rotation.x;
329        let y2 = rotation.y + rotation.y;
330        let z2 = rotation.z + rotation.z;
331        let xx = rotation.x * x2;
332        let xy = rotation.x * y2;
333        let xz = rotation.x * z2;
334        let yy = rotation.y * y2;
335        let yz = rotation.y * z2;
336        let zz = rotation.z * z2;
337        let wx = rotation.w * x2;
338        let wy = rotation.w * y2;
339        let wz = rotation.w * z2;
340
341        Self::from_cols(
342            Vec3A::new(1.0 - (yy + zz), xy + wz, xz - wy),
343            Vec3A::new(xy - wz, 1.0 - (xx + zz), yz + wx),
344            Vec3A::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
345        )
346    }
347
348    /// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in
349    /// radians).
350    ///
351    /// # Panics
352    ///
353    /// Will panic if `axis` is not normalized when `glam_assert` is enabled.
354    #[inline]
355    #[must_use]
356    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
357    pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self {
358        glam_assert!(axis.is_normalized());
359
360        let (sin, cos) = math::sin_cos(angle);
361        let (xsin, ysin, zsin) = axis.mul(sin).into();
362        let (x, y, z) = axis.into();
363        let (x2, y2, z2) = axis.mul(axis).into();
364        let omc = 1.0 - cos;
365        let xyomc = x * y * omc;
366        let xzomc = x * z * omc;
367        let yzomc = y * z * omc;
368        Self::from_cols(
369            Vec3A::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
370            Vec3A::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
371            Vec3A::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
372        )
373    }
374
375    /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in
376    /// radians).
377    #[inline]
378    #[must_use]
379    pub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Self {
380        Self::from_euler_angles(order, a, b, c)
381    }
382
383    /// Extract Euler angles with the given Euler rotation order.
384    ///
385    /// Note if the input matrix contains scales, shears, or other non-rotation transformations then
386    /// the resulting Euler angles will be ill-defined.
387    ///
388    /// # Panics
389    ///
390    /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled.
391    #[inline]
392    #[must_use]
393    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
394    pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
395        glam_assert!(
396            self.x_axis.is_normalized()
397                && self.y_axis.is_normalized()
398                && self.z_axis.is_normalized()
399        );
400        self.to_euler_angles(order)
401    }
402
403    /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
404    #[inline]
405    #[must_use]
406    pub fn from_rotation_x(angle: f32) -> Self {
407        let (sina, cosa) = math::sin_cos(angle);
408        Self::from_cols(
409            Vec3A::X,
410            Vec3A::new(0.0, cosa, sina),
411            Vec3A::new(0.0, -sina, cosa),
412        )
413    }
414
415    /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis.
416    #[inline]
417    #[must_use]
418    pub fn from_rotation_y(angle: f32) -> Self {
419        let (sina, cosa) = math::sin_cos(angle);
420        Self::from_cols(
421            Vec3A::new(cosa, 0.0, -sina),
422            Vec3A::Y,
423            Vec3A::new(sina, 0.0, cosa),
424        )
425    }
426
427    /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis.
428    #[inline]
429    #[must_use]
430    pub fn from_rotation_z(angle: f32) -> Self {
431        let (sina, cosa) = math::sin_cos(angle);
432        Self::from_cols(
433            Vec3A::new(cosa, sina, 0.0),
434            Vec3A::new(-sina, cosa, 0.0),
435            Vec3A::Z,
436        )
437    }
438
439    /// Creates an affine transformation matrix from the given 2D `translation`.
440    ///
441    /// The resulting matrix can be used to transform 2D points and vectors. See
442    /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
443    #[inline]
444    #[must_use]
445    pub fn from_translation(translation: Vec2) -> Self {
446        Self::from_cols(
447            Vec3A::X,
448            Vec3A::Y,
449            Vec3A::new(translation.x, translation.y, 1.0),
450        )
451    }
452
453    /// Creates an affine transformation matrix from the given 2D rotation `angle` (in
454    /// radians).
455    ///
456    /// The resulting matrix can be used to transform 2D points and vectors. See
457    /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
458    #[inline]
459    #[must_use]
460    pub fn from_angle(angle: f32) -> Self {
461        let (sin, cos) = math::sin_cos(angle);
462        Self::from_cols(
463            Vec3A::new(cos, sin, 0.0),
464            Vec3A::new(-sin, cos, 0.0),
465            Vec3A::Z,
466        )
467    }
468
469    /// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in
470    /// radians) and `translation`.
471    ///
472    /// The resulting matrix can be used to transform 2D points and vectors. See
473    /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
474    #[inline]
475    #[must_use]
476    pub fn from_scale_angle_translation(scale: Vec2, angle: f32, translation: Vec2) -> Self {
477        let (sin, cos) = math::sin_cos(angle);
478        Self::from_cols(
479            Vec3A::new(cos * scale.x, sin * scale.x, 0.0),
480            Vec3A::new(-sin * scale.y, cos * scale.y, 0.0),
481            Vec3A::new(translation.x, translation.y, 1.0),
482        )
483    }
484
485    /// Creates an affine transformation matrix from the given non-uniform 2D `scale`.
486    ///
487    /// The resulting matrix can be used to transform 2D points and vectors. See
488    /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
489    ///
490    /// # Panics
491    ///
492    /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled.
493    #[inline]
494    #[must_use]
495    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
496    pub fn from_scale(scale: Vec2) -> Self {
497        // Do not panic as long as any component is non-zero
498        glam_assert!(scale.cmpne(Vec2::ZERO).any());
499
500        Self::from_cols(
501            Vec3A::new(scale.x, 0.0, 0.0),
502            Vec3A::new(0.0, scale.y, 0.0),
503            Vec3A::Z,
504        )
505    }
506
507    /// Creates an affine transformation matrix from the given 2x2 matrix.
508    ///
509    /// The resulting matrix can be used to transform 2D points and vectors. See
510    /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
511    #[inline]
512    pub fn from_mat2(m: Mat2) -> Self {
513        Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), Vec3A::Z)
514    }
515
516    /// Creates a 3x3 matrix from the first 9 values in `slice`.
517    ///
518    /// See also [`Self::from_rows_slice`] when the slice is in row major order.
519    ///
520    /// # Panics
521    ///
522    /// Panics if `slice` is less than 9 elements long.
523    #[inline]
524    #[must_use]
525    #[track_caller]
526    pub const fn from_cols_slice(slice: &[f32]) -> Self {
527        Self::new(
528            slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
529            slice[8],
530        )
531    }
532
533    /// Writes the columns of `self` to the first 9 elements in `slice`.
534    ///
535    /// # Panics
536    ///
537    /// Panics if `slice` is less than 9 elements long.
538    #[inline]
539    #[track_caller]
540    pub fn write_cols_to_slice(&self, slice: &mut [f32]) {
541        slice[0] = self.x_axis.x;
542        slice[1] = self.x_axis.y;
543        slice[2] = self.x_axis.z;
544        slice[3] = self.y_axis.x;
545        slice[4] = self.y_axis.y;
546        slice[5] = self.y_axis.z;
547        slice[6] = self.z_axis.x;
548        slice[7] = self.z_axis.y;
549        slice[8] = self.z_axis.z;
550    }
551
552    /// Creates a 3x3 matrix from the first 9 values in `slice`, stored in row
553    /// major order.
554    ///
555    /// Matrices are stored in column major order, so the slice is permuted into the
556    /// matrix layout. Use [`Self::from_cols_slice`] instead when the slice is already in
557    /// column major order.
558    ///
559    /// # Panics
560    ///
561    /// Panics if `slice` is less than 9 elements long.
562    #[inline]
563    #[must_use]
564    #[track_caller]
565    pub const fn from_rows_slice(slice: &[f32]) -> Self {
566        Self::new(
567            slice[0], slice[3], slice[6], slice[1], slice[4], slice[7], slice[2], slice[5],
568            slice[8],
569        )
570    }
571
572    /// Returns the matrix column for the given `index`.
573    ///
574    /// # Panics
575    ///
576    /// Panics if `index` is greater than 2.
577    #[inline]
578    #[must_use]
579    #[track_caller]
580    pub fn col(&self, index: usize) -> Vec3A {
581        match index {
582            0 => self.x_axis,
583            1 => self.y_axis,
584            2 => self.z_axis,
585            _ => panic!("index out of bounds"),
586        }
587    }
588
589    /// Returns a mutable reference to the matrix column for the given `index`.
590    ///
591    /// # Panics
592    ///
593    /// Panics if `index` is greater than 2.
594    #[inline]
595    #[track_caller]
596    pub fn col_mut(&mut self, index: usize) -> &mut Vec3A {
597        match index {
598            0 => &mut self.x_axis,
599            1 => &mut self.y_axis,
600            2 => &mut self.z_axis,
601            _ => panic!("index out of bounds"),
602        }
603    }
604
605    /// Returns the matrix row for the given `index`.
606    ///
607    /// See also [`Self::set_row`] when you need to change the row.
608    ///
609    /// # Panics
610    ///
611    /// Panics if `index` is greater than 2.
612    #[inline]
613    #[must_use]
614    #[track_caller]
615    pub fn row(&self, index: usize) -> Vec3A {
616        match index {
617            0 => Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
618            1 => Vec3A::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
619            2 => Vec3A::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
620            _ => panic!("index out of bounds"),
621        }
622    }
623
624    /// Sets the matrix row for the given `index`.
625    ///
626    /// Matrices are stored in column major order, so the row is spread across all
627    /// 3 columns and writing it touches every column. Use [`Self::col_mut`]
628    /// instead when you can work with columns. See also [`Self::row`].
629    ///
630    /// # Panics
631    ///
632    /// Panics if `index` is greater than 2.
633    #[inline]
634    #[track_caller]
635    pub fn set_row(&mut self, index: usize, row: Vec3A) {
636        match index {
637            0 => {
638                self.x_axis.x = row.x;
639                self.y_axis.x = row.y;
640                self.z_axis.x = row.z;
641            }
642            1 => {
643                self.x_axis.y = row.x;
644                self.y_axis.y = row.y;
645                self.z_axis.y = row.z;
646            }
647            2 => {
648                self.x_axis.z = row.x;
649                self.y_axis.z = row.y;
650                self.z_axis.z = row.z;
651            }
652            _ => panic!("index out of bounds"),
653        }
654    }
655
656    /// Returns `true` if, and only if, all elements are finite.
657    /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
658    #[inline]
659    #[must_use]
660    pub fn is_finite(&self) -> bool {
661        self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
662    }
663
664    /// Returns `true` if any elements are `NaN`.
665    #[inline]
666    #[must_use]
667    pub fn is_nan(&self) -> bool {
668        self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
669    }
670
671    /// Returns the transpose of `self`.
672    #[inline]
673    #[must_use]
674    pub fn transpose(&self) -> Self {
675        let x = self.x_axis.0;
676        let y = self.y_axis.0;
677        let z = self.z_axis.0;
678        unsafe {
679            let tmp0 = vreinterpretq_f32_u64(vsetq_lane_u64(
680                vgetq_lane_u64(vreinterpretq_u64_f32(y), 0),
681                vreinterpretq_u64_f32(x),
682                1,
683            ));
684            let tmp1 = vreinterpretq_f32_u64(vzip2q_u64(
685                vreinterpretq_u64_f32(x),
686                vreinterpretq_u64_f32(y),
687            ));
688            Mat3A::from_cols(
689                Vec3A::from(vsetq_lane_f32(vgetq_lane_f32(z, 0), vuzp1q_f32(tmp0, z), 3)),
690                Vec3A::from(vuzp2q_f32(tmp0, vdupq_laneq_f32(z, 1))),
691                Vec3A::from(vsetq_lane_f32(vgetq_lane_f32(z, 2), vuzp1q_f32(tmp1, z), 2)),
692            )
693        }
694    }
695
696    /// Returns the diagonal of `self`.
697    #[inline]
698    #[must_use]
699    pub fn diagonal(&self) -> Vec3A {
700        Vec3A::new(self.x_axis.x, self.y_axis.y, self.z_axis.z)
701    }
702
703    /// Returns the determinant of `self`.
704    #[inline]
705    #[must_use]
706    pub fn determinant(&self) -> f32 {
707        self.x_axis.dot(self.y_axis.cross(self.z_axis))
708    }
709
710    /// If `CHECKED` is true then if the determinant is zero this function will return a tuple
711    /// containing a zero matrix and false. If the determinant is non zero a tuple containing the
712    /// inverted matrix and true is returned.
713    ///
714    /// If `CHECKED` is false then the determinant is not checked and if it is zero the resulting
715    /// inverted matrix will be invalid. Will panic if the resulting inverted matrix is not finite
716    /// when `glam_assert` is enabled.
717    ///
718    /// A tuple containing the inverted matrix and a bool is used instead of an option here as
719    /// regular Rust enums put the discriminant first which can result in a lot of padding if the
720    /// matrix is aligned.
721    #[inline(always)]
722    #[must_use]
723    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
724    fn inverse_checked<const CHECKED: bool>(&self) -> (Self, bool) {
725        let tmp0 = self.y_axis.cross(self.z_axis);
726        let tmp1 = self.z_axis.cross(self.x_axis);
727        let tmp2 = self.x_axis.cross(self.y_axis);
728        let inv_det = Vec3A::splat(1.0 / self.x_axis.dot(tmp0));
729        let m =
730            Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose();
731        if CHECKED {
732            if !m.is_finite() {
733                return (Self::ZERO, false);
734            }
735        } else {
736            glam_assert!(m.is_finite());
737        }
738        (m, true)
739    }
740
741    /// Returns the inverse of `self`.
742    ///
743    /// If the matrix is not invertible the returned matrix will be invalid. The
744    /// returned matrix will also be invalid if the inverse is not finite, which can
745    /// happen when `self` contains very large or very small values. Use
746    /// [`Self::try_inverse`] or [`Self::inverse_or_zero`] to detect these cases.
747    ///
748    /// # Panics
749    ///
750    /// Will panic if the resulting inverted matrix is not finite when `glam_assert`
751    /// is enabled.
752    #[inline]
753    #[must_use]
754    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
755    pub fn inverse(&self) -> Self {
756        self.inverse_checked::<false>().0
757    }
758
759    /// Returns the inverse of `self` or `None` if the matrix is not invertible, or if
760    /// the inverse is not finite.
761    #[inline]
762    #[must_use]
763    pub fn try_inverse(&self) -> Option<Self> {
764        let (m, is_valid) = self.inverse_checked::<true>();
765        if is_valid { Some(m) } else { None }
766    }
767
768    /// Returns the inverse of `self` or `Mat3A::ZERO` if the matrix is not
769    /// invertible, or if the inverse is not finite.
770    #[inline]
771    #[must_use]
772    pub fn inverse_or_zero(&self) -> Self {
773        self.inverse_checked::<true>().0
774    }
775
776    /// Transforms the given 2D vector as a point.
777    ///
778    /// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`.
779    ///
780    /// This method assumes that `self` contains a valid affine transform.
781    ///
782    /// # Panics
783    ///
784    /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled.
785    #[inline]
786    #[must_use]
787    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
788    pub fn transform_point2(&self, rhs: Vec2) -> Vec2 {
789        glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
790        Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
791    }
792
793    /// Rotates the given 2D vector.
794    ///
795    /// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`.
796    ///
797    /// This method assumes that `self` contains a valid affine transform.
798    ///
799    /// # Panics
800    ///
801    /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled.
802    #[inline]
803    #[must_use]
804    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
805    pub fn transform_vector2(&self, rhs: Vec2) -> Vec2 {
806        glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
807        Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
808    }
809
810    /// Transforms a 3D vector.
811    #[inline]
812    #[must_use]
813    pub fn mul_vec3(&self, rhs: Vec3) -> Vec3 {
814        self.mul_vec3a(rhs.into()).into()
815    }
816
817    /// Transforms a [`Vec3A`].
818    #[inline]
819    #[must_use]
820    pub fn mul_vec3a(&self, rhs: Vec3A) -> Vec3A {
821        let mut res = self.x_axis.mul(rhs.xxx());
822        res = res.add(self.y_axis.mul(rhs.yyy()));
823        res = res.add(self.z_axis.mul(rhs.zzz()));
824        res
825    }
826
827    /// Transforms a 3D vector by the transpose of `self`.
828    #[inline]
829    #[must_use]
830    pub fn transpose_mul_vec3(&self, rhs: Vec3) -> Vec3 {
831        self.transpose_mul_vec3a(rhs.into()).into()
832    }
833
834    /// Transforms a 3D vector by the transpose of `self`.
835    #[inline]
836    #[must_use]
837    #[deprecated(
838        since = "0.34.2",
839        note = "Use `transpose_mul_vec3` instead, whose word order matches its order of operations and is consistent with `transpose().mul_vec3`."
840    )]
841    pub fn mul_transpose_vec3(&self, rhs: Vec3) -> Vec3 {
842        self.transpose_mul_vec3(rhs)
843    }
844
845    /// Transforms a [`Vec3A`] by the transpose of `self`.
846    #[inline]
847    #[must_use]
848    pub fn transpose_mul_vec3a(&self, rhs: Vec3A) -> Vec3A {
849        Vec3A::new(
850            self.x_axis.dot(rhs),
851            self.y_axis.dot(rhs),
852            self.z_axis.dot(rhs),
853        )
854    }
855
856    /// Transforms a [`Vec3A`] by the transpose of `self`.
857    #[inline]
858    #[must_use]
859    #[deprecated(
860        since = "0.34.2",
861        note = "Use `transpose_mul_vec3a` instead, whose word order matches its order of operations and is consistent with `transpose().mul_vec3a`."
862    )]
863    pub fn mul_transpose_vec3a(&self, rhs: Vec3A) -> Vec3A {
864        self.transpose_mul_vec3a(rhs)
865    }
866
867    /// Multiplies two 3x3 matrices.
868    #[inline]
869    #[must_use]
870    pub fn mul_mat3(&self, rhs: &Self) -> Self {
871        self.mul(rhs)
872    }
873
874    /// Adds two 3x3 matrices.
875    #[inline]
876    #[must_use]
877    pub fn add_mat3(&self, rhs: &Self) -> Self {
878        self.add(rhs)
879    }
880
881    /// Subtracts two 3x3 matrices.
882    #[inline]
883    #[must_use]
884    pub fn sub_mat3(&self, rhs: &Self) -> Self {
885        self.sub(rhs)
886    }
887
888    /// Multiplies a 3x3 matrix by a scalar.
889    #[inline]
890    #[must_use]
891    pub fn mul_scalar(&self, rhs: f32) -> Self {
892        Self::from_cols(
893            self.x_axis.mul(rhs),
894            self.y_axis.mul(rhs),
895            self.z_axis.mul(rhs),
896        )
897    }
898
899    /// Multiply `self` by a scaling vector `scale`.
900    /// This is faster than creating a whole diagonal scaling matrix and then multiplying that.
901    /// This operation is commutative.
902    #[inline]
903    #[must_use]
904    pub fn mul_diagonal_scale(&self, scale: Vec3) -> Self {
905        Self::from_cols(
906            self.x_axis * scale.x,
907            self.y_axis * scale.y,
908            self.z_axis * scale.z,
909        )
910    }
911
912    /// Divides a 3x3 matrix by a scalar.
913    #[inline]
914    #[must_use]
915    pub fn div_scalar(&self, rhs: f32) -> Self {
916        let rhs = Vec3A::splat(rhs);
917        Self::from_cols(
918            self.x_axis.div(rhs),
919            self.y_axis.div(rhs),
920            self.z_axis.div(rhs),
921        )
922    }
923
924    /// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
925    #[inline]
926    #[must_use]
927    pub fn recip(&self) -> Self {
928        Self::from_cols(
929            self.x_axis.recip(),
930            self.y_axis.recip(),
931            self.z_axis.recip(),
932        )
933    }
934
935    /// Returns true if the absolute difference of all elements between `self` and `rhs`
936    /// is less than or equal to `max_abs_diff`.
937    ///
938    /// This can be used to compare if two matrices contain similar elements. It works best
939    /// when comparing with a known value. The `max_abs_diff` that should be used used
940    /// depends on the values being compared against.
941    ///
942    /// For more see
943    /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
944    #[inline]
945    #[must_use]
946    pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
947        self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
948            && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
949            && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
950    }
951
952    /// Takes the absolute value of each element in `self`
953    #[inline]
954    #[must_use]
955    pub fn abs(&self) -> Self {
956        Self::from_cols(self.x_axis.abs(), self.y_axis.abs(), self.z_axis.abs())
957    }
958
959    #[cfg(feature = "f64")]
960    #[inline]
961    #[must_use]
962    pub fn as_dmat3(&self) -> DMat3 {
963        DMat3::from_cols(
964            self.x_axis.as_dvec3(),
965            self.y_axis.as_dvec3(),
966            self.z_axis.as_dvec3(),
967        )
968    }
969}
970
971impl Default for Mat3A {
972    #[inline]
973    fn default() -> Self {
974        Self::IDENTITY
975    }
976}
977
978impl Add for Mat3A {
979    type Output = Self;
980    #[inline]
981    fn add(self, rhs: Self) -> Self {
982        Self::from_cols(
983            self.x_axis.add(rhs.x_axis),
984            self.y_axis.add(rhs.y_axis),
985            self.z_axis.add(rhs.z_axis),
986        )
987    }
988}
989
990impl Add<&Self> for Mat3A {
991    type Output = Self;
992    #[inline]
993    fn add(self, rhs: &Self) -> Self {
994        self.add(*rhs)
995    }
996}
997
998impl Add<&Mat3A> for &Mat3A {
999    type Output = Mat3A;
1000    #[inline]
1001    fn add(self, rhs: &Mat3A) -> Mat3A {
1002        (*self).add(*rhs)
1003    }
1004}
1005
1006impl Add<Mat3A> for &Mat3A {
1007    type Output = Mat3A;
1008    #[inline]
1009    fn add(self, rhs: Mat3A) -> Mat3A {
1010        (*self).add(rhs)
1011    }
1012}
1013
1014impl AddAssign for Mat3A {
1015    #[inline]
1016    fn add_assign(&mut self, rhs: Self) {
1017        *self = self.add(rhs);
1018    }
1019}
1020
1021impl AddAssign<&Self> for Mat3A {
1022    #[inline]
1023    fn add_assign(&mut self, rhs: &Self) {
1024        self.add_assign(*rhs);
1025    }
1026}
1027
1028impl Sub for Mat3A {
1029    type Output = Self;
1030    #[inline]
1031    fn sub(self, rhs: Self) -> Self {
1032        Self::from_cols(
1033            self.x_axis.sub(rhs.x_axis),
1034            self.y_axis.sub(rhs.y_axis),
1035            self.z_axis.sub(rhs.z_axis),
1036        )
1037    }
1038}
1039
1040impl Sub<&Self> for Mat3A {
1041    type Output = Self;
1042    #[inline]
1043    fn sub(self, rhs: &Self) -> Self {
1044        self.sub(*rhs)
1045    }
1046}
1047
1048impl Sub<&Mat3A> for &Mat3A {
1049    type Output = Mat3A;
1050    #[inline]
1051    fn sub(self, rhs: &Mat3A) -> Mat3A {
1052        (*self).sub(*rhs)
1053    }
1054}
1055
1056impl Sub<Mat3A> for &Mat3A {
1057    type Output = Mat3A;
1058    #[inline]
1059    fn sub(self, rhs: Mat3A) -> Mat3A {
1060        (*self).sub(rhs)
1061    }
1062}
1063
1064impl SubAssign for Mat3A {
1065    #[inline]
1066    fn sub_assign(&mut self, rhs: Self) {
1067        *self = self.sub(rhs);
1068    }
1069}
1070
1071impl SubAssign<&Self> for Mat3A {
1072    #[inline]
1073    fn sub_assign(&mut self, rhs: &Self) {
1074        self.sub_assign(*rhs);
1075    }
1076}
1077
1078impl Neg for Mat3A {
1079    type Output = Self;
1080    #[inline]
1081    fn neg(self) -> Self::Output {
1082        Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
1083    }
1084}
1085
1086impl Neg for &Mat3A {
1087    type Output = Mat3A;
1088    #[inline]
1089    fn neg(self) -> Mat3A {
1090        (*self).neg()
1091    }
1092}
1093
1094impl Mul for Mat3A {
1095    type Output = Self;
1096    #[inline]
1097    fn mul(self, rhs: Self) -> Self {
1098        Self::from_cols(
1099            self.mul(rhs.x_axis),
1100            self.mul(rhs.y_axis),
1101            self.mul(rhs.z_axis),
1102        )
1103    }
1104}
1105
1106impl Mul<&Self> for Mat3A {
1107    type Output = Self;
1108    #[inline]
1109    fn mul(self, rhs: &Self) -> Self {
1110        self.mul(*rhs)
1111    }
1112}
1113
1114impl Mul<&Mat3A> for &Mat3A {
1115    type Output = Mat3A;
1116    #[inline]
1117    fn mul(self, rhs: &Mat3A) -> Mat3A {
1118        (*self).mul(*rhs)
1119    }
1120}
1121
1122impl Mul<Mat3A> for &Mat3A {
1123    type Output = Mat3A;
1124    #[inline]
1125    fn mul(self, rhs: Mat3A) -> Mat3A {
1126        (*self).mul(rhs)
1127    }
1128}
1129
1130impl MulAssign for Mat3A {
1131    #[inline]
1132    fn mul_assign(&mut self, rhs: Self) {
1133        *self = self.mul(rhs);
1134    }
1135}
1136
1137impl MulAssign<&Self> for Mat3A {
1138    #[inline]
1139    fn mul_assign(&mut self, rhs: &Self) {
1140        self.mul_assign(*rhs);
1141    }
1142}
1143
1144impl Mul<Vec3A> for Mat3A {
1145    type Output = Vec3A;
1146    #[inline]
1147    fn mul(self, rhs: Vec3A) -> Self::Output {
1148        self.mul_vec3a(rhs)
1149    }
1150}
1151
1152impl Mul<&Vec3A> for Mat3A {
1153    type Output = Vec3A;
1154    #[inline]
1155    fn mul(self, rhs: &Vec3A) -> Vec3A {
1156        self.mul(*rhs)
1157    }
1158}
1159
1160impl Mul<&Vec3A> for &Mat3A {
1161    type Output = Vec3A;
1162    #[inline]
1163    fn mul(self, rhs: &Vec3A) -> Vec3A {
1164        (*self).mul(*rhs)
1165    }
1166}
1167
1168impl Mul<Vec3A> for &Mat3A {
1169    type Output = Vec3A;
1170    #[inline]
1171    fn mul(self, rhs: Vec3A) -> Vec3A {
1172        (*self).mul(rhs)
1173    }
1174}
1175
1176impl Mul<Mat3A> for f32 {
1177    type Output = Mat3A;
1178    #[inline]
1179    fn mul(self, rhs: Mat3A) -> Self::Output {
1180        rhs.mul_scalar(self)
1181    }
1182}
1183
1184impl Mul<&Mat3A> for f32 {
1185    type Output = Mat3A;
1186    #[inline]
1187    fn mul(self, rhs: &Mat3A) -> Mat3A {
1188        self.mul(*rhs)
1189    }
1190}
1191
1192impl Mul<&Mat3A> for &f32 {
1193    type Output = Mat3A;
1194    #[inline]
1195    fn mul(self, rhs: &Mat3A) -> Mat3A {
1196        (*self).mul(*rhs)
1197    }
1198}
1199
1200impl Mul<Mat3A> for &f32 {
1201    type Output = Mat3A;
1202    #[inline]
1203    fn mul(self, rhs: Mat3A) -> Mat3A {
1204        (*self).mul(rhs)
1205    }
1206}
1207
1208impl Mul<f32> for Mat3A {
1209    type Output = Self;
1210    #[inline]
1211    fn mul(self, rhs: f32) -> Self {
1212        self.mul_scalar(rhs)
1213    }
1214}
1215
1216impl Mul<&f32> for Mat3A {
1217    type Output = Self;
1218    #[inline]
1219    fn mul(self, rhs: &f32) -> Self {
1220        self.mul(*rhs)
1221    }
1222}
1223
1224impl Mul<&f32> for &Mat3A {
1225    type Output = Mat3A;
1226    #[inline]
1227    fn mul(self, rhs: &f32) -> Mat3A {
1228        (*self).mul(*rhs)
1229    }
1230}
1231
1232impl Mul<f32> for &Mat3A {
1233    type Output = Mat3A;
1234    #[inline]
1235    fn mul(self, rhs: f32) -> Mat3A {
1236        (*self).mul(rhs)
1237    }
1238}
1239
1240impl MulAssign<f32> for Mat3A {
1241    #[inline]
1242    fn mul_assign(&mut self, rhs: f32) {
1243        *self = self.mul(rhs);
1244    }
1245}
1246
1247impl MulAssign<&f32> for Mat3A {
1248    #[inline]
1249    fn mul_assign(&mut self, rhs: &f32) {
1250        self.mul_assign(*rhs);
1251    }
1252}
1253
1254impl Div<Mat3A> for f32 {
1255    type Output = Mat3A;
1256    #[inline]
1257    fn div(self, rhs: Mat3A) -> Self::Output {
1258        Mat3A::from_cols(
1259            self.div(rhs.x_axis),
1260            self.div(rhs.y_axis),
1261            self.div(rhs.z_axis),
1262        )
1263    }
1264}
1265
1266impl Div<&Mat3A> for f32 {
1267    type Output = Mat3A;
1268    #[inline]
1269    fn div(self, rhs: &Mat3A) -> Mat3A {
1270        self.div(*rhs)
1271    }
1272}
1273
1274impl Div<&Mat3A> for &f32 {
1275    type Output = Mat3A;
1276    #[inline]
1277    fn div(self, rhs: &Mat3A) -> Mat3A {
1278        (*self).div(*rhs)
1279    }
1280}
1281
1282impl Div<Mat3A> for &f32 {
1283    type Output = Mat3A;
1284    #[inline]
1285    fn div(self, rhs: Mat3A) -> Mat3A {
1286        (*self).div(rhs)
1287    }
1288}
1289
1290impl Div<f32> for Mat3A {
1291    type Output = Self;
1292    #[inline]
1293    fn div(self, rhs: f32) -> Self {
1294        self.div_scalar(rhs)
1295    }
1296}
1297
1298impl Div<&f32> for Mat3A {
1299    type Output = Self;
1300    #[inline]
1301    fn div(self, rhs: &f32) -> Self {
1302        self.div(*rhs)
1303    }
1304}
1305
1306impl Div<&f32> for &Mat3A {
1307    type Output = Mat3A;
1308    #[inline]
1309    fn div(self, rhs: &f32) -> Mat3A {
1310        (*self).div(*rhs)
1311    }
1312}
1313
1314impl Div<f32> for &Mat3A {
1315    type Output = Mat3A;
1316    #[inline]
1317    fn div(self, rhs: f32) -> Mat3A {
1318        (*self).div(rhs)
1319    }
1320}
1321
1322impl DivAssign<f32> for Mat3A {
1323    #[inline]
1324    fn div_assign(&mut self, rhs: f32) {
1325        *self = self.div(rhs);
1326    }
1327}
1328
1329impl DivAssign<&f32> for Mat3A {
1330    #[inline]
1331    fn div_assign(&mut self, rhs: &f32) {
1332        self.div_assign(*rhs);
1333    }
1334}
1335
1336impl Mul<Vec3> for Mat3A {
1337    type Output = Vec3;
1338    #[inline]
1339    fn mul(self, rhs: Vec3) -> Vec3 {
1340        self.mul_vec3a(rhs.into()).into()
1341    }
1342}
1343
1344impl Mul<&Vec3> for Mat3A {
1345    type Output = Vec3;
1346    #[inline]
1347    fn mul(self, rhs: &Vec3) -> Vec3 {
1348        self.mul(*rhs)
1349    }
1350}
1351
1352impl Mul<&Vec3> for &Mat3A {
1353    type Output = Vec3;
1354    #[inline]
1355    fn mul(self, rhs: &Vec3) -> Vec3 {
1356        (*self).mul(*rhs)
1357    }
1358}
1359
1360impl Mul<Vec3> for &Mat3A {
1361    type Output = Vec3;
1362    #[inline]
1363    fn mul(self, rhs: Vec3) -> Vec3 {
1364        (*self).mul(rhs)
1365    }
1366}
1367
1368impl From<Mat3> for Mat3A {
1369    #[inline]
1370    fn from(m: Mat3) -> Self {
1371        Self {
1372            x_axis: m.x_axis.into(),
1373            y_axis: m.y_axis.into(),
1374            z_axis: m.z_axis.into(),
1375        }
1376    }
1377}
1378
1379impl Sum<Self> for Mat3A {
1380    fn sum<I>(iter: I) -> Self
1381    where
1382        I: Iterator<Item = Self>,
1383    {
1384        iter.fold(Self::ZERO, Self::add)
1385    }
1386}
1387
1388impl<'a> Sum<&'a Self> for Mat3A {
1389    fn sum<I>(iter: I) -> Self
1390    where
1391        I: Iterator<Item = &'a Self>,
1392    {
1393        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1394    }
1395}
1396
1397impl Product for Mat3A {
1398    fn product<I>(iter: I) -> Self
1399    where
1400        I: Iterator<Item = Self>,
1401    {
1402        iter.fold(Self::IDENTITY, Self::mul)
1403    }
1404}
1405
1406impl<'a> Product<&'a Self> for Mat3A {
1407    fn product<I>(iter: I) -> Self
1408    where
1409        I: Iterator<Item = &'a Self>,
1410    {
1411        iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
1412    }
1413}
1414
1415impl PartialEq for Mat3A {
1416    #[inline]
1417    fn eq(&self, rhs: &Self) -> bool {
1418        self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
1419    }
1420}
1421
1422impl fmt::Debug for Mat3A {
1423    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1424        fmt.debug_struct(stringify!(Mat3A))
1425            .field("x_axis", &self.x_axis)
1426            .field("y_axis", &self.y_axis)
1427            .field("z_axis", &self.z_axis)
1428            .finish()
1429    }
1430}
1431
1432impl fmt::Display for Mat3A {
1433    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1434        if let Some(p) = f.precision() {
1435            write!(
1436                f,
1437                "[{:.*}, {:.*}, {:.*}]",
1438                p, self.x_axis, p, self.y_axis, p, self.z_axis
1439            )
1440        } else {
1441            write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
1442        }
1443    }
1444}