1use crate::{
4 DMat2, DMat4, DQuat, DVec2, DVec3, EulerRot, Mat3,
5 euler::{FromEuler, ToEuler},
6 f64::math,
7 swizzles::*,
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-08")]
14use zerocopy_derive_08::*;
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-08",
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)]
95 #[must_use]
96 pub const fn from_cols(x_axis: DVec3, y_axis: DVec3, z_axis: DVec3) -> Self {
97 Self {
98 x_axis,
99 y_axis,
100 z_axis,
101 }
102 }
103
104 #[inline(always)]
110 #[must_use]
111 pub const fn from_rows(row0: DVec3, row1: DVec3, row2: DVec3) -> Self {
112 let [m00, m01, m02] = row0.to_array();
113 let [m10, m11, m12] = row1.to_array();
114 let [m20, m21, m22] = row2.to_array();
115 Self::new(m00, m10, m20, m01, m11, m21, m02, m12, m22)
116 }
117
118 #[inline]
122 #[must_use]
123 pub const fn from_cols_array(m: &[f64; 9]) -> Self {
124 Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
125 }
126
127 #[inline]
131 #[must_use]
132 pub const fn to_cols_array(&self) -> [f64; 9] {
133 [
134 self.x_axis.x,
135 self.x_axis.y,
136 self.x_axis.z,
137 self.y_axis.x,
138 self.y_axis.y,
139 self.y_axis.z,
140 self.z_axis.x,
141 self.z_axis.y,
142 self.z_axis.z,
143 ]
144 }
145
146 #[inline]
150 #[must_use]
151 pub const fn from_cols_array_2d(m: &[[f64; 3]; 3]) -> Self {
152 Self::from_cols(
153 DVec3::from_array(m[0]),
154 DVec3::from_array(m[1]),
155 DVec3::from_array(m[2]),
156 )
157 }
158
159 #[inline]
163 #[must_use]
164 pub const fn to_cols_array_2d(&self) -> [[f64; 3]; 3] {
165 [
166 self.x_axis.to_array(),
167 self.y_axis.to_array(),
168 self.z_axis.to_array(),
169 ]
170 }
171
172 #[inline]
178 #[must_use]
179 pub const fn from_rows_array(m: &[f64; 9]) -> Self {
180 Self::new(m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8])
181 }
182
183 #[inline]
189 #[must_use]
190 pub const fn to_rows_array(&self) -> [f64; 9] {
191 let m = self.to_cols_array();
192 [m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8]]
193 }
194
195 #[doc(alias = "scale")]
197 #[inline]
198 #[must_use]
199 pub const fn from_diagonal(diagonal: DVec3) -> Self {
200 Self::new(
201 diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
202 )
203 }
204
205 #[inline]
207 #[must_use]
208 pub fn from_mat4(m: DMat4) -> Self {
209 Self::from_cols(
210 DVec3::from_vec4(m.x_axis),
211 DVec3::from_vec4(m.y_axis),
212 DVec3::from_vec4(m.z_axis),
213 )
214 }
215
216 #[inline]
223 #[must_use]
224 #[track_caller]
225 pub fn from_mat4_minor(m: DMat4, i: usize, j: usize) -> Self {
226 match (i, j) {
227 (0, 0) => Self::from_cols(m.y_axis.yzw(), m.z_axis.yzw(), m.w_axis.yzw()),
228 (0, 1) => Self::from_cols(m.y_axis.xzw(), m.z_axis.xzw(), m.w_axis.xzw()),
229 (0, 2) => Self::from_cols(m.y_axis.xyw(), m.z_axis.xyw(), m.w_axis.xyw()),
230 (0, 3) => Self::from_cols(m.y_axis.xyz(), m.z_axis.xyz(), m.w_axis.xyz()),
231 (1, 0) => Self::from_cols(m.x_axis.yzw(), m.z_axis.yzw(), m.w_axis.yzw()),
232 (1, 1) => Self::from_cols(m.x_axis.xzw(), m.z_axis.xzw(), m.w_axis.xzw()),
233 (1, 2) => Self::from_cols(m.x_axis.xyw(), m.z_axis.xyw(), m.w_axis.xyw()),
234 (1, 3) => Self::from_cols(m.x_axis.xyz(), m.z_axis.xyz(), m.w_axis.xyz()),
235 (2, 0) => Self::from_cols(m.x_axis.yzw(), m.y_axis.yzw(), m.w_axis.yzw()),
236 (2, 1) => Self::from_cols(m.x_axis.xzw(), m.y_axis.xzw(), m.w_axis.xzw()),
237 (2, 2) => Self::from_cols(m.x_axis.xyw(), m.y_axis.xyw(), m.w_axis.xyw()),
238 (2, 3) => Self::from_cols(m.x_axis.xyz(), m.y_axis.xyz(), m.w_axis.xyz()),
239 (3, 0) => Self::from_cols(m.x_axis.yzw(), m.y_axis.yzw(), m.z_axis.yzw()),
240 (3, 1) => Self::from_cols(m.x_axis.xzw(), m.y_axis.xzw(), m.z_axis.xzw()),
241 (3, 2) => Self::from_cols(m.x_axis.xyw(), m.y_axis.xyw(), m.z_axis.xyw()),
242 (3, 3) => Self::from_cols(m.x_axis.xyz(), m.y_axis.xyz(), m.z_axis.xyz()),
243 _ => panic!("index out of bounds"),
244 }
245 }
246
247 #[inline]
253 #[must_use]
254 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
255 pub fn from_quat(rotation: DQuat) -> Self {
256 glam_assert!(rotation.is_normalized());
257
258 let x2 = rotation.x + rotation.x;
259 let y2 = rotation.y + rotation.y;
260 let z2 = rotation.z + rotation.z;
261 let xx = rotation.x * x2;
262 let xy = rotation.x * y2;
263 let xz = rotation.x * z2;
264 let yy = rotation.y * y2;
265 let yz = rotation.y * z2;
266 let zz = rotation.z * z2;
267 let wx = rotation.w * x2;
268 let wy = rotation.w * y2;
269 let wz = rotation.w * z2;
270
271 Self::from_cols(
272 DVec3::new(1.0 - (yy + zz), xy + wz, xz - wy),
273 DVec3::new(xy - wz, 1.0 - (xx + zz), yz + wx),
274 DVec3::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
275 )
276 }
277
278 #[inline]
285 #[must_use]
286 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
287 pub fn from_axis_angle(axis: DVec3, angle: f64) -> Self {
288 glam_assert!(axis.is_normalized());
289
290 let (sin, cos) = math::sin_cos(angle);
291 let (xsin, ysin, zsin) = axis.mul(sin).into();
292 let (x, y, z) = axis.into();
293 let (x2, y2, z2) = axis.mul(axis).into();
294 let omc = 1.0 - cos;
295 let xyomc = x * y * omc;
296 let xzomc = x * z * omc;
297 let yzomc = y * z * omc;
298 Self::from_cols(
299 DVec3::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
300 DVec3::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
301 DVec3::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
302 )
303 }
304
305 #[inline]
308 #[must_use]
309 pub fn from_euler(order: EulerRot, a: f64, b: f64, c: f64) -> Self {
310 Self::from_euler_angles(order, a, b, c)
311 }
312
313 #[inline]
322 #[must_use]
323 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
324 pub fn to_euler(&self, order: EulerRot) -> (f64, f64, f64) {
325 glam_assert!(
326 self.x_axis.is_normalized()
327 && self.y_axis.is_normalized()
328 && self.z_axis.is_normalized()
329 );
330 self.to_euler_angles(order)
331 }
332
333 #[inline]
335 #[must_use]
336 pub fn from_rotation_x(angle: f64) -> Self {
337 let (sina, cosa) = math::sin_cos(angle);
338 Self::from_cols(
339 DVec3::X,
340 DVec3::new(0.0, cosa, sina),
341 DVec3::new(0.0, -sina, cosa),
342 )
343 }
344
345 #[inline]
347 #[must_use]
348 pub fn from_rotation_y(angle: f64) -> Self {
349 let (sina, cosa) = math::sin_cos(angle);
350 Self::from_cols(
351 DVec3::new(cosa, 0.0, -sina),
352 DVec3::Y,
353 DVec3::new(sina, 0.0, cosa),
354 )
355 }
356
357 #[inline]
359 #[must_use]
360 pub fn from_rotation_z(angle: f64) -> Self {
361 let (sina, cosa) = math::sin_cos(angle);
362 Self::from_cols(
363 DVec3::new(cosa, sina, 0.0),
364 DVec3::new(-sina, cosa, 0.0),
365 DVec3::Z,
366 )
367 }
368
369 #[inline]
374 #[must_use]
375 pub fn from_translation(translation: DVec2) -> Self {
376 Self::from_cols(
377 DVec3::X,
378 DVec3::Y,
379 DVec3::new(translation.x, translation.y, 1.0),
380 )
381 }
382
383 #[inline]
389 #[must_use]
390 pub fn from_angle(angle: f64) -> Self {
391 let (sin, cos) = math::sin_cos(angle);
392 Self::from_cols(
393 DVec3::new(cos, sin, 0.0),
394 DVec3::new(-sin, cos, 0.0),
395 DVec3::Z,
396 )
397 }
398
399 #[inline]
405 #[must_use]
406 pub fn from_scale_angle_translation(scale: DVec2, angle: f64, translation: DVec2) -> Self {
407 let (sin, cos) = math::sin_cos(angle);
408 Self::from_cols(
409 DVec3::new(cos * scale.x, sin * scale.x, 0.0),
410 DVec3::new(-sin * scale.y, cos * scale.y, 0.0),
411 DVec3::new(translation.x, translation.y, 1.0),
412 )
413 }
414
415 #[inline]
424 #[must_use]
425 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
426 pub fn from_scale(scale: DVec2) -> Self {
427 glam_assert!(scale.cmpne(DVec2::ZERO).any());
429
430 Self::from_cols(
431 DVec3::new(scale.x, 0.0, 0.0),
432 DVec3::new(0.0, scale.y, 0.0),
433 DVec3::Z,
434 )
435 }
436
437 #[inline]
442 pub fn from_mat2(m: DMat2) -> Self {
443 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), DVec3::Z)
444 }
445
446 #[inline]
454 #[must_use]
455 #[track_caller]
456 pub const fn from_cols_slice(slice: &[f64]) -> Self {
457 Self::new(
458 slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
459 slice[8],
460 )
461 }
462
463 #[inline]
469 #[track_caller]
470 pub fn write_cols_to_slice(&self, slice: &mut [f64]) {
471 slice[0] = self.x_axis.x;
472 slice[1] = self.x_axis.y;
473 slice[2] = self.x_axis.z;
474 slice[3] = self.y_axis.x;
475 slice[4] = self.y_axis.y;
476 slice[5] = self.y_axis.z;
477 slice[6] = self.z_axis.x;
478 slice[7] = self.z_axis.y;
479 slice[8] = self.z_axis.z;
480 }
481
482 #[inline]
493 #[must_use]
494 #[track_caller]
495 pub const fn from_rows_slice(slice: &[f64]) -> Self {
496 Self::new(
497 slice[0], slice[3], slice[6], slice[1], slice[4], slice[7], slice[2], slice[5],
498 slice[8],
499 )
500 }
501
502 #[inline]
508 #[must_use]
509 #[track_caller]
510 pub fn col(&self, index: usize) -> DVec3 {
511 match index {
512 0 => self.x_axis,
513 1 => self.y_axis,
514 2 => self.z_axis,
515 _ => panic!("index out of bounds"),
516 }
517 }
518
519 #[inline]
525 #[track_caller]
526 pub fn col_mut(&mut self, index: usize) -> &mut DVec3 {
527 match index {
528 0 => &mut self.x_axis,
529 1 => &mut self.y_axis,
530 2 => &mut self.z_axis,
531 _ => panic!("index out of bounds"),
532 }
533 }
534
535 #[inline]
543 #[must_use]
544 #[track_caller]
545 pub fn row(&self, index: usize) -> DVec3 {
546 match index {
547 0 => DVec3::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
548 1 => DVec3::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
549 2 => DVec3::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
550 _ => panic!("index out of bounds"),
551 }
552 }
553
554 #[inline]
564 #[track_caller]
565 pub fn set_row(&mut self, index: usize, row: DVec3) {
566 match index {
567 0 => {
568 self.x_axis.x = row.x;
569 self.y_axis.x = row.y;
570 self.z_axis.x = row.z;
571 }
572 1 => {
573 self.x_axis.y = row.x;
574 self.y_axis.y = row.y;
575 self.z_axis.y = row.z;
576 }
577 2 => {
578 self.x_axis.z = row.x;
579 self.y_axis.z = row.y;
580 self.z_axis.z = row.z;
581 }
582 _ => panic!("index out of bounds"),
583 }
584 }
585
586 #[inline]
589 #[must_use]
590 pub fn is_finite(&self) -> bool {
591 self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
592 }
593
594 #[inline]
596 #[must_use]
597 pub fn is_nan(&self) -> bool {
598 self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
599 }
600
601 #[inline]
603 #[must_use]
604 pub fn transpose(&self) -> Self {
605 Self {
606 x_axis: DVec3::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
607 y_axis: DVec3::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
608 z_axis: DVec3::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
609 }
610 }
611
612 #[inline]
614 #[must_use]
615 pub fn diagonal(&self) -> DVec3 {
616 DVec3::new(self.x_axis.x, self.y_axis.y, self.z_axis.z)
617 }
618
619 #[inline]
621 #[must_use]
622 pub fn determinant(&self) -> f64 {
623 self.x_axis.dot(self.y_axis.cross(self.z_axis))
624 }
625
626 #[inline(always)]
638 #[must_use]
639 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
640 fn inverse_checked<const CHECKED: bool>(&self) -> (Self, bool) {
641 let tmp0 = self.y_axis.cross(self.z_axis);
642 let tmp1 = self.z_axis.cross(self.x_axis);
643 let tmp2 = self.x_axis.cross(self.y_axis);
644 let inv_det = DVec3::splat(1.0 / self.x_axis.dot(tmp0));
645 let m =
646 Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose();
647 if CHECKED {
648 if !m.is_finite() {
649 return (Self::ZERO, false);
650 }
651 } else {
652 glam_assert!(m.is_finite());
653 }
654 (m, true)
655 }
656
657 #[inline]
669 #[must_use]
670 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
671 pub fn inverse(&self) -> Self {
672 self.inverse_checked::<false>().0
673 }
674
675 #[inline]
678 #[must_use]
679 pub fn try_inverse(&self) -> Option<Self> {
680 let (m, is_valid) = self.inverse_checked::<true>();
681 if is_valid { Some(m) } else { None }
682 }
683
684 #[inline]
687 #[must_use]
688 pub fn inverse_or_zero(&self) -> Self {
689 self.inverse_checked::<true>().0
690 }
691
692 #[inline]
702 #[must_use]
703 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
704 pub fn transform_point2(&self, rhs: DVec2) -> DVec2 {
705 glam_assert!(self.row(2).abs_diff_eq(DVec3::Z, 1e-6));
706 DMat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
707 }
708
709 #[inline]
719 #[must_use]
720 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
721 pub fn transform_vector2(&self, rhs: DVec2) -> DVec2 {
722 glam_assert!(self.row(2).abs_diff_eq(DVec3::Z, 1e-6));
723 DMat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
724 }
725
726 #[inline]
728 #[must_use]
729 pub fn mul_vec3(&self, rhs: DVec3) -> DVec3 {
730 let mut res = self.x_axis.mul(rhs.x);
731 res = res.add(self.y_axis.mul(rhs.y));
732 res = res.add(self.z_axis.mul(rhs.z));
733 res
734 }
735
736 #[inline]
738 #[must_use]
739 pub fn transpose_mul_vec3(&self, rhs: DVec3) -> DVec3 {
740 DVec3::new(
741 self.x_axis.dot(rhs),
742 self.y_axis.dot(rhs),
743 self.z_axis.dot(rhs),
744 )
745 }
746
747 #[inline]
749 #[must_use]
750 #[deprecated(
751 since = "0.34.2",
752 note = "Use `transpose_mul_vec3` instead, whose word order matches its order of operations and is consistent with `transpose().mul_vec3`."
753 )]
754 pub fn mul_transpose_vec3(&self, rhs: DVec3) -> DVec3 {
755 self.transpose_mul_vec3(rhs)
756 }
757
758 #[inline]
760 #[must_use]
761 pub fn mul_mat3(&self, rhs: &Self) -> Self {
762 self.mul(rhs)
763 }
764
765 #[inline]
767 #[must_use]
768 pub fn add_mat3(&self, rhs: &Self) -> Self {
769 self.add(rhs)
770 }
771
772 #[inline]
774 #[must_use]
775 pub fn sub_mat3(&self, rhs: &Self) -> Self {
776 self.sub(rhs)
777 }
778
779 #[inline]
781 #[must_use]
782 pub fn mul_scalar(&self, rhs: f64) -> Self {
783 Self::from_cols(
784 self.x_axis.mul(rhs),
785 self.y_axis.mul(rhs),
786 self.z_axis.mul(rhs),
787 )
788 }
789
790 #[inline]
794 #[must_use]
795 pub fn mul_diagonal_scale(&self, scale: DVec3) -> Self {
796 Self::from_cols(
797 self.x_axis * scale.x,
798 self.y_axis * scale.y,
799 self.z_axis * scale.z,
800 )
801 }
802
803 #[inline]
805 #[must_use]
806 pub fn div_scalar(&self, rhs: f64) -> Self {
807 let rhs = DVec3::splat(rhs);
808 Self::from_cols(
809 self.x_axis.div(rhs),
810 self.y_axis.div(rhs),
811 self.z_axis.div(rhs),
812 )
813 }
814
815 #[inline]
817 #[must_use]
818 pub fn recip(&self) -> Self {
819 Self::from_cols(
820 self.x_axis.recip(),
821 self.y_axis.recip(),
822 self.z_axis.recip(),
823 )
824 }
825
826 #[inline]
836 #[must_use]
837 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f64) -> bool {
838 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
839 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
840 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
841 }
842
843 #[inline]
845 #[must_use]
846 pub fn abs(&self) -> Self {
847 Self::from_cols(self.x_axis.abs(), self.y_axis.abs(), self.z_axis.abs())
848 }
849
850 #[cfg(feature = "f64")]
851 #[inline]
852 #[must_use]
853 pub fn as_mat3(&self) -> Mat3 {
854 Mat3::from_cols(
855 self.x_axis.as_vec3(),
856 self.y_axis.as_vec3(),
857 self.z_axis.as_vec3(),
858 )
859 }
860}
861
862impl Default for DMat3 {
863 #[inline]
864 fn default() -> Self {
865 Self::IDENTITY
866 }
867}
868
869impl Add for DMat3 {
870 type Output = Self;
871 #[inline]
872 fn add(self, rhs: Self) -> Self {
873 Self::from_cols(
874 self.x_axis.add(rhs.x_axis),
875 self.y_axis.add(rhs.y_axis),
876 self.z_axis.add(rhs.z_axis),
877 )
878 }
879}
880
881impl Add<&Self> for DMat3 {
882 type Output = Self;
883 #[inline]
884 fn add(self, rhs: &Self) -> Self {
885 self.add(*rhs)
886 }
887}
888
889impl Add<&DMat3> for &DMat3 {
890 type Output = DMat3;
891 #[inline]
892 fn add(self, rhs: &DMat3) -> DMat3 {
893 (*self).add(*rhs)
894 }
895}
896
897impl Add<DMat3> for &DMat3 {
898 type Output = DMat3;
899 #[inline]
900 fn add(self, rhs: DMat3) -> DMat3 {
901 (*self).add(rhs)
902 }
903}
904
905impl AddAssign for DMat3 {
906 #[inline]
907 fn add_assign(&mut self, rhs: Self) {
908 *self = self.add(rhs);
909 }
910}
911
912impl AddAssign<&Self> for DMat3 {
913 #[inline]
914 fn add_assign(&mut self, rhs: &Self) {
915 self.add_assign(*rhs);
916 }
917}
918
919impl Sub for DMat3 {
920 type Output = Self;
921 #[inline]
922 fn sub(self, rhs: Self) -> Self {
923 Self::from_cols(
924 self.x_axis.sub(rhs.x_axis),
925 self.y_axis.sub(rhs.y_axis),
926 self.z_axis.sub(rhs.z_axis),
927 )
928 }
929}
930
931impl Sub<&Self> for DMat3 {
932 type Output = Self;
933 #[inline]
934 fn sub(self, rhs: &Self) -> Self {
935 self.sub(*rhs)
936 }
937}
938
939impl Sub<&DMat3> for &DMat3 {
940 type Output = DMat3;
941 #[inline]
942 fn sub(self, rhs: &DMat3) -> DMat3 {
943 (*self).sub(*rhs)
944 }
945}
946
947impl Sub<DMat3> for &DMat3 {
948 type Output = DMat3;
949 #[inline]
950 fn sub(self, rhs: DMat3) -> DMat3 {
951 (*self).sub(rhs)
952 }
953}
954
955impl SubAssign for DMat3 {
956 #[inline]
957 fn sub_assign(&mut self, rhs: Self) {
958 *self = self.sub(rhs);
959 }
960}
961
962impl SubAssign<&Self> for DMat3 {
963 #[inline]
964 fn sub_assign(&mut self, rhs: &Self) {
965 self.sub_assign(*rhs);
966 }
967}
968
969impl Neg for DMat3 {
970 type Output = Self;
971 #[inline]
972 fn neg(self) -> Self::Output {
973 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
974 }
975}
976
977impl Neg for &DMat3 {
978 type Output = DMat3;
979 #[inline]
980 fn neg(self) -> DMat3 {
981 (*self).neg()
982 }
983}
984
985impl Mul for DMat3 {
986 type Output = Self;
987 #[inline]
988 fn mul(self, rhs: Self) -> Self {
989 Self::from_cols(
990 self.mul(rhs.x_axis),
991 self.mul(rhs.y_axis),
992 self.mul(rhs.z_axis),
993 )
994 }
995}
996
997impl Mul<&Self> for DMat3 {
998 type Output = Self;
999 #[inline]
1000 fn mul(self, rhs: &Self) -> Self {
1001 self.mul(*rhs)
1002 }
1003}
1004
1005impl Mul<&DMat3> for &DMat3 {
1006 type Output = DMat3;
1007 #[inline]
1008 fn mul(self, rhs: &DMat3) -> DMat3 {
1009 (*self).mul(*rhs)
1010 }
1011}
1012
1013impl Mul<DMat3> for &DMat3 {
1014 type Output = DMat3;
1015 #[inline]
1016 fn mul(self, rhs: DMat3) -> DMat3 {
1017 (*self).mul(rhs)
1018 }
1019}
1020
1021impl MulAssign for DMat3 {
1022 #[inline]
1023 fn mul_assign(&mut self, rhs: Self) {
1024 *self = self.mul(rhs);
1025 }
1026}
1027
1028impl MulAssign<&Self> for DMat3 {
1029 #[inline]
1030 fn mul_assign(&mut self, rhs: &Self) {
1031 self.mul_assign(*rhs);
1032 }
1033}
1034
1035impl Mul<DVec3> for DMat3 {
1036 type Output = DVec3;
1037 #[inline]
1038 fn mul(self, rhs: DVec3) -> Self::Output {
1039 self.mul_vec3(rhs)
1040 }
1041}
1042
1043impl Mul<&DVec3> for DMat3 {
1044 type Output = DVec3;
1045 #[inline]
1046 fn mul(self, rhs: &DVec3) -> DVec3 {
1047 self.mul(*rhs)
1048 }
1049}
1050
1051impl Mul<&DVec3> for &DMat3 {
1052 type Output = DVec3;
1053 #[inline]
1054 fn mul(self, rhs: &DVec3) -> DVec3 {
1055 (*self).mul(*rhs)
1056 }
1057}
1058
1059impl Mul<DVec3> for &DMat3 {
1060 type Output = DVec3;
1061 #[inline]
1062 fn mul(self, rhs: DVec3) -> DVec3 {
1063 (*self).mul(rhs)
1064 }
1065}
1066
1067impl Mul<DMat3> for f64 {
1068 type Output = DMat3;
1069 #[inline]
1070 fn mul(self, rhs: DMat3) -> Self::Output {
1071 rhs.mul_scalar(self)
1072 }
1073}
1074
1075impl Mul<&DMat3> for f64 {
1076 type Output = DMat3;
1077 #[inline]
1078 fn mul(self, rhs: &DMat3) -> DMat3 {
1079 self.mul(*rhs)
1080 }
1081}
1082
1083impl Mul<&DMat3> for &f64 {
1084 type Output = DMat3;
1085 #[inline]
1086 fn mul(self, rhs: &DMat3) -> DMat3 {
1087 (*self).mul(*rhs)
1088 }
1089}
1090
1091impl Mul<DMat3> for &f64 {
1092 type Output = DMat3;
1093 #[inline]
1094 fn mul(self, rhs: DMat3) -> DMat3 {
1095 (*self).mul(rhs)
1096 }
1097}
1098
1099impl Mul<f64> for DMat3 {
1100 type Output = Self;
1101 #[inline]
1102 fn mul(self, rhs: f64) -> Self {
1103 self.mul_scalar(rhs)
1104 }
1105}
1106
1107impl Mul<&f64> for DMat3 {
1108 type Output = Self;
1109 #[inline]
1110 fn mul(self, rhs: &f64) -> Self {
1111 self.mul(*rhs)
1112 }
1113}
1114
1115impl Mul<&f64> for &DMat3 {
1116 type Output = DMat3;
1117 #[inline]
1118 fn mul(self, rhs: &f64) -> DMat3 {
1119 (*self).mul(*rhs)
1120 }
1121}
1122
1123impl Mul<f64> for &DMat3 {
1124 type Output = DMat3;
1125 #[inline]
1126 fn mul(self, rhs: f64) -> DMat3 {
1127 (*self).mul(rhs)
1128 }
1129}
1130
1131impl MulAssign<f64> for DMat3 {
1132 #[inline]
1133 fn mul_assign(&mut self, rhs: f64) {
1134 *self = self.mul(rhs);
1135 }
1136}
1137
1138impl MulAssign<&f64> for DMat3 {
1139 #[inline]
1140 fn mul_assign(&mut self, rhs: &f64) {
1141 self.mul_assign(*rhs);
1142 }
1143}
1144
1145impl Div<DMat3> for f64 {
1146 type Output = DMat3;
1147 #[inline]
1148 fn div(self, rhs: DMat3) -> Self::Output {
1149 DMat3::from_cols(
1150 self.div(rhs.x_axis),
1151 self.div(rhs.y_axis),
1152 self.div(rhs.z_axis),
1153 )
1154 }
1155}
1156
1157impl Div<&DMat3> for f64 {
1158 type Output = DMat3;
1159 #[inline]
1160 fn div(self, rhs: &DMat3) -> DMat3 {
1161 self.div(*rhs)
1162 }
1163}
1164
1165impl Div<&DMat3> for &f64 {
1166 type Output = DMat3;
1167 #[inline]
1168 fn div(self, rhs: &DMat3) -> DMat3 {
1169 (*self).div(*rhs)
1170 }
1171}
1172
1173impl Div<DMat3> for &f64 {
1174 type Output = DMat3;
1175 #[inline]
1176 fn div(self, rhs: DMat3) -> DMat3 {
1177 (*self).div(rhs)
1178 }
1179}
1180
1181impl Div<f64> for DMat3 {
1182 type Output = Self;
1183 #[inline]
1184 fn div(self, rhs: f64) -> Self {
1185 self.div_scalar(rhs)
1186 }
1187}
1188
1189impl Div<&f64> for DMat3 {
1190 type Output = Self;
1191 #[inline]
1192 fn div(self, rhs: &f64) -> Self {
1193 self.div(*rhs)
1194 }
1195}
1196
1197impl Div<&f64> for &DMat3 {
1198 type Output = DMat3;
1199 #[inline]
1200 fn div(self, rhs: &f64) -> DMat3 {
1201 (*self).div(*rhs)
1202 }
1203}
1204
1205impl Div<f64> for &DMat3 {
1206 type Output = DMat3;
1207 #[inline]
1208 fn div(self, rhs: f64) -> DMat3 {
1209 (*self).div(rhs)
1210 }
1211}
1212
1213impl DivAssign<f64> for DMat3 {
1214 #[inline]
1215 fn div_assign(&mut self, rhs: f64) {
1216 *self = self.div(rhs);
1217 }
1218}
1219
1220impl DivAssign<&f64> for DMat3 {
1221 #[inline]
1222 fn div_assign(&mut self, rhs: &f64) {
1223 self.div_assign(*rhs);
1224 }
1225}
1226
1227impl Sum<Self> for DMat3 {
1228 fn sum<I>(iter: I) -> Self
1229 where
1230 I: Iterator<Item = Self>,
1231 {
1232 iter.fold(Self::ZERO, Self::add)
1233 }
1234}
1235
1236impl<'a> Sum<&'a Self> for DMat3 {
1237 fn sum<I>(iter: I) -> Self
1238 where
1239 I: Iterator<Item = &'a Self>,
1240 {
1241 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1242 }
1243}
1244
1245impl Product for DMat3 {
1246 fn product<I>(iter: I) -> Self
1247 where
1248 I: Iterator<Item = Self>,
1249 {
1250 iter.fold(Self::IDENTITY, Self::mul)
1251 }
1252}
1253
1254impl<'a> Product<&'a Self> for DMat3 {
1255 fn product<I>(iter: I) -> Self
1256 where
1257 I: Iterator<Item = &'a Self>,
1258 {
1259 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
1260 }
1261}
1262
1263impl PartialEq for DMat3 {
1264 #[inline]
1265 fn eq(&self, rhs: &Self) -> bool {
1266 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
1267 }
1268}
1269
1270impl AsRef<[f64; 9]> for DMat3 {
1271 #[inline]
1272 fn as_ref(&self) -> &[f64; 9] {
1273 unsafe { &*(self as *const Self as *const [f64; 9]) }
1274 }
1275}
1276
1277impl AsMut<[f64; 9]> for DMat3 {
1278 #[inline]
1279 fn as_mut(&mut self) -> &mut [f64; 9] {
1280 unsafe { &mut *(self as *mut Self as *mut [f64; 9]) }
1281 }
1282}
1283
1284impl fmt::Debug for DMat3 {
1285 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1286 fmt.debug_struct(stringify!(DMat3))
1287 .field("x_axis", &self.x_axis)
1288 .field("y_axis", &self.y_axis)
1289 .field("z_axis", &self.z_axis)
1290 .finish()
1291 }
1292}
1293
1294impl fmt::Display for DMat3 {
1295 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1296 if let Some(p) = f.precision() {
1297 write!(
1298 f,
1299 "[{:.*}, {:.*}, {:.*}]",
1300 p, self.x_axis, p, self.y_axis, p, self.z_axis
1301 )
1302 } else {
1303 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
1304 }
1305 }
1306}