Debian Codegraph @

debian/missing-sources/glam-0.23.0/src/f64/dmat3.rs

raw symbols SCIP
1 // Generated from mat.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{swizzles::*, DMat2, DMat4, DQuat, DVec2, DVec3, EulerRot, Mat3};
4 #[cfg(not(target_arch = "spirv"))]
5 use core::fmt;
6 use core::iter::{Product, Sum};
7 use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
8
9 #[cfg(feature = "libm")]
10 #[allow(unused_imports)]
11 use num_traits::Float;
12
13 /// Creates a 3x3 matrix from column vectors.
14 #[inline(always)]
15 pub const fn dmat3(x_axis: DVec3, y_axis: DVec3, z_axis: DVec3) -> DMat3 {
16 DMat3::from_cols(x_axis, y_axis, z_axis)
17 }
18
19 /// A 3x3 column major matrix.
20 ///
21 /// This 3x3 matrix type features convenience methods for creating and using linear and
22 /// affine transformations. If you are primarily dealing with 2D affine transformations the
23 /// [`DAffine2`](crate::DAffine2) type is much faster and more space efficient than
24 /// using a 3x3 matrix.
25 ///
26 /// Linear transformations including 3D rotation and scale can be created using methods
27 /// such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`],
28 /// [`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or
29 /// [`Self::from_rotation_z()`].
30 ///
31 /// The resulting matrices can be use to transform 3D vectors using regular vector
32 /// multiplication.
33 ///
34 /// Affine transformations including 2D translation, rotation and scale can be created
35 /// using methods such as [`Self::from_translation()`], [`Self::from_angle()`],
36 /// [`Self::from_scale()`] and [`Self::from_scale_angle_translation()`].
37 ///
38 /// The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods
39 /// are provided for performing affine transforms on 2D vectors and points. These multiply
40 /// 2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for
41 /// vectors respectively. These methods assume that `Self` contains a valid affine
42 /// transform.
43 #[derive(Clone, Copy)]
44 #[repr(C)]
45 pub struct DMat3 {
46 pub x_axis: DVec3,
47 pub y_axis: DVec3,
48 pub z_axis: DVec3,
49 }
50
51 impl DMat3 {
52 /// A 3x3 matrix with all elements set to `0.0`.
53 pub const ZERO: Self = Self::from_cols(DVec3::ZERO, DVec3::ZERO, DVec3::ZERO);
54
55 /// A 3x3 identity matrix, where all diagonal elements are `1`, and all off-diagonal elements are `0`.
56 pub const IDENTITY: Self = Self::from_cols(DVec3::X, DVec3::Y, DVec3::Z);
57
58 /// All NAN:s.
59 pub const NAN: Self = Self::from_cols(DVec3::NAN, DVec3::NAN, DVec3::NAN);
60
61 #[allow(clippy::too_many_arguments)]
62 #[inline(always)]
63 const fn new(
64 m00: f64,
65 m01: f64,
66 m02: f64,
67 m10: f64,
68 m11: f64,
69 m12: f64,
70 m20: f64,
71 m21: f64,
72 m22: f64,
73 ) -> Self {
74 Self {
75 x_axis: DVec3::new(m00, m01, m02),
76 y_axis: DVec3::new(m10, m11, m12),
77 z_axis: DVec3::new(m20, m21, m22),
78 }
79 }
80
81 /// Creates a 3x3 matrix from two column vectors.
82 #[inline(always)]
83 pub const fn from_cols(x_axis: DVec3, y_axis: DVec3, z_axis: DVec3) -> Self {
84 Self {
85 x_axis,
86 y_axis,
87 z_axis,
88 }
89 }
90
91 /// Creates a 3x3 matrix from a `[f64; 9]` array stored in column major order.
92 /// If your data is stored in row major you will need to `transpose` the returned
93 /// matrix.
94 #[inline]
95 pub const fn from_cols_array(m: &[f64; 9]) -> Self {
96 Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8])
97 }
98
99 /// Creates a `[f64; 9]` array storing data in column major order.
100 /// If you require data in row major order `transpose` the matrix first.
101 #[inline]
102 pub const fn to_cols_array(&self) -> [f64; 9] {
103 [
104 self.x_axis.x,
105 self.x_axis.y,
106 self.x_axis.z,
107 self.y_axis.x,
108 self.y_axis.y,
109 self.y_axis.z,
110 self.z_axis.x,
111 self.z_axis.y,
112 self.z_axis.z,
113 ]
114 }
115
116 /// Creates a 3x3 matrix from a `[[f64; 3]; 3]` 3D array stored in column major order.
117 /// If your data is in row major order you will need to `transpose` the returned
118 /// matrix.
119 #[inline]
120 pub const fn from_cols_array_2d(m: &[[f64; 3]; 3]) -> Self {
121 Self::from_cols(
122 DVec3::from_array(m[0]),
123 DVec3::from_array(m[1]),
124 DVec3::from_array(m[2]),
125 )
126 }
127
128 /// Creates a `[[f64; 3]; 3]` 3D array storing data in column major order.
129 /// If you require data in row major order `transpose` the matrix first.
130 #[inline]
131 pub const fn to_cols_array_2d(&self) -> [[f64; 3]; 3] {
132 [
133 self.x_axis.to_array(),
134 self.y_axis.to_array(),
135 self.z_axis.to_array(),
136 ]
137 }
138
139 /// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0.
140 #[doc(alias = "scale")]
141 #[inline]
142 pub const fn from_diagonal(diagonal: DVec3) -> Self {
143 Self::new(
144 diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z,
145 )
146 }
147
148 /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column.
149 pub fn from_mat4(m: DMat4) -> Self {
150 Self::from_cols(m.x_axis.xyz(), m.y_axis.xyz(), m.z_axis.xyz())
151 }
152
153 /// Creates a 3D rotation matrix from the given quaternion.
154 ///
155 /// # Panics
156 ///
157 /// Will panic if `rotation` is not normalized when `glam_assert` is enabled.
158 #[inline]
159 pub fn from_quat(rotation: DQuat) -> Self {
160 glam_assert!(rotation.is_normalized());
161
162 let x2 = rotation.x + rotation.x;
163 let y2 = rotation.y + rotation.y;
164 let z2 = rotation.z + rotation.z;
165 let xx = rotation.x * x2;
166 let xy = rotation.x * y2;
167 let xz = rotation.x * z2;
168 let yy = rotation.y * y2;
169 let yz = rotation.y * z2;
170 let zz = rotation.z * z2;
171 let wx = rotation.w * x2;
172 let wy = rotation.w * y2;
173 let wz = rotation.w * z2;
174
175 Self::from_cols(
176 DVec3::new(1.0 - (yy + zz), xy + wz, xz - wy),
177 DVec3::new(xy - wz, 1.0 - (xx + zz), yz + wx),
178 DVec3::new(xz + wy, yz - wx, 1.0 - (xx + yy)),
179 )
180 }
181
182 /// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in
183 /// radians).
184 ///
185 /// # Panics
186 ///
187 /// Will panic if `axis` is not normalized when `glam_assert` is enabled.
188 #[inline]
189 pub fn from_axis_angle(axis: DVec3, angle: f64) -> Self {
190 glam_assert!(axis.is_normalized());
191
192 let (sin, cos) = angle.sin_cos();
193 let (xsin, ysin, zsin) = axis.mul(sin).into();
194 let (x, y, z) = axis.into();
195 let (x2, y2, z2) = axis.mul(axis).into();
196 let omc = 1.0 - cos;
197 let xyomc = x * y * omc;
198 let xzomc = x * z * omc;
199 let yzomc = y * z * omc;
200 Self::from_cols(
201 DVec3::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
202 DVec3::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
203 DVec3::new(xzomc + ysin, yzomc - xsin, z2 * omc + cos),
204 )
205 }
206
207 #[inline]
208 /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in
209 /// radians).
210 pub fn from_euler(order: EulerRot, a: f64, b: f64, c: f64) -> Self {
211 let quat = DQuat::from_euler(order, a, b, c);
212 Self::from_quat(quat)
213 }
214
215 /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
216 #[inline]
217 pub fn from_rotation_x(angle: f64) -> Self {
218 let (sina, cosa) = angle.sin_cos();
219 Self::from_cols(
220 DVec3::X,
221 DVec3::new(0.0, cosa, sina),
222 DVec3::new(0.0, -sina, cosa),
223 )
224 }
225
226 /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis.
227 #[inline]
228 pub fn from_rotation_y(angle: f64) -> Self {
229 let (sina, cosa) = angle.sin_cos();
230 Self::from_cols(
231 DVec3::new(cosa, 0.0, -sina),
232 DVec3::Y,
233 DVec3::new(sina, 0.0, cosa),
234 )
235 }
236
237 /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis.
238 #[inline]
239 pub fn from_rotation_z(angle: f64) -> Self {
240 let (sina, cosa) = angle.sin_cos();
241 Self::from_cols(
242 DVec3::new(cosa, sina, 0.0),
243 DVec3::new(-sina, cosa, 0.0),
244 DVec3::Z,
245 )
246 }
247
248 /// Creates an affine transformation matrix from the given 2D `translation`.
249 ///
250 /// The resulting matrix can be used to transform 2D points and vectors. See
251 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
252 #[inline]
253 pub fn from_translation(translation: DVec2) -> Self {
254 Self::from_cols(
255 DVec3::X,
256 DVec3::Y,
257 DVec3::new(translation.x, translation.y, 1.0),
258 )
259 }
260
261 /// Creates an affine transformation matrix from the given 2D rotation `angle` (in
262 /// radians).
263 ///
264 /// The resulting matrix can be used to transform 2D points and vectors. See
265 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
266 #[inline]
267 pub fn from_angle(angle: f64) -> Self {
268 let (sin, cos) = angle.sin_cos();
269 Self::from_cols(
270 DVec3::new(cos, sin, 0.0),
271 DVec3::new(-sin, cos, 0.0),
272 DVec3::Z,
273 )
274 }
275
276 /// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in
277 /// radians) and `translation`.
278 ///
279 /// The resulting matrix can be used to transform 2D points and vectors. See
280 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
281 #[inline]
282 pub fn from_scale_angle_translation(scale: DVec2, angle: f64, translation: DVec2) -> Self {
283 let (sin, cos) = angle.sin_cos();
284 Self::from_cols(
285 DVec3::new(cos * scale.x, sin * scale.x, 0.0),
286 DVec3::new(-sin * scale.y, cos * scale.y, 0.0),
287 DVec3::new(translation.x, translation.y, 1.0),
288 )
289 }
290
291 /// Creates an affine transformation matrix from the given non-uniform 2D `scale`.
292 ///
293 /// The resulting matrix can be used to transform 2D points and vectors. See
294 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
295 ///
296 /// # Panics
297 ///
298 /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled.
299 #[inline]
300 pub fn from_scale(scale: DVec2) -> Self {
301 // Do not panic as long as any component is non-zero
302 glam_assert!(scale.cmpne(DVec2::ZERO).any());
303
304 Self::from_cols(
305 DVec3::new(scale.x, 0.0, 0.0),
306 DVec3::new(0.0, scale.y, 0.0),
307 DVec3::Z,
308 )
309 }
310
311 /// Creates an affine transformation matrix from the given 2x2 matrix.
312 ///
313 /// The resulting matrix can be used to transform 2D points and vectors. See
314 /// [`Self::transform_point2()`] and [`Self::transform_vector2()`].
315 #[inline]
316 pub fn from_mat2(m: DMat2) -> Self {
317 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), DVec3::Z)
318 }
319
320 /// Creates a 3x3 matrix from the first 9 values in `slice`.
321 ///
322 /// # Panics
323 ///
324 /// Panics if `slice` is less than 9 elements long.
325 #[inline]
326 pub const fn from_cols_slice(slice: &[f64]) -> Self {
327 Self::new(
328 slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7],
329 slice[8],
330 )
331 }
332
333 /// Writes the columns of `self` to the first 9 elements in `slice`.
334 ///
335 /// # Panics
336 ///
337 /// Panics if `slice` is less than 9 elements long.
338 #[inline]
339 pub fn write_cols_to_slice(self, slice: &mut [f64]) {
340 slice[0] = self.x_axis.x;
341 slice[1] = self.x_axis.y;
342 slice[2] = self.x_axis.z;
343 slice[3] = self.y_axis.x;
344 slice[4] = self.y_axis.y;
345 slice[5] = self.y_axis.z;
346 slice[6] = self.z_axis.x;
347 slice[7] = self.z_axis.y;
348 slice[8] = self.z_axis.z;
349 }
350
351 /// Returns the matrix column for the given `index`.
352 ///
353 /// # Panics
354 ///
355 /// Panics if `index` is greater than 2.
356 #[inline]
357 pub fn col(&self, index: usize) -> DVec3 {
358 match index {
359 0 => self.x_axis,
360 1 => self.y_axis,
361 2 => self.z_axis,
362 _ => panic!("index out of bounds"),
363 }
364 }
365
366 /// Returns a mutable reference to the matrix column for the given `index`.
367 ///
368 /// # Panics
369 ///
370 /// Panics if `index` is greater than 2.
371 #[inline]
372 pub fn col_mut(&mut self, index: usize) -> &mut DVec3 {
373 match index {
374 0 => &mut self.x_axis,
375 1 => &mut self.y_axis,
376 2 => &mut self.z_axis,
377 _ => panic!("index out of bounds"),
378 }
379 }
380
381 /// Returns the matrix row for the given `index`.
382 ///
383 /// # Panics
384 ///
385 /// Panics if `index` is greater than 2.
386 #[inline]
387 pub fn row(&self, index: usize) -> DVec3 {
388 match index {
389 0 => DVec3::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
390 1 => DVec3::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
391 2 => DVec3::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
392 _ => panic!("index out of bounds"),
393 }
394 }
395
396 /// Returns `true` if, and only if, all elements are finite.
397 /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
398 #[inline]
399 pub fn is_finite(&self) -> bool {
400 self.x_axis.is_finite() && self.y_axis.is_finite() && self.z_axis.is_finite()
401 }
402
403 /// Returns `true` if any elements are `NaN`.
404 #[inline]
405 pub fn is_nan(&self) -> bool {
406 self.x_axis.is_nan() || self.y_axis.is_nan() || self.z_axis.is_nan()
407 }
408
409 /// Returns the transpose of `self`.
410 #[must_use]
411 #[inline]
412 pub fn transpose(&self) -> Self {
413 Self {
414 x_axis: DVec3::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
415 y_axis: DVec3::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
416 z_axis: DVec3::new(self.x_axis.z, self.y_axis.z, self.z_axis.z),
417 }
418 }
419
420 /// Returns the determinant of `self`.
421 #[inline]
422 pub fn determinant(&self) -> f64 {
423 self.z_axis.dot(self.x_axis.cross(self.y_axis))
424 }
425
426 /// Returns the inverse of `self`.
427 ///
428 /// If the matrix is not invertible the returned matrix will be invalid.
429 ///
430 /// # Panics
431 ///
432 /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled.
433 #[must_use]
434 #[inline]
435 pub fn inverse(&self) -> Self {
436 let tmp0 = self.y_axis.cross(self.z_axis);
437 let tmp1 = self.z_axis.cross(self.x_axis);
438 let tmp2 = self.x_axis.cross(self.y_axis);
439 let det = self.z_axis.dot(tmp2);
440 glam_assert!(det != 0.0);
441 let inv_det = DVec3::splat(det.recip());
442 Self::from_cols(tmp0.mul(inv_det), tmp1.mul(inv_det), tmp2.mul(inv_det)).transpose()
443 }
444
445 /// Transforms the given 2D vector as a point.
446 ///
447 /// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`.
448 ///
449 /// This method assumes that `self` contains a valid affine transform.
450 ///
451 /// # Panics
452 ///
453 /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled.
454 #[inline]
455 pub fn transform_point2(&self, rhs: DVec2) -> DVec2 {
456 glam_assert!(self.row(2).abs_diff_eq(DVec3::Z, 1e-6));
457 DMat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy()
458 }
459
460 /// Rotates the given 2D vector.
461 ///
462 /// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`.
463 ///
464 /// This method assumes that `self` contains a valid affine transform.
465 ///
466 /// # Panics
467 ///
468 /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled.
469 #[inline]
470 pub fn transform_vector2(&self, rhs: DVec2) -> DVec2 {
471 glam_assert!(self.row(2).abs_diff_eq(DVec3::Z, 1e-6));
472 DMat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs
473 }
474
475 /// Transforms a 3D vector.
476 #[inline]
477 pub fn mul_vec3(&self, rhs: DVec3) -> DVec3 {
478 let mut res = self.x_axis.mul(rhs.x);
479 res = res.add(self.y_axis.mul(rhs.y));
480 res = res.add(self.z_axis.mul(rhs.z));
481 res
482 }
483
484 /// Multiplies two 3x3 matrices.
485 #[inline]
486 pub fn mul_mat3(&self, rhs: &Self) -> Self {
487 Self::from_cols(
488 self.mul(rhs.x_axis),
489 self.mul(rhs.y_axis),
490 self.mul(rhs.z_axis),
491 )
492 }
493
494 /// Adds two 3x3 matrices.
495 #[inline]
496 pub fn add_mat3(&self, rhs: &Self) -> Self {
497 Self::from_cols(
498 self.x_axis.add(rhs.x_axis),
499 self.y_axis.add(rhs.y_axis),
500 self.z_axis.add(rhs.z_axis),
501 )
502 }
503
504 /// Subtracts two 3x3 matrices.
505 #[inline]
506 pub fn sub_mat3(&self, rhs: &Self) -> Self {
507 Self::from_cols(
508 self.x_axis.sub(rhs.x_axis),
509 self.y_axis.sub(rhs.y_axis),
510 self.z_axis.sub(rhs.z_axis),
511 )
512 }
513
514 /// Multiplies a 3x3 matrix by a scalar.
515 #[inline]
516 pub fn mul_scalar(&self, rhs: f64) -> Self {
517 Self::from_cols(
518 self.x_axis.mul(rhs),
519 self.y_axis.mul(rhs),
520 self.z_axis.mul(rhs),
521 )
522 }
523
524 /// Returns true if the absolute difference of all elements between `self` and `rhs`
525 /// is less than or equal to `max_abs_diff`.
526 ///
527 /// This can be used to compare if two matrices contain similar elements. It works best
528 /// when comparing with a known value. The `max_abs_diff` that should be used used
529 /// depends on the values being compared against.
530 ///
531 /// For more see
532 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
533 #[inline]
534 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f64) -> bool {
535 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
536 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
537 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
538 }
539
540 #[inline]
541 pub fn as_mat3(&self) -> Mat3 {
542 Mat3::from_cols(
543 self.x_axis.as_vec3(),
544 self.y_axis.as_vec3(),
545 self.z_axis.as_vec3(),
546 )
547 }
548 }
549
550 impl Default for DMat3 {
551 #[inline]
552 fn default() -> Self {
553 Self::IDENTITY
554 }
555 }
556
557 impl Add<DMat3> for DMat3 {
558 type Output = Self;
559 #[inline]
560 fn add(self, rhs: Self) -> Self::Output {
561 self.add_mat3(&rhs)
562 }
563 }
564
565 impl AddAssign<DMat3> for DMat3 {
566 #[inline]
567 fn add_assign(&mut self, rhs: Self) {
568 *self = self.add_mat3(&rhs);
569 }
570 }
571
572 impl Sub<DMat3> for DMat3 {
573 type Output = Self;
574 #[inline]
575 fn sub(self, rhs: Self) -> Self::Output {
576 self.sub_mat3(&rhs)
577 }
578 }
579
580 impl SubAssign<DMat3> for DMat3 {
581 #[inline]
582 fn sub_assign(&mut self, rhs: Self) {
583 *self = self.sub_mat3(&rhs);
584 }
585 }
586
587 impl Neg for DMat3 {
588 type Output = Self;
589 #[inline]
590 fn neg(self) -> Self::Output {
591 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
592 }
593 }
594
595 impl Mul<DMat3> for DMat3 {
596 type Output = Self;
597 #[inline]
598 fn mul(self, rhs: Self) -> Self::Output {
599 self.mul_mat3(&rhs)
600 }
601 }
602
603 impl MulAssign<DMat3> for DMat3 {
604 #[inline]
605 fn mul_assign(&mut self, rhs: Self) {
606 *self = self.mul_mat3(&rhs);
607 }
608 }
609
610 impl Mul<DVec3> for DMat3 {
611 type Output = DVec3;
612 #[inline]
613 fn mul(self, rhs: DVec3) -> Self::Output {
614 self.mul_vec3(rhs)
615 }
616 }
617
618 impl Mul<DMat3> for f64 {
619 type Output = DMat3;
620 #[inline]
621 fn mul(self, rhs: DMat3) -> Self::Output {
622 rhs.mul_scalar(self)
623 }
624 }
625
626 impl Mul<f64> for DMat3 {
627 type Output = Self;
628 #[inline]
629 fn mul(self, rhs: f64) -> Self::Output {
630 self.mul_scalar(rhs)
631 }
632 }
633
634 impl MulAssign<f64> for DMat3 {
635 #[inline]
636 fn mul_assign(&mut self, rhs: f64) {
637 *self = self.mul_scalar(rhs);
638 }
639 }
640
641 impl Sum<Self> for DMat3 {
642 fn sum<I>(iter: I) -> Self
643 where
644 I: Iterator<Item = Self>,
645 {
646 iter.fold(Self::ZERO, Self::add)
647 }
648 }
649
650 impl<'a> Sum<&'a Self> for DMat3 {
651 fn sum<I>(iter: I) -> Self
652 where
653 I: Iterator<Item = &'a Self>,
654 {
655 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
656 }
657 }
658
659 impl Product for DMat3 {
660 fn product<I>(iter: I) -> Self
661 where
662 I: Iterator<Item = Self>,
663 {
664 iter.fold(Self::IDENTITY, Self::mul)
665 }
666 }
667
668 impl<'a> Product<&'a Self> for DMat3 {
669 fn product<I>(iter: I) -> Self
670 where
671 I: Iterator<Item = &'a Self>,
672 {
673 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
674 }
675 }
676
677 impl PartialEq for DMat3 {
678 #[inline]
679 fn eq(&self, rhs: &Self) -> bool {
680 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
681 }
682 }
683
684 #[cfg(not(target_arch = "spirv"))]
685 impl AsRef<[f64; 9]> for DMat3 {
686 #[inline]
687 fn as_ref(&self) -> &[f64; 9] {
688 unsafe { &*(self as *const Self as *const [f64; 9]) }
689 }
690 }
691
692 #[cfg(not(target_arch = "spirv"))]
693 impl AsMut<[f64; 9]> for DMat3 {
694 #[inline]
695 fn as_mut(&mut self) -> &mut [f64; 9] {
696 unsafe { &mut *(self as *mut Self as *mut [f64; 9]) }
697 }
698 }
699
700 #[cfg(not(target_arch = "spirv"))]
701 impl fmt::Debug for DMat3 {
702 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
703 fmt.debug_struct(stringify!(DMat3))
704 .field("x_axis", &self.x_axis)
705 .field("y_axis", &self.y_axis)
706 .field("z_axis", &self.z_axis)
707 .finish()
708 }
709 }
710
711 #[cfg(not(target_arch = "spirv"))]
712 impl fmt::Display for DMat3 {
713 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
714 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
715 }
716 }