Debian Codegraph @

debian/missing-sources/glam-0.21.3/src/f32/scalar/mat3a.rs

raw
1 // Generated from mat.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{swizzles::*, DMat3, EulerRot, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A};
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 mat3a(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Mat3A {
16 Mat3A::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 /// [`Affine2`](crate::Affine2) 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 Mat3A {
46 pub x_axis: Vec3A,
47 pub y_axis: Vec3A,
48 pub z_axis: Vec3A,
49 }
50
51 impl Mat3A {
52 /// A 3x3 matrix with all elements set to `0.0`.
53 pub const ZERO: Self = Self::from_cols(Vec3A::ZERO, Vec3A::ZERO, Vec3A::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(Vec3A::X, Vec3A::Y, Vec3A::Z);
57
58 /// All NAN:s.
59 pub const NAN: Self = Self::from_cols(Vec3A::NAN, Vec3A::NAN, Vec3A::NAN);
60
61 #[allow(clippy::too_many_arguments)]
62 #[inline(always)]
63 const fn new(
64 m00: f32,
65 m01: f32,
66 m02: f32,
67 m10: f32,
68 m11: f32,
69 m12: f32,
70 m20: f32,
71 m21: f32,
72 m22: f32,
73 ) -> Self {
74 Self {
75 x_axis: Vec3A::new(m00, m01, m02),
76 y_axis: Vec3A::new(m10, m11, m12),
77 z_axis: Vec3A::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: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Self {
84 Self {
85 x_axis,
86 y_axis,
87 z_axis,
88 }
89 }
90
91 /// Creates a 3x3 matrix from a `[f32; 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: &[f32; 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 `[f32; 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 fn to_cols_array(&self) -> [f32; 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 `[[f32; 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: &[[f32; 3]; 3]) -> Self {
121 Self::from_cols(
122 Vec3A::from_array(m[0]),
123 Vec3A::from_array(m[1]),
124 Vec3A::from_array(m[2]),
125 )
126 }
127
128 /// Creates a `[[f32; 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 fn to_cols_array_2d(&self) -> [[f32; 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 fn from_diagonal(diagonal: Vec3) -> 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: Mat4) -> Self {
150 Self::from_cols(m.x_axis.into(), m.y_axis.into(), m.z_axis.into())
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: Quat) -> 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 Vec3A::new(1.0 - (yy + zz), xy + wz, xz - wy),
177 Vec3A::new(xy - wz, 1.0 - (xx + zz), yz + wx),
178 Vec3A::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: Vec3, angle: f32) -> 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 Vec3A::new(x2 * omc + cos, xyomc + zsin, xzomc - ysin),
202 Vec3A::new(xyomc - zsin, y2 * omc + cos, yzomc + xsin),
203 Vec3A::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: f32, b: f32, c: f32) -> Self {
211 let quat = Quat::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: f32) -> Self {
218 let (sina, cosa) = angle.sin_cos();
219 Self::from_cols(
220 Vec3A::X,
221 Vec3A::new(0.0, cosa, sina),
222 Vec3A::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: f32) -> Self {
229 let (sina, cosa) = angle.sin_cos();
230 Self::from_cols(
231 Vec3A::new(cosa, 0.0, -sina),
232 Vec3A::Y,
233 Vec3A::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: f32) -> Self {
240 let (sina, cosa) = angle.sin_cos();
241 Self::from_cols(
242 Vec3A::new(cosa, sina, 0.0),
243 Vec3A::new(-sina, cosa, 0.0),
244 Vec3A::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: Vec2) -> Self {
254 Self::from_cols(
255 Vec3A::X,
256 Vec3A::Y,
257 Vec3A::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: f32) -> Self {
268 let (sin, cos) = angle.sin_cos();
269 Self::from_cols(
270 Vec3A::new(cos, sin, 0.0),
271 Vec3A::new(-sin, cos, 0.0),
272 Vec3A::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: Vec2, angle: f32, translation: Vec2) -> Self {
283 let (sin, cos) = angle.sin_cos();
284 Self::from_cols(
285 Vec3A::new(cos * scale.x, sin * scale.x, 0.0),
286 Vec3A::new(-sin * scale.y, cos * scale.y, 0.0),
287 Vec3A::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: Vec2) -> Self {
301 // Do not panic as long as any component is non-zero
302 glam_assert!(scale.cmpne(Vec2::ZERO).any());
303
304 Self::from_cols(
305 Vec3A::new(scale.x, 0.0, 0.0),
306 Vec3A::new(0.0, scale.y, 0.0),
307 Vec3A::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: Mat2) -> Self {
317 Self::from_cols((m.x_axis, 0.0).into(), (m.y_axis, 0.0).into(), Vec3A::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: &[f32]) -> 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 [f32]) {
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) -> Vec3A {
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 Vec3A {
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) -> Vec3A {
388 match index {
389 0 => Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
390 1 => Vec3A::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
391 2 => Vec3A::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: Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x),
415 y_axis: Vec3A::new(self.x_axis.y, self.y_axis.y, self.z_axis.y),
416 z_axis: Vec3A::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) -> f32 {
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 = Vec3A::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: Vec2) -> Vec2 {
456 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
457 Mat2::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: Vec2) -> Vec2 {
471 glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6));
472 Mat2::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: Vec3) -> Vec3 {
478 self.mul_vec3a(rhs.into()).into()
479 }
480
481 /// Transforms a `Vec3A`.
482 #[inline]
483 pub fn mul_vec3a(&self, rhs: Vec3A) -> Vec3A {
484 let mut res = self.x_axis.mul(rhs.xxx());
485 res = res.add(self.y_axis.mul(rhs.yyy()));
486 res = res.add(self.z_axis.mul(rhs.zzz()));
487 res
488 }
489
490 /// Multiplies two 3x3 matrices.
491 #[inline]
492 pub fn mul_mat3(&self, rhs: &Self) -> Self {
493 Self::from_cols(
494 self.mul(rhs.x_axis),
495 self.mul(rhs.y_axis),
496 self.mul(rhs.z_axis),
497 )
498 }
499
500 /// Adds two 3x3 matrices.
501 #[inline]
502 pub fn add_mat3(&self, rhs: &Self) -> Self {
503 Self::from_cols(
504 self.x_axis.add(rhs.x_axis),
505 self.y_axis.add(rhs.y_axis),
506 self.z_axis.add(rhs.z_axis),
507 )
508 }
509
510 /// Subtracts two 3x3 matrices.
511 #[inline]
512 pub fn sub_mat3(&self, rhs: &Self) -> Self {
513 Self::from_cols(
514 self.x_axis.sub(rhs.x_axis),
515 self.y_axis.sub(rhs.y_axis),
516 self.z_axis.sub(rhs.z_axis),
517 )
518 }
519
520 /// Multiplies a 3x3 matrix by a scalar.
521 #[inline]
522 pub fn mul_scalar(&self, rhs: f32) -> Self {
523 Self::from_cols(
524 self.x_axis.mul(rhs),
525 self.y_axis.mul(rhs),
526 self.z_axis.mul(rhs),
527 )
528 }
529
530 /// Returns true if the absolute difference of all elements between `self` and `rhs`
531 /// is less than or equal to `max_abs_diff`.
532 ///
533 /// This can be used to compare if two matrices contain similar elements. It works best
534 /// when comparing with a known value. The `max_abs_diff` that should be used used
535 /// depends on the values being compared against.
536 ///
537 /// For more see
538 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
539 #[inline]
540 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
541 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
542 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
543 && self.z_axis.abs_diff_eq(rhs.z_axis, max_abs_diff)
544 }
545
546 #[inline]
547 pub fn as_dmat3(&self) -> DMat3 {
548 DMat3::from_cols(
549 self.x_axis.as_dvec3(),
550 self.y_axis.as_dvec3(),
551 self.z_axis.as_dvec3(),
552 )
553 }
554 }
555
556 impl Default for Mat3A {
557 #[inline]
558 fn default() -> Self {
559 Self::IDENTITY
560 }
561 }
562
563 impl Add<Mat3A> for Mat3A {
564 type Output = Self;
565 #[inline]
566 fn add(self, rhs: Self) -> Self::Output {
567 self.add_mat3(&rhs)
568 }
569 }
570
571 impl AddAssign<Mat3A> for Mat3A {
572 #[inline]
573 fn add_assign(&mut self, rhs: Self) {
574 *self = self.add_mat3(&rhs);
575 }
576 }
577
578 impl Sub<Mat3A> for Mat3A {
579 type Output = Self;
580 #[inline]
581 fn sub(self, rhs: Self) -> Self::Output {
582 self.sub_mat3(&rhs)
583 }
584 }
585
586 impl SubAssign<Mat3A> for Mat3A {
587 #[inline]
588 fn sub_assign(&mut self, rhs: Self) {
589 *self = self.sub_mat3(&rhs);
590 }
591 }
592
593 impl Neg for Mat3A {
594 type Output = Self;
595 #[inline]
596 fn neg(self) -> Self::Output {
597 Self::from_cols(self.x_axis.neg(), self.y_axis.neg(), self.z_axis.neg())
598 }
599 }
600
601 impl Mul<Mat3A> for Mat3A {
602 type Output = Self;
603 #[inline]
604 fn mul(self, rhs: Self) -> Self::Output {
605 self.mul_mat3(&rhs)
606 }
607 }
608
609 impl MulAssign<Mat3A> for Mat3A {
610 #[inline]
611 fn mul_assign(&mut self, rhs: Self) {
612 *self = self.mul_mat3(&rhs);
613 }
614 }
615
616 impl Mul<Vec3A> for Mat3A {
617 type Output = Vec3A;
618 #[inline]
619 fn mul(self, rhs: Vec3A) -> Self::Output {
620 self.mul_vec3a(rhs)
621 }
622 }
623
624 impl Mul<Mat3A> for f32 {
625 type Output = Mat3A;
626 #[inline]
627 fn mul(self, rhs: Mat3A) -> Self::Output {
628 rhs.mul_scalar(self)
629 }
630 }
631
632 impl Mul<f32> for Mat3A {
633 type Output = Self;
634 #[inline]
635 fn mul(self, rhs: f32) -> Self::Output {
636 self.mul_scalar(rhs)
637 }
638 }
639
640 impl MulAssign<f32> for Mat3A {
641 #[inline]
642 fn mul_assign(&mut self, rhs: f32) {
643 *self = self.mul_scalar(rhs);
644 }
645 }
646
647 impl Mul<Vec3> for Mat3A {
648 type Output = Vec3;
649 #[inline]
650 fn mul(self, rhs: Vec3) -> Vec3 {
651 self.mul_vec3a(rhs.into()).into()
652 }
653 }
654
655 impl From<Mat3> for Mat3A {
656 #[inline]
657 fn from(m: Mat3) -> Self {
658 Self {
659 x_axis: m.x_axis.into(),
660 y_axis: m.y_axis.into(),
661 z_axis: m.z_axis.into(),
662 }
663 }
664 }
665
666 impl<'a> Sum<&'a Self> for Mat3A {
667 fn sum<I>(iter: I) -> Self
668 where
669 I: Iterator<Item = &'a Self>,
670 {
671 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
672 }
673 }
674
675 impl<'a> Product<&'a Self> for Mat3A {
676 fn product<I>(iter: I) -> Self
677 where
678 I: Iterator<Item = &'a Self>,
679 {
680 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
681 }
682 }
683
684 impl PartialEq for Mat3A {
685 #[inline]
686 fn eq(&self, rhs: &Self) -> bool {
687 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis) && self.z_axis.eq(&rhs.z_axis)
688 }
689 }
690
691 #[cfg(not(target_arch = "spirv"))]
692 impl fmt::Debug for Mat3A {
693 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
694 fmt.debug_struct(stringify!(Mat3A))
695 .field("x_axis", &self.x_axis)
696 .field("y_axis", &self.y_axis)
697 .field("z_axis", &self.z_axis)
698 .finish()
699 }
700 }
701
702 #[cfg(not(target_arch = "spirv"))]
703 impl fmt::Display for Mat3A {
704 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
705 write!(f, "[{}, {}, {}]", self.x_axis, self.y_axis, self.z_axis)
706 }
707 }