1use crate::{
4 euler::{FromEuler, ToEuler},
5 f32::math,
6 swizzles::*,
7 DMat3, EulerRot, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A,
8};
9use core::fmt;
10use core::iter::{Product, Sum};
11use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
12
13#[cfg(target_arch = "x86")]
14use core::arch::x86::*;
15#[cfg(target_arch = "x86_64")]
16use core::arch::x86_64::*;
17
18#[cfg(feature = "zerocopy")]
19use zerocopy_derive::*;
20
21#[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#[derive(Clone, Copy)]
53#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
54#[cfg_attr(
55 feature = "zerocopy",
56 derive(FromBytes, Immutable, IntoBytes, KnownLayout)
57)]
58#[repr(C)]
59pub struct Mat3A {
60 pub x_axis: Vec3A,
61 pub y_axis: Vec3A,
62 pub z_axis: Vec3A,
63}
64
65impl Mat3A {
66 pub const ZERO: Self = Self::from_cols(Vec3A::ZERO, Vec3A::ZERO, Vec3A::ZERO);
68
69 pub const IDENTITY: Self = Self::from_cols(Vec3A::X, Vec3A::Y, Vec3A::Z);
71
72 pub const NAN: Self = Self::from_cols(Vec3A::NAN, Vec3A::NAN, Vec3A::NAN);
74
75 #[allow(clippy::too_many_arguments)]
76 #[inline(always)]
77 #[must_use]
78 const fn new(
79 m00: f32,
80 m01: f32,
81 m02: f32,
82 m10: f32,
83 m11: f32,
84 m12: f32,
85 m20: f32,
86 m21: f32,
87 m22: f32,
88 ) -> Self {
89 Self {
90 x_axis: Vec3A::new(m00, m01, m02),
91 y_axis: Vec3A::new(m10, m11, m12),
92 z_axis: Vec3A::new(m20, m21, m22),
93 }
94 }
95
96 #[inline(always)]
98 #[must_use]
99 pub const fn from_cols(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Self {
100 Self {
101 x_axis,
102 y_axis,
103 z_axis,
104 }
105 }
106
107 #[inline]
111 #[must_use]
112 pub const fn from_cols_array(m: &[f32; 9]) -> Self {
113 Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
114 }
115
116 #[inline]
119 #[must_use]
120 pub const fn to_cols_array(&self) -> [f32; 9] {
121 let [x_axis_x, x_axis_y, x_axis_z] = self.x_axis.to_array();
122 let [y_axis_x, y_axis_y, y_axis_z] = self.y_axis.to_array();
123 let [z_axis_x, z_axis_y, z_axis_z] = self.z_axis.to_array();
124
125 [
126 x_axis_x, x_axis_y, x_axis_z, y_axis_x, y_axis_y, y_axis_z, z_axis_x, z_axis_y,
127 z_axis_z,
128 ]
129 }
130
131 #[inline]
135 #[must_use]
136 pub const fn from_cols_array_2d(m: &[[f32; 3]; 3]) -> Self {
137 Self::from_cols(
138 Vec3A::from_array(m[0]),
139 Vec3A::from_array(m[1]),
140 Vec3A::from_array(m[2]),
141 )
142 }
143
144 #[inline]
147 #[must_use]
148 pub const fn to_cols_array_2d(&self) -> [[f32; 3]; 3] {
149 [
150 self.x_axis.to_array(),
151 self.y_axis.to_array(),
152 self.z_axis.to_array(),
153 ]
154 }
155
156 #[doc(alias = "scale")]
158 #[inline]
159 #[must_use]
160 pub const fn from_diagonal(diagonal: Vec3) -> Self {
161 Self::new(
162 diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
163 )
164 }
165
166 #[inline]
168 #[must_use]
169 pub fn from_mat4(m: Mat4) -> Self {
170 Self::from_cols(
171 Vec3A::from_vec4(m.x_axis),
172 Vec3A::from_vec4(m.y_axis),
173 Vec3A::from_vec4(m.z_axis),
174 )
175 }
176
177 #[inline]
184 #[must_use]
185 pub fn from_mat4_minor(m: Mat4, i: usize, j: usize) -> Self {
186 match (i, j) {
187 (0, 0) => Self::from_cols(
188 Vec3A::from_vec4(m.y_axis.yzww()),
189 Vec3A::from_vec4(m.z_axis.yzww()),
190 Vec3A::from_vec4(m.w_axis.yzww()),
191 ),
192 (0, 1) => Self::from_cols(
193 Vec3A::from_vec4(m.y_axis.xzww()),
194 Vec3A::from_vec4(m.z_axis.xzww()),
195 Vec3A::from_vec4(m.w_axis.xzww()),
196 ),
197 (0, 2) => Self::from_cols(
198 Vec3A::from_vec4(m.y_axis.xyww()),
199 Vec3A::from_vec4(m.z_axis.xyww()),
200 Vec3A::from_vec4(m.w_axis.xyww()),
201 ),
202 (0, 3) => Self::from_cols(
203 Vec3A::from_vec4(m.y_axis.xyzw()),
204 Vec3A::from_vec4(m.z_axis.xyzw()),
205 Vec3A::from_vec4(m.w_axis.xyzw()),
206 ),
207 (1, 0) => Self::from_cols(
208 Vec3A::from_vec4(m.x_axis.yzww()),
209 Vec3A::from_vec4(m.z_axis.yzww()),
210 Vec3A::from_vec4(m.w_axis.yzww()),
211 ),
212 (1, 1) => Self::from_cols(
213 Vec3A::from_vec4(m.x_axis.xzww()),
214 Vec3A::from_vec4(m.z_axis.xzww()),
215 Vec3A::from_vec4(m.w_axis.xzww()),
216 ),
217 (1, 2) => Self::from_cols(
218 Vec3A::from_vec4(m.x_axis.xyww()),
219 Vec3A::from_vec4(m.z_axis.xyww()),
220 Vec3A::from_vec4(m.w_axis.xyww()),
221 ),
222 (1, 3) => Self::from_cols(
223 Vec3A::from_vec4(m.x_axis.xyzw()),
224 Vec3A::from_vec4(m.z_axis.xyzw()),
225 Vec3A::from_vec4(m.w_axis.xyzw()),
226 ),
227 (2, 0) => Self::from_cols(
228 Vec3A::from_vec4(m.x_axis.yzww()),
229 Vec3A::from_vec4(m.y_axis.yzww()),
230 Vec3A::from_vec4(m.w_axis.yzww()),
231 ),
232 (2, 1) => Self::from_cols(
233 Vec3A::from_vec4(m.x_axis.xzww()),
234 Vec3A::from_vec4(m.y_axis.xzww()),
235 Vec3A::from_vec4(m.w_axis.xzww()),
236 ),
237 (2, 2) => Self::from_cols(
238 Vec3A::from_vec4(m.x_axis.xyww()),
239 Vec3A::from_vec4(m.y_axis.xyww()),
240 Vec3A::from_vec4(m.w_axis.xyww()),
241 ),
242 (2, 3) => Self::from_cols(
243 Vec3A::from_vec4(m.x_axis.xyzw()),
244 Vec3A::from_vec4(m.y_axis.xyzw()),
245 Vec3A::from_vec4(m.w_axis.xyzw()),
246 ),
247 (3, 0) => Self::from_cols(
248 Vec3A::from_vec4(m.x_axis.yzww()),
249 Vec3A::from_vec4(m.y_axis.yzww()),
250 Vec3A::from_vec4(m.z_axis.yzww()),
251 ),
252 (3, 1) => Self::from_cols(
253 Vec3A::from_vec4(m.x_axis.xzww()),
254 Vec3A::from_vec4(m.y_axis.xzww()),
255 Vec3A::from_vec4(m.z_axis.xzww()),
256 ),
257 (3, 2) => Self::from_cols(
258 Vec3A::from_vec4(m.x_axis.xyww()),
259 Vec3A::from_vec4(m.y_axis.xyww()),
260 Vec3A::from_vec4(m.z_axis.xyww()),
261 ),
262 (3, 3) => Self::from_cols(
263 Vec3A::from_vec4(m.x_axis.xyzw()),
264 Vec3A::from_vec4(m.y_axis.xyzw()),
265 Vec3A::from_vec4(m.z_axis.xyzw()),
266 ),
267 _ => panic!("index out of bounds"),
268 }
269 }
270
271 #[inline]
277 #[must_use]
278 pub fn from_quat(rotation: Quat) -> Self {
279 glam_assert!(rotation.is_normalized());
280
281 let x2 = rotation.x + rotation.x;
282 let y2 = rotation.y + rotation.y;
283 let z2 = rotation.z + rotation.z;
284 let xx = rotation.x * x2;
285 let xy = rotation.x * y2;
286 let xz = rotation.x * z2;
287 let yy = rotation.y * y2;
288 let yz = rotation.y * z2;
289 let zz = rotation.z * z2;
290 let wx = rotation.w * x2;
291 let wy = rotation.w * y2;
292 let wz = rotation.w * z2;
293
294 Self::from_cols(
295 Vec3A::new(1.0 - (yy + zz), xy + wz, xz - wy),
296 Vec3A::new(xy - wz, 1.0 - (xx + zz), yz + wx),
297 Vec3A::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
298 )
299 }
300
301 #[inline]
308 #[must_use]
309 pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self {
310 glam_assert!(axis.is_normalized());
311
312 let (sin, cos) = math::sin_cos(angle);
313 let (xsin, ysin, zsin) = axis.mul(sin).into();
314 let (x, y, z) = axis.into();
315 let (x2, y2, z2) = axis.mul(axis).into();
316 let omc = 1.0 - cos;
317 let xyomc = x * y * omc;
318 let xzomc = x * z * omc;
319 let yzomc = y * z * omc;
320 Self::from_cols(
321 Vec3A::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
322 Vec3A::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
323 Vec3A::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
324 )
325 }
326
327 #[inline]
330 #[must_use]
331 pub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Self {
332 Self::from_euler_angles(order, a, b, c)
333 }
334
335 #[inline]
344 #[must_use]
345 pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
346 glam_assert!(
347 self.x_axis.is_normalized()
348 && self.y_axis.is_normalized()
349 && self.z_axis.is_normalized()
350 );
351 self.to_euler_angles(order)
352 }
353
354 #[inline]
356 #[must_use]
357 pub fn from_rotation_x(angle: f32) -> Self {
358 let (sina, cosa) = math::sin_cos(angle);
359 Self::from_cols(
360 Vec3A::X,
361 Vec3A::new(0.0, cosa, sina),
362 Vec3A::new(0.0, -sina, cosa),
363 )
364 }
365
366 #[inline]
368 #[must_use]
369 pub fn from_rotation_y(angle: f32) -> Self {
370 let (sina, cosa) = math::sin_cos(angle);
371 Self::from_cols(
372 Vec3A::new(cosa, 0.0, -sina),
373 Vec3A::Y,
374 Vec3A::new(sina, 0.0, cosa),
375 )
376 }
377
378 #[inline]
380 #[must_use]
381 pub fn from_rotation_z(angle: f32) -> Self {
382 let (sina, cosa) = math::sin_cos(angle);
383 Self::from_cols(
384 Vec3A::new(cosa, sina, 0.0),
385 Vec3A::new(-sina, cosa, 0.0),
386 Vec3A::Z,
387 )
388 }
389
390 #[inline]
395 #[must_use]
396 pub fn from_translation(translation: Vec2) -> Self {
397 Self::from_cols(
398 Vec3A::X,
399 Vec3A::Y,
400 Vec3A::new(translation.x, translation.y, 1.0),
401 )
402 }
403
404 #[inline]
410 #[must_use]
411 pub fn from_angle(angle: f32) -> Self {
412 let (sin, cos) = math::sin_cos(angle);
413 Self::from_cols(
414 Vec3A::new(cos, sin, 0.0),
415 Vec3A::new(-sin, cos, 0.0),
416 Vec3A::Z,
417 )
418 }
419
420 #[inline]
426 #[must_use]
427 pub fn from_scale_angle_translation(scale: Vec2, angle: f32, translation: Vec2) -> Self {
428 let (sin, cos) = math::sin_cos(angle);
429 Self::from_cols(
430 Vec3A::new(cos * scale.x, sin * scale.x, 0.0),
431 Vec3A::new(-sin * scale.y, cos * scale.y, 0.0),
432 Vec3A::new(translation.x, translation.y, 1.0),
433 )
434 }
435
436 #[inline]
445 #[must_use]
446 pub fn from_scale(scale: Vec2) -> Self {
447 glam_assert!(scale.cmpne(Vec2::ZERO).any());
449
450 Self::from_cols(
451 Vec3A::new(scale.x, 0.0, 0.0),
452 Vec3A::new(0.0, scale.y, 0.0),
453 Vec3A::Z,
454 )
455 }
456
457 #[inline]
462 pub fn from_mat2(m: Mat2) -> Self {
463 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), Vec3A::Z)
464 }
465
466 #[inline]
472 #[must_use]
473 pub const fn from_cols_slice(slice: &[f32]) -> Self {
474 Self::new(
475 slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
476 slice[8],
477 )
478 }
479
480 #[inline]
486 pub fn write_cols_to_slice(&self, slice: &mut [f32]) {
487 slice[0] = self.x_axis.x;
488 slice[1] = self.x_axis.y;
489 slice[2] = self.x_axis.z;
490 slice[3] = self.y_axis.x;
491 slice[4] = self.y_axis.y;
492 slice[5] = self.y_axis.z;
493 slice[6] = self.z_axis.x;
494 slice[7] = self.z_axis.y;
495 slice[8] = self.z_axis.z;
496 }
497
498 #[inline]
504 #[must_use]
505 pub fn col(&self, index: usize) -> Vec3A {
506 match index {
507 0 => self.x_axis,
508 1 => self.y_axis,
509 2 => self.z_axis,
510 _ => panic!("index out of bounds"),
511 }
512 }
513
514 #[inline]
520 pub fn col_mut(&mut self, index: usize) -> &mut Vec3A {
521 match index {
522 0 => &mut self.x_axis,
523 1 => &mut self.y_axis,
524 2 => &mut self.z_axis,
525 _ => panic!("index out of bounds"),
526 }
527 }
528
529 #[inline]
535 #[must_use]
536 pub fn row(&self, index: usize) -> Vec3A {
537 match index {
538 0 => Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
539 1 => Vec3A::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
540 2 => Vec3A::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
541 _ => panic!("index out of bounds"),
542 }
543 }
544
545 #[inline]
548 #[must_use]
549 pub fn is_finite(&self) -> bool {
550 self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
551 }
552
553 #[inline]
555 #[must_use]
556 pub fn is_nan(&self) -> bool {
557 self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
558 }
559
560 #[inline]
562 #[must_use]
563 pub fn transpose(&self) -> Self {
564 unsafe {
565 let tmp0 = _mm_shuffle_ps(self.x_axis.0, self.y_axis.0, 0b01_00_01_00);
566 let tmp1 = _mm_shuffle_ps(self.x_axis.0, self.y_axis.0, 0b11_10_11_10);
567
568 Self {
569 x_axis: Vec3A(_mm_shuffle_ps(tmp0, self.z_axis.0, 0b00_00_10_00)),
570 y_axis: Vec3A(_mm_shuffle_ps(tmp0, self.z_axis.0, 0b01_01_11_01)),
571 z_axis: Vec3A(_mm_shuffle_ps(tmp1, self.z_axis.0, 0b10_10_10_00)),
572 }
573 }
574 }
575
576 #[inline]
578 #[must_use]
579 pub fn diagonal(&self) -> Vec3A {
580 Vec3A::new(self.x_axis.x, self.y_axis.y, self.z_axis.z)
581 }
582
583 #[inline]
585 #[must_use]
586 pub fn determinant(&self) -> f32 {
587 self.z_axis.dot(self.x_axis.cross(self.y_axis))
588 }
589
590 #[inline(always)]
602 #[must_use]
603 fn inverse_checked<const CHECKED: bool>(&self) -> (Self, bool) {
604 let tmp0 = self.y_axis.cross(self.z_axis);
605 let tmp1 = self.z_axis.cross(self.x_axis);
606 let tmp2 = self.x_axis.cross(self.y_axis);
607 let det = self.z_axis.dot(tmp2);
608 if CHECKED {
609 if det == 0.0 {
610 return (Self::ZERO, false);
611 }
612 } else {
613 glam_assert!(det != 0.0);
614 }
615 let inv_det = Vec3A::splat(det.recip());
616 (
617 Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose(),
618 true,
619 )
620 }
621
622 #[inline]
630 #[must_use]
631 pub fn inverse(&self) -> Self {
632 self.inverse_checked::<false>().0
633 }
634
635 #[inline]
637 #[must_use]
638 pub fn try_inverse(&self) -> Option<Self> {
639 let (m, is_valid) = self.inverse_checked::<true>();
640 if is_valid {
641 Some(m)
642 } else {
643 None
644 }
645 }
646
647 #[inline]
649 #[must_use]
650 pub fn inverse_or_zero(&self) -> Self {
651 self.inverse_checked::<true>().0
652 }
653
654 #[inline]
664 #[must_use]
665 pub fn transform_point2(&self, rhs: Vec2) -> Vec2 {
666 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
667 Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
668 }
669
670 #[inline]
680 #[must_use]
681 pub fn transform_vector2(&self, rhs: Vec2) -> Vec2 {
682 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
683 Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
684 }
685
686 #[inline]
694 #[must_use]
695 pub fn look_to_lh(dir: Vec3, up: Vec3) -> Self {
696 Self::look_to_rh(-dir, up)
697 }
698
699 #[inline]
707 #[must_use]
708 pub fn look_to_rh(dir: Vec3, up: Vec3) -> Self {
709 glam_assert!(dir.is_normalized());
710 glam_assert!(up.is_normalized());
711 let f = dir;
712 let s = f.cross(up).normalize();
713 let u = s.cross(f);
714
715 Self::from_cols(
716 Vec3A::new(s.x, u.x, -f.x),
717 Vec3A::new(s.y, u.y, -f.y),
718 Vec3A::new(s.z, u.z, -f.z),
719 )
720 }
721
722 #[inline]
731 #[must_use]
732 pub fn look_at_lh(eye: Vec3, center: Vec3, up: Vec3) -> Self {
733 Self::look_to_lh(center.sub(eye).normalize(), up)
734 }
735
736 #[inline]
745 pub fn look_at_rh(eye: Vec3, center: Vec3, up: Vec3) -> Self {
746 Self::look_to_rh(center.sub(eye).normalize(), up)
747 }
748
749 #[inline]
751 #[must_use]
752 pub fn mul_vec3(&self, rhs: Vec3) -> Vec3 {
753 self.mul_vec3a(rhs.into()).into()
754 }
755
756 #[inline]
758 #[must_use]
759 pub fn mul_vec3a(&self, rhs: Vec3A) -> Vec3A {
760 let mut res = self.x_axis.mul(rhs.xxx());
761 res = res.add(self.y_axis.mul(rhs.yyy()));
762 res = res.add(self.z_axis.mul(rhs.zzz()));
763 res
764 }
765
766 #[inline]
768 #[must_use]
769 pub fn mul_transpose_vec3(&self, rhs: Vec3) -> Vec3 {
770 self.mul_transpose_vec3a(rhs.into()).into()
771 }
772
773 #[inline]
775 #[must_use]
776 pub fn mul_transpose_vec3a(&self, rhs: Vec3A) -> Vec3A {
777 Vec3A::new(
778 self.x_axis.dot(rhs),
779 self.y_axis.dot(rhs),
780 self.z_axis.dot(rhs),
781 )
782 }
783
784 #[inline]
786 #[must_use]
787 pub fn mul_mat3(&self, rhs: &Self) -> Self {
788 self.mul(rhs)
789 }
790
791 #[inline]
793 #[must_use]
794 pub fn add_mat3(&self, rhs: &Self) -> Self {
795 self.add(rhs)
796 }
797
798 #[inline]
800 #[must_use]
801 pub fn sub_mat3(&self, rhs: &Self) -> Self {
802 self.sub(rhs)
803 }
804
805 #[inline]
807 #[must_use]
808 pub fn mul_scalar(&self, rhs: f32) -> Self {
809 Self::from_cols(
810 self.x_axis.mul(rhs),
811 self.y_axis.mul(rhs),
812 self.z_axis.mul(rhs),
813 )
814 }
815
816 #[inline]
820 #[must_use]
821 pub fn mul_diagonal_scale(&self, scale: Vec3) -> Self {
822 Self::from_cols(
823 self.x_axis * scale.x,
824 self.y_axis * scale.y,
825 self.z_axis * scale.z,
826 )
827 }
828
829 #[inline]
831 #[must_use]
832 pub fn div_scalar(&self, rhs: f32) -> Self {
833 let rhs = Vec3A::splat(rhs);
834 Self::from_cols(
835 self.x_axis.div(rhs),
836 self.y_axis.div(rhs),
837 self.z_axis.div(rhs),
838 )
839 }
840
841 #[inline]
851 #[must_use]
852 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
853 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
854 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
855 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
856 }
857
858 #[inline]
860 #[must_use]
861 pub fn abs(&self) -> Self {
862 Self::from_cols(self.x_axis.abs(), self.y_axis.abs(), self.z_axis.abs())
863 }
864
865 #[inline]
866 pub fn as_dmat3(&self) -> DMat3 {
867 DMat3::from_cols(
868 self.x_axis.as_dvec3(),
869 self.y_axis.as_dvec3(),
870 self.z_axis.as_dvec3(),
871 )
872 }
873}
874
875impl Default for Mat3A {
876 #[inline]
877 fn default() -> Self {
878 Self::IDENTITY
879 }
880}
881
882impl Add for Mat3A {
883 type Output = Self;
884 #[inline]
885 fn add(self, rhs: Self) -> Self {
886 Self::from_cols(
887 self.x_axis.add(rhs.x_axis),
888 self.y_axis.add(rhs.y_axis),
889 self.z_axis.add(rhs.z_axis),
890 )
891 }
892}
893
894impl Add<&Self> for Mat3A {
895 type Output = Self;
896 #[inline]
897 fn add(self, rhs: &Self) -> Self {
898 self.add(*rhs)
899 }
900}
901
902impl Add<&Mat3A> for &Mat3A {
903 type Output = Mat3A;
904 #[inline]
905 fn add(self, rhs: &Mat3A) -> Mat3A {
906 (*self).add(*rhs)
907 }
908}
909
910impl Add<Mat3A> for &Mat3A {
911 type Output = Mat3A;
912 #[inline]
913 fn add(self, rhs: Mat3A) -> Mat3A {
914 (*self).add(rhs)
915 }
916}
917
918impl AddAssign for Mat3A {
919 #[inline]
920 fn add_assign(&mut self, rhs: Self) {
921 *self = self.add(rhs);
922 }
923}
924
925impl AddAssign<&Self> for Mat3A {
926 #[inline]
927 fn add_assign(&mut self, rhs: &Self) {
928 self.add_assign(*rhs);
929 }
930}
931
932impl Sub for Mat3A {
933 type Output = Self;
934 #[inline]
935 fn sub(self, rhs: Self) -> Self {
936 Self::from_cols(
937 self.x_axis.sub(rhs.x_axis),
938 self.y_axis.sub(rhs.y_axis),
939 self.z_axis.sub(rhs.z_axis),
940 )
941 }
942}
943
944impl Sub<&Self> for Mat3A {
945 type Output = Self;
946 #[inline]
947 fn sub(self, rhs: &Self) -> Self {
948 self.sub(*rhs)
949 }
950}
951
952impl Sub<&Mat3A> for &Mat3A {
953 type Output = Mat3A;
954 #[inline]
955 fn sub(self, rhs: &Mat3A) -> Mat3A {
956 (*self).sub(*rhs)
957 }
958}
959
960impl Sub<Mat3A> for &Mat3A {
961 type Output = Mat3A;
962 #[inline]
963 fn sub(self, rhs: Mat3A) -> Mat3A {
964 (*self).sub(rhs)
965 }
966}
967
968impl SubAssign for Mat3A {
969 #[inline]
970 fn sub_assign(&mut self, rhs: Self) {
971 *self = self.sub(rhs);
972 }
973}
974
975impl SubAssign<&Self> for Mat3A {
976 #[inline]
977 fn sub_assign(&mut self, rhs: &Self) {
978 self.sub_assign(*rhs);
979 }
980}
981
982impl Neg for Mat3A {
983 type Output = Self;
984 #[inline]
985 fn neg(self) -> Self::Output {
986 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
987 }
988}
989
990impl Neg for &Mat3A {
991 type Output = Mat3A;
992 #[inline]
993 fn neg(self) -> Mat3A {
994 (*self).neg()
995 }
996}
997
998impl Mul for Mat3A {
999 type Output = Self;
1000 #[inline]
1001 fn mul(self, rhs: Self) -> Self {
1002 Self::from_cols(
1003 self.mul(rhs.x_axis),
1004 self.mul(rhs.y_axis),
1005 self.mul(rhs.z_axis),
1006 )
1007 }
1008}
1009
1010impl Mul<&Self> for Mat3A {
1011 type Output = Self;
1012 #[inline]
1013 fn mul(self, rhs: &Self) -> Self {
1014 self.mul(*rhs)
1015 }
1016}
1017
1018impl Mul<&Mat3A> for &Mat3A {
1019 type Output = Mat3A;
1020 #[inline]
1021 fn mul(self, rhs: &Mat3A) -> Mat3A {
1022 (*self).mul(*rhs)
1023 }
1024}
1025
1026impl Mul<Mat3A> for &Mat3A {
1027 type Output = Mat3A;
1028 #[inline]
1029 fn mul(self, rhs: Mat3A) -> Mat3A {
1030 (*self).mul(rhs)
1031 }
1032}
1033
1034impl MulAssign for Mat3A {
1035 #[inline]
1036 fn mul_assign(&mut self, rhs: Self) {
1037 *self = self.mul(rhs);
1038 }
1039}
1040
1041impl MulAssign<&Self> for Mat3A {
1042 #[inline]
1043 fn mul_assign(&mut self, rhs: &Self) {
1044 self.mul_assign(*rhs);
1045 }
1046}
1047
1048impl Mul<Vec3A> for Mat3A {
1049 type Output = Vec3A;
1050 #[inline]
1051 fn mul(self, rhs: Vec3A) -> Self::Output {
1052 self.mul_vec3a(rhs)
1053 }
1054}
1055
1056impl Mul<&Vec3A> for Mat3A {
1057 type Output = Vec3A;
1058 #[inline]
1059 fn mul(self, rhs: &Vec3A) -> Vec3A {
1060 self.mul(*rhs)
1061 }
1062}
1063
1064impl Mul<&Vec3A> for &Mat3A {
1065 type Output = Vec3A;
1066 #[inline]
1067 fn mul(self, rhs: &Vec3A) -> Vec3A {
1068 (*self).mul(*rhs)
1069 }
1070}
1071
1072impl Mul<Vec3A> for &Mat3A {
1073 type Output = Vec3A;
1074 #[inline]
1075 fn mul(self, rhs: Vec3A) -> Vec3A {
1076 (*self).mul(rhs)
1077 }
1078}
1079
1080impl Mul<Mat3A> for f32 {
1081 type Output = Mat3A;
1082 #[inline]
1083 fn mul(self, rhs: Mat3A) -> Self::Output {
1084 rhs.mul_scalar(self)
1085 }
1086}
1087
1088impl Mul<&Mat3A> for f32 {
1089 type Output = Mat3A;
1090 #[inline]
1091 fn mul(self, rhs: &Mat3A) -> Mat3A {
1092 self.mul(*rhs)
1093 }
1094}
1095
1096impl Mul<&Mat3A> for &f32 {
1097 type Output = Mat3A;
1098 #[inline]
1099 fn mul(self, rhs: &Mat3A) -> Mat3A {
1100 (*self).mul(*rhs)
1101 }
1102}
1103
1104impl Mul<Mat3A> for &f32 {
1105 type Output = Mat3A;
1106 #[inline]
1107 fn mul(self, rhs: Mat3A) -> Mat3A {
1108 (*self).mul(rhs)
1109 }
1110}
1111
1112impl Mul<f32> for Mat3A {
1113 type Output = Self;
1114 #[inline]
1115 fn mul(self, rhs: f32) -> Self {
1116 self.mul_scalar(rhs)
1117 }
1118}
1119
1120impl Mul<&f32> for Mat3A {
1121 type Output = Self;
1122 #[inline]
1123 fn mul(self, rhs: &f32) -> Self {
1124 self.mul(*rhs)
1125 }
1126}
1127
1128impl Mul<&f32> for &Mat3A {
1129 type Output = Mat3A;
1130 #[inline]
1131 fn mul(self, rhs: &f32) -> Mat3A {
1132 (*self).mul(*rhs)
1133 }
1134}
1135
1136impl Mul<f32> for &Mat3A {
1137 type Output = Mat3A;
1138 #[inline]
1139 fn mul(self, rhs: f32) -> Mat3A {
1140 (*self).mul(rhs)
1141 }
1142}
1143
1144impl MulAssign<f32> for Mat3A {
1145 #[inline]
1146 fn mul_assign(&mut self, rhs: f32) {
1147 *self = self.mul(rhs);
1148 }
1149}
1150
1151impl MulAssign<&f32> for Mat3A {
1152 #[inline]
1153 fn mul_assign(&mut self, rhs: &f32) {
1154 self.mul_assign(*rhs);
1155 }
1156}
1157
1158impl Div<Mat3A> for f32 {
1159 type Output = Mat3A;
1160 #[inline]
1161 fn div(self, rhs: Mat3A) -> Self::Output {
1162 rhs.div_scalar(self)
1163 }
1164}
1165
1166impl Div<&Mat3A> for f32 {
1167 type Output = Mat3A;
1168 #[inline]
1169 fn div(self, rhs: &Mat3A) -> Mat3A {
1170 self.div(*rhs)
1171 }
1172}
1173
1174impl Div<&Mat3A> for &f32 {
1175 type Output = Mat3A;
1176 #[inline]
1177 fn div(self, rhs: &Mat3A) -> Mat3A {
1178 (*self).div(*rhs)
1179 }
1180}
1181
1182impl Div<Mat3A> for &f32 {
1183 type Output = Mat3A;
1184 #[inline]
1185 fn div(self, rhs: Mat3A) -> Mat3A {
1186 (*self).div(rhs)
1187 }
1188}
1189
1190impl Div<f32> for Mat3A {
1191 type Output = Self;
1192 #[inline]
1193 fn div(self, rhs: f32) -> Self {
1194 self.div_scalar(rhs)
1195 }
1196}
1197
1198impl Div<&f32> for Mat3A {
1199 type Output = Self;
1200 #[inline]
1201 fn div(self, rhs: &f32) -> Self {
1202 self.div(*rhs)
1203 }
1204}
1205
1206impl Div<&f32> for &Mat3A {
1207 type Output = Mat3A;
1208 #[inline]
1209 fn div(self, rhs: &f32) -> Mat3A {
1210 (*self).div(*rhs)
1211 }
1212}
1213
1214impl Div<f32> for &Mat3A {
1215 type Output = Mat3A;
1216 #[inline]
1217 fn div(self, rhs: f32) -> Mat3A {
1218 (*self).div(rhs)
1219 }
1220}
1221
1222impl DivAssign<f32> for Mat3A {
1223 #[inline]
1224 fn div_assign(&mut self, rhs: f32) {
1225 *self = self.div(rhs);
1226 }
1227}
1228
1229impl DivAssign<&f32> for Mat3A {
1230 #[inline]
1231 fn div_assign(&mut self, rhs: &f32) {
1232 self.div_assign(*rhs);
1233 }
1234}
1235
1236impl Mul<Vec3> for Mat3A {
1237 type Output = Vec3;
1238 #[inline]
1239 fn mul(self, rhs: Vec3) -> Vec3 {
1240 self.mul_vec3a(rhs.into()).into()
1241 }
1242}
1243
1244impl Mul<&Vec3> for Mat3A {
1245 type Output = Vec3;
1246 #[inline]
1247 fn mul(self, rhs: &Vec3) -> Vec3 {
1248 self.mul(*rhs)
1249 }
1250}
1251
1252impl Mul<&Vec3> for &Mat3A {
1253 type Output = Vec3;
1254 #[inline]
1255 fn mul(self, rhs: &Vec3) -> Vec3 {
1256 (*self).mul(*rhs)
1257 }
1258}
1259
1260impl Mul<Vec3> for &Mat3A {
1261 type Output = Vec3;
1262 #[inline]
1263 fn mul(self, rhs: Vec3) -> Vec3 {
1264 (*self).mul(rhs)
1265 }
1266}
1267
1268impl From<Mat3> for Mat3A {
1269 #[inline]
1270 fn from(m: Mat3) -> Self {
1271 Self {
1272 x_axis: m.x_axis.into(),
1273 y_axis: m.y_axis.into(),
1274 z_axis: m.z_axis.into(),
1275 }
1276 }
1277}
1278
1279impl Sum<Self> for Mat3A {
1280 fn sum<I>(iter: I) -> Self
1281 where
1282 I: Iterator<Item = Self>,
1283 {
1284 iter.fold(Self::ZERO, Self::add)
1285 }
1286}
1287
1288impl<'a> Sum<&'a Self> for Mat3A {
1289 fn sum<I>(iter: I) -> Self
1290 where
1291 I: Iterator<Item = &'a Self>,
1292 {
1293 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1294 }
1295}
1296
1297impl Product for Mat3A {
1298 fn product<I>(iter: I) -> Self
1299 where
1300 I: Iterator<Item = Self>,
1301 {
1302 iter.fold(Self::IDENTITY, Self::mul)
1303 }
1304}
1305
1306impl<'a> Product<&'a Self> for Mat3A {
1307 fn product<I>(iter: I) -> Self
1308 where
1309 I: Iterator<Item = &'a Self>,
1310 {
1311 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
1312 }
1313}
1314
1315impl PartialEq for Mat3A {
1316 #[inline]
1317 fn eq(&self, rhs: &Self) -> bool {
1318 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
1319 }
1320}
1321
1322impl fmt::Debug for Mat3A {
1323 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1324 fmt.debug_struct(stringify!(Mat3A))
1325 .field("x_axis", &self.x_axis)
1326 .field("y_axis", &self.y_axis)
1327 .field("z_axis", &self.z_axis)
1328 .finish()
1329 }
1330}
1331
1332impl fmt::Display for Mat3A {
1333 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1334 if let Some(p) = f.precision() {
1335 write!(
1336 f,
1337 "[{:.*}, {:.*}, {:.*}]",
1338 p, self.x_axis, p, self.y_axis, p, self.z_axis
1339 )
1340 } else {
1341 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
1342 }
1343 }
1344}