Debian Codegraph @

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