Debian Codegraph @

debian/missing-sources/glam-0.24.2/src/f32/coresimd/mat3a.rs

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