Debian Codegraph @

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