Debian Codegraph @

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