1use crate::{
4 euler::{FromEuler, ToEuler},
5 f64::math,
6 swizzles::*,
7 DMat2, DMat4, DQuat, DVec2, DVec3, EulerRot, Mat3,
8};
9use core::fmt;
10use core::iter::{Product, Sum};
11use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
12
13#[cfg(feature = "zerocopy")]
14use zerocopy_derive::*;
15
16#[inline(always)]
18#[must_use]
19pub const fn dmat3(x_axis: DVec3, y_axis: DVec3, z_axis: DVec3) -> DMat3 {
20 DMat3::from_cols(x_axis, y_axis, z_axis)
21}
22
23#[derive(Clone, Copy)]
48#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
49#[cfg_attr(
50 feature = "zerocopy",
51 derive(FromBytes, Immutable, IntoBytes, KnownLayout)
52)]
53#[repr(C)]
54pub struct DMat3 {
55 pub x_axis: DVec3,
56 pub y_axis: DVec3,
57 pub z_axis: DVec3,
58}
59
60impl DMat3 {
61 pub const ZERO: Self = Self::from_cols(DVec3::ZERO, DVec3::ZERO, DVec3::ZERO);
63
64 pub const IDENTITY: Self = Self::from_cols(DVec3::X, DVec3::Y, DVec3::Z);
66
67 pub const NAN: Self = Self::from_cols(DVec3::NAN, DVec3::NAN, DVec3::NAN);
69
70 #[allow(clippy::too_many_arguments)]
71 #[inline(always)]
72 #[must_use]
73 const fn new(
74 m00: f64,
75 m01: f64,
76 m02: f64,
77 m10: f64,
78 m11: f64,
79 m12: f64,
80 m20: f64,
81 m21: f64,
82 m22: f64,
83 ) -> Self {
84 Self {
85 x_axis: DVec3::new(m00, m01, m02),
86 y_axis: DVec3::new(m10, m11, m12),
87 z_axis: DVec3::new(m20, m21, m22),
88 }
89 }
90
91 #[inline(always)]
93 #[must_use]
94 pub const fn from_cols(x_axis: DVec3, y_axis: DVec3, z_axis: DVec3) -> Self {
95 Self {
96 x_axis,
97 y_axis,
98 z_axis,
99 }
100 }
101
102 #[inline]
106 #[must_use]
107 pub const fn from_cols_array(m: &[f64; 9]) -> Self {
108 Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
109 }
110
111 #[inline]
114 #[must_use]
115 pub const fn to_cols_array(&self) -> [f64; 9] {
116 [
117 self.x_axis.x,
118 self.x_axis.y,
119 self.x_axis.z,
120 self.y_axis.x,
121 self.y_axis.y,
122 self.y_axis.z,
123 self.z_axis.x,
124 self.z_axis.y,
125 self.z_axis.z,
126 ]
127 }
128
129 #[inline]
133 #[must_use]
134 pub const fn from_cols_array_2d(m: &[[f64; 3]; 3]) -> Self {
135 Self::from_cols(
136 DVec3::from_array(m[0]),
137 DVec3::from_array(m[1]),
138 DVec3::from_array(m[2]),
139 )
140 }
141
142 #[inline]
145 #[must_use]
146 pub const fn to_cols_array_2d(&self) -> [[f64; 3]; 3] {
147 [
148 self.x_axis.to_array(),
149 self.y_axis.to_array(),
150 self.z_axis.to_array(),
151 ]
152 }
153
154 #[doc(alias = "scale")]
156 #[inline]
157 #[must_use]
158 pub const fn from_diagonal(diagonal: DVec3) -> Self {
159 Self::new(
160 diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
161 )
162 }
163
164 #[inline]
166 #[must_use]
167 pub fn from_mat4(m: DMat4) -> Self {
168 Self::from_cols(
169 DVec3::from_vec4(m.x_axis),
170 DVec3::from_vec4(m.y_axis),
171 DVec3::from_vec4(m.z_axis),
172 )
173 }
174
175 #[inline]
182 #[must_use]
183 pub fn from_mat4_minor(m: DMat4, i: usize, j: usize) -> Self {
184 match (i, j) {
185 (0, 0) => Self::from_cols(m.y_axis.yzw(), m.z_axis.yzw(), m.w_axis.yzw()),
186 (0, 1) => Self::from_cols(m.y_axis.xzw(), m.z_axis.xzw(), m.w_axis.xzw()),
187 (0, 2) => Self::from_cols(m.y_axis.xyw(), m.z_axis.xyw(), m.w_axis.xyw()),
188 (0, 3) => Self::from_cols(m.y_axis.xyz(), m.z_axis.xyz(), m.w_axis.xyz()),
189 (1, 0) => Self::from_cols(m.x_axis.yzw(), m.z_axis.yzw(), m.w_axis.yzw()),
190 (1, 1) => Self::from_cols(m.x_axis.xzw(), m.z_axis.xzw(), m.w_axis.xzw()),
191 (1, 2) => Self::from_cols(m.x_axis.xyw(), m.z_axis.xyw(), m.w_axis.xyw()),
192 (1, 3) => Self::from_cols(m.x_axis.xyz(), m.z_axis.xyz(), m.w_axis.xyz()),
193 (2, 0) => Self::from_cols(m.x_axis.yzw(), m.y_axis.yzw(), m.w_axis.yzw()),
194 (2, 1) => Self::from_cols(m.x_axis.xzw(), m.y_axis.xzw(), m.w_axis.xzw()),
195 (2, 2) => Self::from_cols(m.x_axis.xyw(), m.y_axis.xyw(), m.w_axis.xyw()),
196 (2, 3) => Self::from_cols(m.x_axis.xyz(), m.y_axis.xyz(), m.w_axis.xyz()),
197 (3, 0) => Self::from_cols(m.x_axis.yzw(), m.y_axis.yzw(), m.z_axis.yzw()),
198 (3, 1) => Self::from_cols(m.x_axis.xzw(), m.y_axis.xzw(), m.z_axis.xzw()),
199 (3, 2) => Self::from_cols(m.x_axis.xyw(), m.y_axis.xyw(), m.z_axis.xyw()),
200 (3, 3) => Self::from_cols(m.x_axis.xyz(), m.y_axis.xyz(), m.z_axis.xyz()),
201 _ => panic!("index out of bounds"),
202 }
203 }
204
205 #[inline]
211 #[must_use]
212 pub fn from_quat(rotation: DQuat) -> Self {
213 glam_assert!(rotation.is_normalized());
214
215 let x2 = rotation.x + rotation.x;
216 let y2 = rotation.y + rotation.y;
217 let z2 = rotation.z + rotation.z;
218 let xx = rotation.x * x2;
219 let xy = rotation.x * y2;
220 let xz = rotation.x * z2;
221 let yy = rotation.y * y2;
222 let yz = rotation.y * z2;
223 let zz = rotation.z * z2;
224 let wx = rotation.w * x2;
225 let wy = rotation.w * y2;
226 let wz = rotation.w * z2;
227
228 Self::from_cols(
229 DVec3::new(1.0 - (yy + zz), xy + wz, xz - wy),
230 DVec3::new(xy - wz, 1.0 - (xx + zz), yz + wx),
231 DVec3::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
232 )
233 }
234
235 #[inline]
242 #[must_use]
243 pub fn from_axis_angle(axis: DVec3, angle: f64) -> Self {
244 glam_assert!(axis.is_normalized());
245
246 let (sin, cos) = math::sin_cos(angle);
247 let (xsin, ysin, zsin) = axis.mul(sin).into();
248 let (x, y, z) = axis.into();
249 let (x2, y2, z2) = axis.mul(axis).into();
250 let omc = 1.0 - cos;
251 let xyomc = x * y * omc;
252 let xzomc = x * z * omc;
253 let yzomc = y * z * omc;
254 Self::from_cols(
255 DVec3::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
256 DVec3::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
257 DVec3::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
258 )
259 }
260
261 #[inline]
264 #[must_use]
265 pub fn from_euler(order: EulerRot, a: f64, b: f64, c: f64) -> Self {
266 Self::from_euler_angles(order, a, b, c)
267 }
268
269 #[inline]
278 #[must_use]
279 pub fn to_euler(&self, order: EulerRot) -> (f64, f64, f64) {
280 glam_assert!(
281 self.x_axis.is_normalized()
282 && self.y_axis.is_normalized()
283 && self.z_axis.is_normalized()
284 );
285 self.to_euler_angles(order)
286 }
287
288 #[inline]
290 #[must_use]
291 pub fn from_rotation_x(angle: f64) -> Self {
292 let (sina, cosa) = math::sin_cos(angle);
293 Self::from_cols(
294 DVec3::X,
295 DVec3::new(0.0, cosa, sina),
296 DVec3::new(0.0, -sina, cosa),
297 )
298 }
299
300 #[inline]
302 #[must_use]
303 pub fn from_rotation_y(angle: f64) -> Self {
304 let (sina, cosa) = math::sin_cos(angle);
305 Self::from_cols(
306 DVec3::new(cosa, 0.0, -sina),
307 DVec3::Y,
308 DVec3::new(sina, 0.0, cosa),
309 )
310 }
311
312 #[inline]
314 #[must_use]
315 pub fn from_rotation_z(angle: f64) -> Self {
316 let (sina, cosa) = math::sin_cos(angle);
317 Self::from_cols(
318 DVec3::new(cosa, sina, 0.0),
319 DVec3::new(-sina, cosa, 0.0),
320 DVec3::Z,
321 )
322 }
323
324 #[inline]
329 #[must_use]
330 pub fn from_translation(translation: DVec2) -> Self {
331 Self::from_cols(
332 DVec3::X,
333 DVec3::Y,
334 DVec3::new(translation.x, translation.y, 1.0),
335 )
336 }
337
338 #[inline]
344 #[must_use]
345 pub fn from_angle(angle: f64) -> Self {
346 let (sin, cos) = math::sin_cos(angle);
347 Self::from_cols(
348 DVec3::new(cos, sin, 0.0),
349 DVec3::new(-sin, cos, 0.0),
350 DVec3::Z,
351 )
352 }
353
354 #[inline]
360 #[must_use]
361 pub fn from_scale_angle_translation(scale: DVec2, angle: f64, translation: DVec2) -> Self {
362 let (sin, cos) = math::sin_cos(angle);
363 Self::from_cols(
364 DVec3::new(cos * scale.x, sin * scale.x, 0.0),
365 DVec3::new(-sin * scale.y, cos * scale.y, 0.0),
366 DVec3::new(translation.x, translation.y, 1.0),
367 )
368 }
369
370 #[inline]
379 #[must_use]
380 pub fn from_scale(scale: DVec2) -> Self {
381 glam_assert!(scale.cmpne(DVec2::ZERO).any());
383
384 Self::from_cols(
385 DVec3::new(scale.x, 0.0, 0.0),
386 DVec3::new(0.0, scale.y, 0.0),
387 DVec3::Z,
388 )
389 }
390
391 #[inline]
396 pub fn from_mat2(m: DMat2) -> Self {
397 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), DVec3::Z)
398 }
399
400 #[inline]
406 #[must_use]
407 pub const fn from_cols_slice(slice: &[f64]) -> Self {
408 Self::new(
409 slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
410 slice[8],
411 )
412 }
413
414 #[inline]
420 pub fn write_cols_to_slice(&self, slice: &mut [f64]) {
421 slice[0] = self.x_axis.x;
422 slice[1] = self.x_axis.y;
423 slice[2] = self.x_axis.z;
424 slice[3] = self.y_axis.x;
425 slice[4] = self.y_axis.y;
426 slice[5] = self.y_axis.z;
427 slice[6] = self.z_axis.x;
428 slice[7] = self.z_axis.y;
429 slice[8] = self.z_axis.z;
430 }
431
432 #[inline]
438 #[must_use]
439 pub fn col(&self, index: usize) -> DVec3 {
440 match index {
441 0 => self.x_axis,
442 1 => self.y_axis,
443 2 => self.z_axis,
444 _ => panic!("index out of bounds"),
445 }
446 }
447
448 #[inline]
454 pub fn col_mut(&mut self, index: usize) -> &mut DVec3 {
455 match index {
456 0 => &mut self.x_axis,
457 1 => &mut self.y_axis,
458 2 => &mut self.z_axis,
459 _ => panic!("index out of bounds"),
460 }
461 }
462
463 #[inline]
469 #[must_use]
470 pub fn row(&self, index: usize) -> DVec3 {
471 match index {
472 0 => DVec3::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
473 1 => DVec3::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
474 2 => DVec3::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
475 _ => panic!("index out of bounds"),
476 }
477 }
478
479 #[inline]
482 #[must_use]
483 pub fn is_finite(&self) -> bool {
484 self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
485 }
486
487 #[inline]
489 #[must_use]
490 pub fn is_nan(&self) -> bool {
491 self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
492 }
493
494 #[inline]
496 #[must_use]
497 pub fn transpose(&self) -> Self {
498 Self {
499 x_axis: DVec3::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
500 y_axis: DVec3::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
501 z_axis: DVec3::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
502 }
503 }
504
505 #[inline]
507 #[must_use]
508 pub fn diagonal(&self) -> DVec3 {
509 DVec3::new(self.x_axis.x, self.y_axis.y, self.z_axis.z)
510 }
511
512 #[inline]
514 #[must_use]
515 pub fn determinant(&self) -> f64 {
516 self.z_axis.dot(self.x_axis.cross(self.y_axis))
517 }
518
519 #[inline(always)]
531 #[must_use]
532 fn inverse_checked<const CHECKED: bool>(&self) -> (Self, bool) {
533 let tmp0 = self.y_axis.cross(self.z_axis);
534 let tmp1 = self.z_axis.cross(self.x_axis);
535 let tmp2 = self.x_axis.cross(self.y_axis);
536 let det = self.z_axis.dot(tmp2);
537 if CHECKED {
538 if det == 0.0 {
539 return (Self::ZERO, false);
540 }
541 } else {
542 glam_assert!(det != 0.0);
543 }
544 let inv_det = DVec3::splat(det.recip());
545 (
546 Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose(),
547 true,
548 )
549 }
550
551 #[inline]
559 #[must_use]
560 pub fn inverse(&self) -> Self {
561 self.inverse_checked::<false>().0
562 }
563
564 #[inline]
566 #[must_use]
567 pub fn try_inverse(&self) -> Option<Self> {
568 let (m, is_valid) = self.inverse_checked::<true>();
569 if is_valid {
570 Some(m)
571 } else {
572 None
573 }
574 }
575
576 #[inline]
578 #[must_use]
579 pub fn inverse_or_zero(&self) -> Self {
580 self.inverse_checked::<true>().0
581 }
582
583 #[inline]
593 #[must_use]
594 pub fn transform_point2(&self, rhs: DVec2) -> DVec2 {
595 glam_assert!(self.row(2).abs_diff_eq(DVec3::Z, 1e-6));
596 DMat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
597 }
598
599 #[inline]
609 #[must_use]
610 pub fn transform_vector2(&self, rhs: DVec2) -> DVec2 {
611 glam_assert!(self.row(2).abs_diff_eq(DVec3::Z, 1e-6));
612 DMat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
613 }
614
615 #[inline]
623 #[must_use]
624 pub fn look_to_lh(dir: DVec3, up: DVec3) -> Self {
625 Self::look_to_rh(-dir, up)
626 }
627
628 #[inline]
636 #[must_use]
637 pub fn look_to_rh(dir: DVec3, up: DVec3) -> Self {
638 glam_assert!(dir.is_normalized());
639 glam_assert!(up.is_normalized());
640 let f = dir;
641 let s = f.cross(up).normalize();
642 let u = s.cross(f);
643
644 Self::from_cols(
645 DVec3::new(s.x, u.x, -f.x),
646 DVec3::new(s.y, u.y, -f.y),
647 DVec3::new(s.z, u.z, -f.z),
648 )
649 }
650
651 #[inline]
660 #[must_use]
661 pub fn look_at_lh(eye: DVec3, center: DVec3, up: DVec3) -> Self {
662 Self::look_to_lh(center.sub(eye).normalize(), up)
663 }
664
665 #[inline]
674 pub fn look_at_rh(eye: DVec3, center: DVec3, up: DVec3) -> Self {
675 Self::look_to_rh(center.sub(eye).normalize(), up)
676 }
677
678 #[inline]
680 #[must_use]
681 pub fn mul_vec3(&self, rhs: DVec3) -> DVec3 {
682 let mut res = self.x_axis.mul(rhs.x);
683 res = res.add(self.y_axis.mul(rhs.y));
684 res = res.add(self.z_axis.mul(rhs.z));
685 res
686 }
687
688 #[inline]
690 #[must_use]
691 pub fn mul_transpose_vec3(&self, rhs: DVec3) -> DVec3 {
692 DVec3::new(
693 self.x_axis.dot(rhs),
694 self.y_axis.dot(rhs),
695 self.z_axis.dot(rhs),
696 )
697 }
698
699 #[inline]
701 #[must_use]
702 pub fn mul_mat3(&self, rhs: &Self) -> Self {
703 self.mul(rhs)
704 }
705
706 #[inline]
708 #[must_use]
709 pub fn add_mat3(&self, rhs: &Self) -> Self {
710 self.add(rhs)
711 }
712
713 #[inline]
715 #[must_use]
716 pub fn sub_mat3(&self, rhs: &Self) -> Self {
717 self.sub(rhs)
718 }
719
720 #[inline]
722 #[must_use]
723 pub fn mul_scalar(&self, rhs: f64) -> Self {
724 Self::from_cols(
725 self.x_axis.mul(rhs),
726 self.y_axis.mul(rhs),
727 self.z_axis.mul(rhs),
728 )
729 }
730
731 #[inline]
735 #[must_use]
736 pub fn mul_diagonal_scale(&self, scale: DVec3) -> Self {
737 Self::from_cols(
738 self.x_axis * scale.x,
739 self.y_axis * scale.y,
740 self.z_axis * scale.z,
741 )
742 }
743
744 #[inline]
746 #[must_use]
747 pub fn div_scalar(&self, rhs: f64) -> Self {
748 let rhs = DVec3::splat(rhs);
749 Self::from_cols(
750 self.x_axis.div(rhs),
751 self.y_axis.div(rhs),
752 self.z_axis.div(rhs),
753 )
754 }
755
756 #[inline]
766 #[must_use]
767 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f64) -> bool {
768 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
769 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
770 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
771 }
772
773 #[inline]
775 #[must_use]
776 pub fn abs(&self) -> Self {
777 Self::from_cols(self.x_axis.abs(), self.y_axis.abs(), self.z_axis.abs())
778 }
779
780 #[inline]
781 pub fn as_mat3(&self) -> Mat3 {
782 Mat3::from_cols(
783 self.x_axis.as_vec3(),
784 self.y_axis.as_vec3(),
785 self.z_axis.as_vec3(),
786 )
787 }
788}
789
790impl Default for DMat3 {
791 #[inline]
792 fn default() -> Self {
793 Self::IDENTITY
794 }
795}
796
797impl Add for DMat3 {
798 type Output = Self;
799 #[inline]
800 fn add(self, rhs: Self) -> Self {
801 Self::from_cols(
802 self.x_axis.add(rhs.x_axis),
803 self.y_axis.add(rhs.y_axis),
804 self.z_axis.add(rhs.z_axis),
805 )
806 }
807}
808
809impl Add<&Self> for DMat3 {
810 type Output = Self;
811 #[inline]
812 fn add(self, rhs: &Self) -> Self {
813 self.add(*rhs)
814 }
815}
816
817impl Add<&DMat3> for &DMat3 {
818 type Output = DMat3;
819 #[inline]
820 fn add(self, rhs: &DMat3) -> DMat3 {
821 (*self).add(*rhs)
822 }
823}
824
825impl Add<DMat3> for &DMat3 {
826 type Output = DMat3;
827 #[inline]
828 fn add(self, rhs: DMat3) -> DMat3 {
829 (*self).add(rhs)
830 }
831}
832
833impl AddAssign for DMat3 {
834 #[inline]
835 fn add_assign(&mut self, rhs: Self) {
836 *self = self.add(rhs);
837 }
838}
839
840impl AddAssign<&Self> for DMat3 {
841 #[inline]
842 fn add_assign(&mut self, rhs: &Self) {
843 self.add_assign(*rhs);
844 }
845}
846
847impl Sub for DMat3 {
848 type Output = Self;
849 #[inline]
850 fn sub(self, rhs: Self) -> Self {
851 Self::from_cols(
852 self.x_axis.sub(rhs.x_axis),
853 self.y_axis.sub(rhs.y_axis),
854 self.z_axis.sub(rhs.z_axis),
855 )
856 }
857}
858
859impl Sub<&Self> for DMat3 {
860 type Output = Self;
861 #[inline]
862 fn sub(self, rhs: &Self) -> Self {
863 self.sub(*rhs)
864 }
865}
866
867impl Sub<&DMat3> for &DMat3 {
868 type Output = DMat3;
869 #[inline]
870 fn sub(self, rhs: &DMat3) -> DMat3 {
871 (*self).sub(*rhs)
872 }
873}
874
875impl Sub<DMat3> for &DMat3 {
876 type Output = DMat3;
877 #[inline]
878 fn sub(self, rhs: DMat3) -> DMat3 {
879 (*self).sub(rhs)
880 }
881}
882
883impl SubAssign for DMat3 {
884 #[inline]
885 fn sub_assign(&mut self, rhs: Self) {
886 *self = self.sub(rhs);
887 }
888}
889
890impl SubAssign<&Self> for DMat3 {
891 #[inline]
892 fn sub_assign(&mut self, rhs: &Self) {
893 self.sub_assign(*rhs);
894 }
895}
896
897impl Neg for DMat3 {
898 type Output = Self;
899 #[inline]
900 fn neg(self) -> Self::Output {
901 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
902 }
903}
904
905impl Neg for &DMat3 {
906 type Output = DMat3;
907 #[inline]
908 fn neg(self) -> DMat3 {
909 (*self).neg()
910 }
911}
912
913impl Mul for DMat3 {
914 type Output = Self;
915 #[inline]
916 fn mul(self, rhs: Self) -> Self {
917 Self::from_cols(
918 self.mul(rhs.x_axis),
919 self.mul(rhs.y_axis),
920 self.mul(rhs.z_axis),
921 )
922 }
923}
924
925impl Mul<&Self> for DMat3 {
926 type Output = Self;
927 #[inline]
928 fn mul(self, rhs: &Self) -> Self {
929 self.mul(*rhs)
930 }
931}
932
933impl Mul<&DMat3> for &DMat3 {
934 type Output = DMat3;
935 #[inline]
936 fn mul(self, rhs: &DMat3) -> DMat3 {
937 (*self).mul(*rhs)
938 }
939}
940
941impl Mul<DMat3> for &DMat3 {
942 type Output = DMat3;
943 #[inline]
944 fn mul(self, rhs: DMat3) -> DMat3 {
945 (*self).mul(rhs)
946 }
947}
948
949impl MulAssign for DMat3 {
950 #[inline]
951 fn mul_assign(&mut self, rhs: Self) {
952 *self = self.mul(rhs);
953 }
954}
955
956impl MulAssign<&Self> for DMat3 {
957 #[inline]
958 fn mul_assign(&mut self, rhs: &Self) {
959 self.mul_assign(*rhs);
960 }
961}
962
963impl Mul<DVec3> for DMat3 {
964 type Output = DVec3;
965 #[inline]
966 fn mul(self, rhs: DVec3) -> Self::Output {
967 self.mul_vec3(rhs)
968 }
969}
970
971impl Mul<&DVec3> for DMat3 {
972 type Output = DVec3;
973 #[inline]
974 fn mul(self, rhs: &DVec3) -> DVec3 {
975 self.mul(*rhs)
976 }
977}
978
979impl Mul<&DVec3> for &DMat3 {
980 type Output = DVec3;
981 #[inline]
982 fn mul(self, rhs: &DVec3) -> DVec3 {
983 (*self).mul(*rhs)
984 }
985}
986
987impl Mul<DVec3> for &DMat3 {
988 type Output = DVec3;
989 #[inline]
990 fn mul(self, rhs: DVec3) -> DVec3 {
991 (*self).mul(rhs)
992 }
993}
994
995impl Mul<DMat3> for f64 {
996 type Output = DMat3;
997 #[inline]
998 fn mul(self, rhs: DMat3) -> Self::Output {
999 rhs.mul_scalar(self)
1000 }
1001}
1002
1003impl Mul<&DMat3> for f64 {
1004 type Output = DMat3;
1005 #[inline]
1006 fn mul(self, rhs: &DMat3) -> DMat3 {
1007 self.mul(*rhs)
1008 }
1009}
1010
1011impl Mul<&DMat3> for &f64 {
1012 type Output = DMat3;
1013 #[inline]
1014 fn mul(self, rhs: &DMat3) -> DMat3 {
1015 (*self).mul(*rhs)
1016 }
1017}
1018
1019impl Mul<DMat3> for &f64 {
1020 type Output = DMat3;
1021 #[inline]
1022 fn mul(self, rhs: DMat3) -> DMat3 {
1023 (*self).mul(rhs)
1024 }
1025}
1026
1027impl Mul<f64> for DMat3 {
1028 type Output = Self;
1029 #[inline]
1030 fn mul(self, rhs: f64) -> Self {
1031 self.mul_scalar(rhs)
1032 }
1033}
1034
1035impl Mul<&f64> for DMat3 {
1036 type Output = Self;
1037 #[inline]
1038 fn mul(self, rhs: &f64) -> Self {
1039 self.mul(*rhs)
1040 }
1041}
1042
1043impl Mul<&f64> for &DMat3 {
1044 type Output = DMat3;
1045 #[inline]
1046 fn mul(self, rhs: &f64) -> DMat3 {
1047 (*self).mul(*rhs)
1048 }
1049}
1050
1051impl Mul<f64> for &DMat3 {
1052 type Output = DMat3;
1053 #[inline]
1054 fn mul(self, rhs: f64) -> DMat3 {
1055 (*self).mul(rhs)
1056 }
1057}
1058
1059impl MulAssign<f64> for DMat3 {
1060 #[inline]
1061 fn mul_assign(&mut self, rhs: f64) {
1062 *self = self.mul(rhs);
1063 }
1064}
1065
1066impl MulAssign<&f64> for DMat3 {
1067 #[inline]
1068 fn mul_assign(&mut self, rhs: &f64) {
1069 self.mul_assign(*rhs);
1070 }
1071}
1072
1073impl Div<DMat3> for f64 {
1074 type Output = DMat3;
1075 #[inline]
1076 fn div(self, rhs: DMat3) -> Self::Output {
1077 rhs.div_scalar(self)
1078 }
1079}
1080
1081impl Div<&DMat3> for f64 {
1082 type Output = DMat3;
1083 #[inline]
1084 fn div(self, rhs: &DMat3) -> DMat3 {
1085 self.div(*rhs)
1086 }
1087}
1088
1089impl Div<&DMat3> for &f64 {
1090 type Output = DMat3;
1091 #[inline]
1092 fn div(self, rhs: &DMat3) -> DMat3 {
1093 (*self).div(*rhs)
1094 }
1095}
1096
1097impl Div<DMat3> for &f64 {
1098 type Output = DMat3;
1099 #[inline]
1100 fn div(self, rhs: DMat3) -> DMat3 {
1101 (*self).div(rhs)
1102 }
1103}
1104
1105impl Div<f64> for DMat3 {
1106 type Output = Self;
1107 #[inline]
1108 fn div(self, rhs: f64) -> Self {
1109 self.div_scalar(rhs)
1110 }
1111}
1112
1113impl Div<&f64> for DMat3 {
1114 type Output = Self;
1115 #[inline]
1116 fn div(self, rhs: &f64) -> Self {
1117 self.div(*rhs)
1118 }
1119}
1120
1121impl Div<&f64> for &DMat3 {
1122 type Output = DMat3;
1123 #[inline]
1124 fn div(self, rhs: &f64) -> DMat3 {
1125 (*self).div(*rhs)
1126 }
1127}
1128
1129impl Div<f64> for &DMat3 {
1130 type Output = DMat3;
1131 #[inline]
1132 fn div(self, rhs: f64) -> DMat3 {
1133 (*self).div(rhs)
1134 }
1135}
1136
1137impl DivAssign<f64> for DMat3 {
1138 #[inline]
1139 fn div_assign(&mut self, rhs: f64) {
1140 *self = self.div(rhs);
1141 }
1142}
1143
1144impl DivAssign<&f64> for DMat3 {
1145 #[inline]
1146 fn div_assign(&mut self, rhs: &f64) {
1147 self.div_assign(*rhs);
1148 }
1149}
1150
1151impl Sum<Self> for DMat3 {
1152 fn sum<I>(iter: I) -> Self
1153 where
1154 I: Iterator<Item = Self>,
1155 {
1156 iter.fold(Self::ZERO, Self::add)
1157 }
1158}
1159
1160impl<'a> Sum<&'a Self> for DMat3 {
1161 fn sum<I>(iter: I) -> Self
1162 where
1163 I: Iterator<Item = &'a Self>,
1164 {
1165 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1166 }
1167}
1168
1169impl Product for DMat3 {
1170 fn product<I>(iter: I) -> Self
1171 where
1172 I: Iterator<Item = Self>,
1173 {
1174 iter.fold(Self::IDENTITY, Self::mul)
1175 }
1176}
1177
1178impl<'a> Product<&'a Self> for DMat3 {
1179 fn product<I>(iter: I) -> Self
1180 where
1181 I: Iterator<Item = &'a Self>,
1182 {
1183 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
1184 }
1185}
1186
1187impl PartialEq for DMat3 {
1188 #[inline]
1189 fn eq(&self, rhs: &Self) -> bool {
1190 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
1191 }
1192}
1193
1194impl AsRef<[f64; 9]> for DMat3 {
1195 #[inline]
1196 fn as_ref(&self) -> &[f64; 9] {
1197 unsafe { &*(self as *const Self as *const [f64; 9]) }
1198 }
1199}
1200
1201impl AsMut<[f64; 9]> for DMat3 {
1202 #[inline]
1203 fn as_mut(&mut self) -> &mut [f64; 9] {
1204 unsafe { &mut *(self as *mut Self as *mut [f64; 9]) }
1205 }
1206}
1207
1208impl fmt::Debug for DMat3 {
1209 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1210 fmt.debug_struct(stringify!(DMat3))
1211 .field("x_axis", &self.x_axis)
1212 .field("y_axis", &self.y_axis)
1213 .field("z_axis", &self.z_axis)
1214 .finish()
1215 }
1216}
1217
1218impl fmt::Display for DMat3 {
1219 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1220 if let Some(p) = f.precision() {
1221 write!(
1222 f,
1223 "[{:.*}, {:.*}, {:.*}]",
1224 p, self.x_axis, p, self.y_axis, p, self.z_axis
1225 )
1226 } else {
1227 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
1228 }
1229 }
1230}