Debian Codegraph @

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