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#[inline(always)]
20#[must_use]
21pub const fn mat3a(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Mat3A {
22 Mat3A::from_cols(x_axis, y_axis, z_axis)
23}
24
25#[derive(Clone, Copy)]
50#[repr(C)]
51pub struct Mat3A {
52 pub x_axis: Vec3A,
53 pub y_axis: Vec3A,
54 pub z_axis: Vec3A,
55}
56
57impl Mat3A {
58 pub const ZERO: Self = Self::from_cols(Vec3A::ZERO, Vec3A::ZERO, Vec3A::ZERO);
60
61 pub const IDENTITY: Self = Self::from_cols(Vec3A::X, Vec3A::Y, Vec3A::Z);
63
64 pub const NAN: Self = Self::from_cols(Vec3A::NAN, Vec3A::NAN, Vec3A::NAN);
66
67 #[allow(clippy::too_many_arguments)]
68 #[inline(always)]
69 #[must_use]
70 const fn new(
71 m00: f32,
72 m01: f32,
73 m02: f32,
74 m10: f32,
75 m11: f32,
76 m12: f32,
77 m20: f32,
78 m21: f32,
79 m22: f32,
80 ) -> Self {
81 Self {
82 x_axis: Vec3A::new(m00, m01, m02),
83 y_axis: Vec3A::new(m10, m11, m12),
84 z_axis: Vec3A::new(m20, m21, m22),
85 }
86 }
87
88 #[inline(always)]
90 #[must_use]
91 pub const fn from_cols(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Self {
92 Self {
93 x_axis,
94 y_axis,
95 z_axis,
96 }
97 }
98
99 #[inline]
103 #[must_use]
104 pub const fn from_cols_array(m: &[f32; 9]) -> Self {
105 Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
106 }
107
108 #[inline]
111 #[must_use]
112 pub const fn to_cols_array(&self) -> [f32; 9] {
113 let [x_axis_x, x_axis_y, x_axis_z] = self.x_axis.to_array();
114 let [y_axis_x, y_axis_y, y_axis_z] = self.y_axis.to_array();
115 let [z_axis_x, z_axis_y, z_axis_z] = self.z_axis.to_array();
116
117 [
118 x_axis_x, x_axis_y, x_axis_z, y_axis_x, y_axis_y, y_axis_z, z_axis_x, z_axis_y,
119 z_axis_z,
120 ]
121 }
122
123 #[inline]
127 #[must_use]
128 pub const fn from_cols_array_2d(m: &[[f32; 3]; 3]) -> Self {
129 Self::from_cols(
130 Vec3A::from_array(m[0]),
131 Vec3A::from_array(m[1]),
132 Vec3A::from_array(m[2]),
133 )
134 }
135
136 #[inline]
139 #[must_use]
140 pub const fn to_cols_array_2d(&self) -> [[f32; 3]; 3] {
141 [
142 self.x_axis.to_array(),
143 self.y_axis.to_array(),
144 self.z_axis.to_array(),
145 ]
146 }
147
148 #[doc(alias = "scale")]
150 #[inline]
151 #[must_use]
152 pub const fn from_diagonal(diagonal: Vec3) -> Self {
153 Self::new(
154 diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
155 )
156 }
157
158 #[inline]
160 #[must_use]
161 pub fn from_mat4(m: Mat4) -> Self {
162 Self::from_cols(
163 Vec3A::from_vec4(m.x_axis),
164 Vec3A::from_vec4(m.y_axis),
165 Vec3A::from_vec4(m.z_axis),
166 )
167 }
168
169 #[inline]
176 #[must_use]
177 pub fn from_mat4_minor(m: Mat4, i: usize, j: usize) -> Self {
178 match (i, j) {
179 (0, 0) => Self::from_cols(
180 Vec3A::from_vec4(m.y_axis.yzww()),
181 Vec3A::from_vec4(m.z_axis.yzww()),
182 Vec3A::from_vec4(m.w_axis.yzww()),
183 ),
184 (0, 1) => Self::from_cols(
185 Vec3A::from_vec4(m.y_axis.xzww()),
186 Vec3A::from_vec4(m.z_axis.xzww()),
187 Vec3A::from_vec4(m.w_axis.xzww()),
188 ),
189 (0, 2) => Self::from_cols(
190 Vec3A::from_vec4(m.y_axis.xyww()),
191 Vec3A::from_vec4(m.z_axis.xyww()),
192 Vec3A::from_vec4(m.w_axis.xyww()),
193 ),
194 (0, 3) => Self::from_cols(
195 Vec3A::from_vec4(m.y_axis.xyzw()),
196 Vec3A::from_vec4(m.z_axis.xyzw()),
197 Vec3A::from_vec4(m.w_axis.xyzw()),
198 ),
199 (1, 0) => Self::from_cols(
200 Vec3A::from_vec4(m.x_axis.yzww()),
201 Vec3A::from_vec4(m.z_axis.yzww()),
202 Vec3A::from_vec4(m.w_axis.yzww()),
203 ),
204 (1, 1) => Self::from_cols(
205 Vec3A::from_vec4(m.x_axis.xzww()),
206 Vec3A::from_vec4(m.z_axis.xzww()),
207 Vec3A::from_vec4(m.w_axis.xzww()),
208 ),
209 (1, 2) => Self::from_cols(
210 Vec3A::from_vec4(m.x_axis.xyww()),
211 Vec3A::from_vec4(m.z_axis.xyww()),
212 Vec3A::from_vec4(m.w_axis.xyww()),
213 ),
214 (1, 3) => Self::from_cols(
215 Vec3A::from_vec4(m.x_axis.xyzw()),
216 Vec3A::from_vec4(m.z_axis.xyzw()),
217 Vec3A::from_vec4(m.w_axis.xyzw()),
218 ),
219 (2, 0) => Self::from_cols(
220 Vec3A::from_vec4(m.x_axis.yzww()),
221 Vec3A::from_vec4(m.y_axis.yzww()),
222 Vec3A::from_vec4(m.w_axis.yzww()),
223 ),
224 (2, 1) => Self::from_cols(
225 Vec3A::from_vec4(m.x_axis.xzww()),
226 Vec3A::from_vec4(m.y_axis.xzww()),
227 Vec3A::from_vec4(m.w_axis.xzww()),
228 ),
229 (2, 2) => Self::from_cols(
230 Vec3A::from_vec4(m.x_axis.xyww()),
231 Vec3A::from_vec4(m.y_axis.xyww()),
232 Vec3A::from_vec4(m.w_axis.xyww()),
233 ),
234 (2, 3) => Self::from_cols(
235 Vec3A::from_vec4(m.x_axis.xyzw()),
236 Vec3A::from_vec4(m.y_axis.xyzw()),
237 Vec3A::from_vec4(m.w_axis.xyzw()),
238 ),
239 (3, 0) => Self::from_cols(
240 Vec3A::from_vec4(m.x_axis.yzww()),
241 Vec3A::from_vec4(m.y_axis.yzww()),
242 Vec3A::from_vec4(m.z_axis.yzww()),
243 ),
244 (3, 1) => Self::from_cols(
245 Vec3A::from_vec4(m.x_axis.xzww()),
246 Vec3A::from_vec4(m.y_axis.xzww()),
247 Vec3A::from_vec4(m.z_axis.xzww()),
248 ),
249 (3, 2) => Self::from_cols(
250 Vec3A::from_vec4(m.x_axis.xyww()),
251 Vec3A::from_vec4(m.y_axis.xyww()),
252 Vec3A::from_vec4(m.z_axis.xyww()),
253 ),
254 (3, 3) => Self::from_cols(
255 Vec3A::from_vec4(m.x_axis.xyzw()),
256 Vec3A::from_vec4(m.y_axis.xyzw()),
257 Vec3A::from_vec4(m.z_axis.xyzw()),
258 ),
259 _ => panic!("index out of bounds"),
260 }
261 }
262
263 #[inline]
269 #[must_use]
270 pub fn from_quat(rotation: Quat) -> Self {
271 glam_assert!(rotation.is_normalized());
272
273 let x2 = rotation.x + rotation.x;
274 let y2 = rotation.y + rotation.y;
275 let z2 = rotation.z + rotation.z;
276 let xx = rotation.x * x2;
277 let xy = rotation.x * y2;
278 let xz = rotation.x * z2;
279 let yy = rotation.y * y2;
280 let yz = rotation.y * z2;
281 let zz = rotation.z * z2;
282 let wx = rotation.w * x2;
283 let wy = rotation.w * y2;
284 let wz = rotation.w * z2;
285
286 Self::from_cols(
287 Vec3A::new(1.0 - (yy + zz), xy + wz, xz - wy),
288 Vec3A::new(xy - wz, 1.0 - (xx + zz), yz + wx),
289 Vec3A::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
290 )
291 }
292
293 #[inline]
300 #[must_use]
301 pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self {
302 glam_assert!(axis.is_normalized());
303
304 let (sin, cos) = math::sin_cos(angle);
305 let (xsin, ysin, zsin) = axis.mul(sin).into();
306 let (x, y, z) = axis.into();
307 let (x2, y2, z2) = axis.mul(axis).into();
308 let omc = 1.0 - cos;
309 let xyomc = x * y * omc;
310 let xzomc = x * z * omc;
311 let yzomc = y * z * omc;
312 Self::from_cols(
313 Vec3A::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
314 Vec3A::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
315 Vec3A::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
316 )
317 }
318
319 #[inline]
322 #[must_use]
323 pub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Self {
324 Self::from_euler_angles(order, a, b, c)
325 }
326
327 #[inline]
336 #[must_use]
337 pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
338 glam_assert!(
339 self.x_axis.is_normalized()
340 && self.y_axis.is_normalized()
341 && self.z_axis.is_normalized()
342 );
343 self.to_euler_angles(order)
344 }
345
346 #[inline]
348 #[must_use]
349 pub fn from_rotation_x(angle: f32) -> Self {
350 let (sina, cosa) = math::sin_cos(angle);
351 Self::from_cols(
352 Vec3A::X,
353 Vec3A::new(0.0, cosa, sina),
354 Vec3A::new(0.0, -sina, cosa),
355 )
356 }
357
358 #[inline]
360 #[must_use]
361 pub fn from_rotation_y(angle: f32) -> Self {
362 let (sina, cosa) = math::sin_cos(angle);
363 Self::from_cols(
364 Vec3A::new(cosa, 0.0, -sina),
365 Vec3A::Y,
366 Vec3A::new(sina, 0.0, cosa),
367 )
368 }
369
370 #[inline]
372 #[must_use]
373 pub fn from_rotation_z(angle: f32) -> Self {
374 let (sina, cosa) = math::sin_cos(angle);
375 Self::from_cols(
376 Vec3A::new(cosa, sina, 0.0),
377 Vec3A::new(-sina, cosa, 0.0),
378 Vec3A::Z,
379 )
380 }
381
382 #[inline]
387 #[must_use]
388 pub fn from_translation(translation: Vec2) -> Self {
389 Self::from_cols(
390 Vec3A::X,
391 Vec3A::Y,
392 Vec3A::new(translation.x, translation.y, 1.0),
393 )
394 }
395
396 #[inline]
402 #[must_use]
403 pub fn from_angle(angle: f32) -> Self {
404 let (sin, cos) = math::sin_cos(angle);
405 Self::from_cols(
406 Vec3A::new(cos, sin, 0.0),
407 Vec3A::new(-sin, cos, 0.0),
408 Vec3A::Z,
409 )
410 }
411
412 #[inline]
418 #[must_use]
419 pub fn from_scale_angle_translation(scale: Vec2, angle: f32, translation: Vec2) -> Self {
420 let (sin, cos) = math::sin_cos(angle);
421 Self::from_cols(
422 Vec3A::new(cos * scale.x, sin * scale.x, 0.0),
423 Vec3A::new(-sin * scale.y, cos * scale.y, 0.0),
424 Vec3A::new(translation.x, translation.y, 1.0),
425 )
426 }
427
428 #[inline]
437 #[must_use]
438 pub fn from_scale(scale: Vec2) -> Self {
439 glam_assert!(scale.cmpne(Vec2::ZERO).any());
441
442 Self::from_cols(
443 Vec3A::new(scale.x, 0.0, 0.0),
444 Vec3A::new(0.0, scale.y, 0.0),
445 Vec3A::Z,
446 )
447 }
448
449 #[inline]
454 pub fn from_mat2(m: Mat2) -> Self {
455 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), Vec3A::Z)
456 }
457
458 #[inline]
464 #[must_use]
465 pub const fn from_cols_slice(slice: &[f32]) -> Self {
466 Self::new(
467 slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
468 slice[8],
469 )
470 }
471
472 #[inline]
478 pub fn write_cols_to_slice(self, slice: &mut [f32]) {
479 slice[0] = self.x_axis.x;
480 slice[1] = self.x_axis.y;
481 slice[2] = self.x_axis.z;
482 slice[3] = self.y_axis.x;
483 slice[4] = self.y_axis.y;
484 slice[5] = self.y_axis.z;
485 slice[6] = self.z_axis.x;
486 slice[7] = self.z_axis.y;
487 slice[8] = self.z_axis.z;
488 }
489
490 #[inline]
496 #[must_use]
497 pub fn col(&self, index: usize) -> Vec3A {
498 match index {
499 0 => self.x_axis,
500 1 => self.y_axis,
501 2 => self.z_axis,
502 _ => panic!("index out of bounds"),
503 }
504 }
505
506 #[inline]
512 pub fn col_mut(&mut self, index: usize) -> &mut Vec3A {
513 match index {
514 0 => &mut self.x_axis,
515 1 => &mut self.y_axis,
516 2 => &mut self.z_axis,
517 _ => panic!("index out of bounds"),
518 }
519 }
520
521 #[inline]
527 #[must_use]
528 pub fn row(&self, index: usize) -> Vec3A {
529 match index {
530 0 => Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
531 1 => Vec3A::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
532 2 => Vec3A::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
533 _ => panic!("index out of bounds"),
534 }
535 }
536
537 #[inline]
540 #[must_use]
541 pub fn is_finite(&self) -> bool {
542 self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
543 }
544
545 #[inline]
547 #[must_use]
548 pub fn is_nan(&self) -> bool {
549 self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
550 }
551
552 #[inline]
554 #[must_use]
555 pub fn transpose(&self) -> Self {
556 unsafe {
557 let tmp0 = _mm_shuffle_ps(self.x_axis.0, self.y_axis.0, 0b01_00_01_00);
558 let tmp1 = _mm_shuffle_ps(self.x_axis.0, self.y_axis.0, 0b11_10_11_10);
559
560 Self {
561 x_axis: Vec3A(_mm_shuffle_ps(tmp0, self.z_axis.0, 0b00_00_10_00)),
562 y_axis: Vec3A(_mm_shuffle_ps(tmp0, self.z_axis.0, 0b01_01_11_01)),
563 z_axis: Vec3A(_mm_shuffle_ps(tmp1, self.z_axis.0, 0b10_10_10_00)),
564 }
565 }
566 }
567
568 #[inline]
570 #[must_use]
571 pub fn determinant(&self) -> f32 {
572 self.z_axis.dot(self.x_axis.cross(self.y_axis))
573 }
574
575 #[inline]
583 #[must_use]
584 pub fn inverse(&self) -> Self {
585 let tmp0 = self.y_axis.cross(self.z_axis);
586 let tmp1 = self.z_axis.cross(self.x_axis);
587 let tmp2 = self.x_axis.cross(self.y_axis);
588 let det = self.z_axis.dot(tmp2);
589 glam_assert!(det != 0.0);
590 let inv_det = Vec3A::splat(det.recip());
591 Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose()
592 }
593
594 #[inline]
604 #[must_use]
605 pub fn transform_point2(&self, rhs: Vec2) -> Vec2 {
606 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
607 Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
608 }
609
610 #[inline]
620 #[must_use]
621 pub fn transform_vector2(&self, rhs: Vec2) -> Vec2 {
622 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
623 Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
624 }
625
626 #[inline]
628 #[must_use]
629 pub fn mul_vec3(&self, rhs: Vec3) -> Vec3 {
630 self.mul_vec3a(rhs.into()).into()
631 }
632
633 #[inline]
635 #[must_use]
636 pub fn mul_vec3a(&self, rhs: Vec3A) -> Vec3A {
637 let mut res = self.x_axis.mul(rhs.xxx());
638 res = res.add(self.y_axis.mul(rhs.yyy()));
639 res = res.add(self.z_axis.mul(rhs.zzz()));
640 res
641 }
642
643 #[inline]
645 #[must_use]
646 pub fn mul_mat3(&self, rhs: &Self) -> Self {
647 Self::from_cols(
648 self.mul(rhs.x_axis),
649 self.mul(rhs.y_axis),
650 self.mul(rhs.z_axis),
651 )
652 }
653
654 #[inline]
656 #[must_use]
657 pub fn add_mat3(&self, rhs: &Self) -> Self {
658 Self::from_cols(
659 self.x_axis.add(rhs.x_axis),
660 self.y_axis.add(rhs.y_axis),
661 self.z_axis.add(rhs.z_axis),
662 )
663 }
664
665 #[inline]
667 #[must_use]
668 pub fn sub_mat3(&self, rhs: &Self) -> Self {
669 Self::from_cols(
670 self.x_axis.sub(rhs.x_axis),
671 self.y_axis.sub(rhs.y_axis),
672 self.z_axis.sub(rhs.z_axis),
673 )
674 }
675
676 #[inline]
678 #[must_use]
679 pub fn mul_scalar(&self, rhs: f32) -> Self {
680 Self::from_cols(
681 self.x_axis.mul(rhs),
682 self.y_axis.mul(rhs),
683 self.z_axis.mul(rhs),
684 )
685 }
686
687 #[inline]
689 #[must_use]
690 pub fn div_scalar(&self, rhs: f32) -> Self {
691 let rhs = Vec3A::splat(rhs);
692 Self::from_cols(
693 self.x_axis.div(rhs),
694 self.y_axis.div(rhs),
695 self.z_axis.div(rhs),
696 )
697 }
698
699 #[inline]
709 #[must_use]
710 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
711 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
712 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
713 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
714 }
715
716 #[inline]
718 #[must_use]
719 pub fn abs(&self) -> Self {
720 Self::from_cols(self.x_axis.abs(), self.y_axis.abs(), self.z_axis.abs())
721 }
722
723 #[inline]
724 pub fn as_dmat3(&self) -> DMat3 {
725 DMat3::from_cols(
726 self.x_axis.as_dvec3(),
727 self.y_axis.as_dvec3(),
728 self.z_axis.as_dvec3(),
729 )
730 }
731}
732
733impl Default for Mat3A {
734 #[inline]
735 fn default() -> Self {
736 Self::IDENTITY
737 }
738}
739
740impl Add<Mat3A> for Mat3A {
741 type Output = Self;
742 #[inline]
743 fn add(self, rhs: Self) -> Self::Output {
744 self.add_mat3(&rhs)
745 }
746}
747
748impl AddAssign<Mat3A> for Mat3A {
749 #[inline]
750 fn add_assign(&mut self, rhs: Self) {
751 *self = self.add_mat3(&rhs);
752 }
753}
754
755impl Sub<Mat3A> for Mat3A {
756 type Output = Self;
757 #[inline]
758 fn sub(self, rhs: Self) -> Self::Output {
759 self.sub_mat3(&rhs)
760 }
761}
762
763impl SubAssign<Mat3A> for Mat3A {
764 #[inline]
765 fn sub_assign(&mut self, rhs: Self) {
766 *self = self.sub_mat3(&rhs);
767 }
768}
769
770impl Neg for Mat3A {
771 type Output = Self;
772 #[inline]
773 fn neg(self) -> Self::Output {
774 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
775 }
776}
777
778impl Mul<Mat3A> for Mat3A {
779 type Output = Self;
780 #[inline]
781 fn mul(self, rhs: Self) -> Self::Output {
782 self.mul_mat3(&rhs)
783 }
784}
785
786impl MulAssign<Mat3A> for Mat3A {
787 #[inline]
788 fn mul_assign(&mut self, rhs: Self) {
789 *self = self.mul_mat3(&rhs);
790 }
791}
792
793impl Mul<Vec3A> for Mat3A {
794 type Output = Vec3A;
795 #[inline]
796 fn mul(self, rhs: Vec3A) -> Self::Output {
797 self.mul_vec3a(rhs)
798 }
799}
800
801impl Mul<Mat3A> for f32 {
802 type Output = Mat3A;
803 #[inline]
804 fn mul(self, rhs: Mat3A) -> Self::Output {
805 rhs.mul_scalar(self)
806 }
807}
808
809impl Mul<f32> for Mat3A {
810 type Output = Self;
811 #[inline]
812 fn mul(self, rhs: f32) -> Self::Output {
813 self.mul_scalar(rhs)
814 }
815}
816
817impl MulAssign<f32> for Mat3A {
818 #[inline]
819 fn mul_assign(&mut self, rhs: f32) {
820 *self = self.mul_scalar(rhs);
821 }
822}
823
824impl Div<Mat3A> for f32 {
825 type Output = Mat3A;
826 #[inline]
827 fn div(self, rhs: Mat3A) -> Self::Output {
828 rhs.div_scalar(self)
829 }
830}
831
832impl Div<f32> for Mat3A {
833 type Output = Self;
834 #[inline]
835 fn div(self, rhs: f32) -> Self::Output {
836 self.div_scalar(rhs)
837 }
838}
839
840impl DivAssign<f32> for Mat3A {
841 #[inline]
842 fn div_assign(&mut self, rhs: f32) {
843 *self = self.div_scalar(rhs);
844 }
845}
846
847impl Mul<Vec3> for Mat3A {
848 type Output = Vec3;
849 #[inline]
850 fn mul(self, rhs: Vec3) -> Vec3 {
851 self.mul_vec3a(rhs.into()).into()
852 }
853}
854
855impl From<Mat3> for Mat3A {
856 #[inline]
857 fn from(m: Mat3) -> Self {
858 Self {
859 x_axis: m.x_axis.into(),
860 y_axis: m.y_axis.into(),
861 z_axis: m.z_axis.into(),
862 }
863 }
864}
865
866impl Sum<Self> for Mat3A {
867 fn sum<I>(iter: I) -> Self
868 where
869 I: Iterator<Item = Self>,
870 {
871 iter.fold(Self::ZERO, Self::add)
872 }
873}
874
875impl<'a> Sum<&'a Self> for Mat3A {
876 fn sum<I>(iter: I) -> Self
877 where
878 I: Iterator<Item = &'a Self>,
879 {
880 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
881 }
882}
883
884impl Product for Mat3A {
885 fn product<I>(iter: I) -> Self
886 where
887 I: Iterator<Item = Self>,
888 {
889 iter.fold(Self::IDENTITY, Self::mul)
890 }
891}
892
893impl<'a> Product<&'a Self> for Mat3A {
894 fn product<I>(iter: I) -> Self
895 where
896 I: Iterator<Item = &'a Self>,
897 {
898 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
899 }
900}
901
902impl PartialEq for Mat3A {
903 #[inline]
904 fn eq(&self, rhs: &Self) -> bool {
905 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
906 }
907}
908
909impl fmt::Debug for Mat3A {
910 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
911 fmt.debug_struct(stringify!(Mat3A))
912 .field("x_axis", &self.x_axis)
913 .field("y_axis", &self.y_axis)
914 .field("z_axis", &self.z_axis)
915 .finish()
916 }
917}
918
919impl fmt::Display for Mat3A {
920 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
921 if let Some(p) = f.precision() {
922 write!(
923 f,
924 "[{:.*}, {:.*}, {:.*}]",
925 p, self.x_axis, p, self.y_axis, p, self.z_axis
926 )
927 } else {
928 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
929 }
930 }
931}