Debian Codegraph @

debian/missing-sources/glam/src/f32/wasm32/mat2.rs

raw
1 // Generated from mat.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{f32::math, swizzles::*, DMat2, Mat3, Mat3A, Vec2};
4 use core::fmt;
5 use core::iter::{Product, Sum};
6 use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
7
8 use core::arch::wasm32::*;
9
10 #[cfg(feature = "zerocopy")]
11 use zerocopy_derive::*;
12
13 /// Creates a 2x2 matrix from two column vectors.
14 #[inline(always)]
15 #[must_use]
16 pub const fn mat2(x_axis: Vec2, y_axis: Vec2) -> Mat2 {
17 Mat2::from_cols(x_axis, y_axis)
18 }
19
20 /// A 2x2 column major matrix.
21 ///
22 /// SIMD vector types are used for storage on supported platforms.
23 ///
24 /// This type is 16 byte aligned.
25 #[derive(Clone, Copy)]
26 #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
27 #[cfg_attr(
28 feature = "zerocopy",
29 derive(FromBytes, Immutable, IntoBytes, KnownLayout)
30 )]
31 #[repr(transparent)]
32 pub struct Mat2(pub(crate) v128);
33
34 impl Mat2 {
35 /// A 2x2 matrix with all elements set to `0.0`.
36 pub const ZERO: Self = Self::from_cols(Vec2::ZERO, Vec2::ZERO);
37
38 /// A 2x2 identity matrix, where all diagonal elements are `1`, and all off-diagonal elements are `0`.
39 pub const IDENTITY: Self = Self::from_cols(Vec2::X, Vec2::Y);
40
41 /// All NAN:s.
42 pub const NAN: Self = Self::from_cols(Vec2::NAN, Vec2::NAN);
43
44 #[allow(clippy::too_many_arguments)]
45 #[inline(always)]
46 #[must_use]
47 const fn new(m00: f32, m01: f32, m10: f32, m11: f32) -> Self {
48 Self(f32x4(m00, m01, m10, m11))
49 }
50
51 /// Creates a 2x2 matrix from two column vectors.
52 #[inline(always)]
53 #[must_use]
54 pub const fn from_cols(x_axis: Vec2, y_axis: Vec2) -> Self {
55 Self(f32x4(x_axis.x, x_axis.y, y_axis.x, y_axis.y))
56 }
57
58 /// Creates a 2x2 matrix from a `[f32; 4]` array stored in column major order.
59 /// If your data is stored in row major you will need to `transpose` the returned
60 /// matrix.
61 #[inline]
62 #[must_use]
63 pub const fn from_cols_array(m: &[f32; 4]) -> Self {
64 Self::new(m[0], m[1], m[2], m[3])
65 }
66
67 /// Creates a `[f32; 4]` array storing data in column major order.
68 /// If you require data in row major order `transpose` the matrix first.
69 #[inline]
70 #[must_use]
71 pub const fn to_cols_array(&self) -> [f32; 4] {
72 unsafe { *(self as *const Self as *const [f32; 4]) }
73 }
74
75 /// Creates a 2x2 matrix from a `[[f32; 2]; 2]` 2D array stored in column major order.
76 /// If your data is in row major order you will need to `transpose` the returned
77 /// matrix.
78 #[inline]
79 #[must_use]
80 pub const fn from_cols_array_2d(m: &[[f32; 2]; 2]) -> Self {
81 Self::from_cols(Vec2::from_array(m[0]), Vec2::from_array(m[1]))
82 }
83
84 /// Creates a `[[f32; 2]; 2]` 2D array storing data in column major order.
85 /// If you require data in row major order `transpose` the matrix first.
86 #[inline]
87 #[must_use]
88 pub const fn to_cols_array_2d(&self) -> [[f32; 2]; 2] {
89 unsafe { *(self as *const Self as *const [[f32; 2]; 2]) }
90 }
91
92 /// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0.
93 #[doc(alias = "scale")]
94 #[inline]
95 #[must_use]
96 pub const fn from_diagonal(diagonal: Vec2) -> Self {
97 Self::new(diagonal.x, 0.0, 0.0, diagonal.y)
98 }
99
100 /// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of
101 /// `angle` (in radians).
102 #[inline]
103 #[must_use]
104 pub fn from_scale_angle(scale: Vec2, angle: f32) -> Self {
105 let (sin, cos) = math::sin_cos(angle);
106 Self::new(cos * scale.x, sin * scale.x, -sin * scale.y, cos * scale.y)
107 }
108
109 /// Creates a 2x2 matrix containing a rotation of `angle` (in radians).
110 #[inline]
111 #[must_use]
112 pub fn from_angle(angle: f32) -> Self {
113 let (sin, cos) = math::sin_cos(angle);
114 Self::new(cos, sin, -sin, cos)
115 }
116
117 /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column.
118 #[inline]
119 #[must_use]
120 pub fn from_mat3(m: Mat3) -> Self {
121 Self::from_cols(m.x_axis.xy(), m.y_axis.xy())
122 }
123
124 /// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column
125 /// and `j`th row.
126 ///
127 /// # Panics
128 ///
129 /// Panics if `i` or `j` is greater than 2.
130 #[inline]
131 #[must_use]
132 pub fn from_mat3_minor(m: Mat3, i: usize, j: usize) -> Self {
133 match (i, j) {
134 (0, 0) => Self::from_cols(m.y_axis.yz(), m.z_axis.yz()),
135 (0, 1) => Self::from_cols(m.y_axis.xz(), m.z_axis.xz()),
136 (0, 2) => Self::from_cols(m.y_axis.xy(), m.z_axis.xy()),
137 (1, 0) => Self::from_cols(m.x_axis.yz(), m.z_axis.yz()),
138 (1, 1) => Self::from_cols(m.x_axis.xz(), m.z_axis.xz()),
139 (1, 2) => Self::from_cols(m.x_axis.xy(), m.z_axis.xy()),
140 (2, 0) => Self::from_cols(m.x_axis.yz(), m.y_axis.yz()),
141 (2, 1) => Self::from_cols(m.x_axis.xz(), m.y_axis.xz()),
142 (2, 2) => Self::from_cols(m.x_axis.xy(), m.y_axis.xy()),
143 _ => panic!("index out of bounds"),
144 }
145 }
146
147 /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column.
148 #[inline]
149 #[must_use]
150 pub fn from_mat3a(m: Mat3A) -> Self {
151 Self::from_cols(m.x_axis.xy(), m.y_axis.xy())
152 }
153
154 /// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column
155 /// and `j`th row.
156 ///
157 /// # Panics
158 ///
159 /// Panics if `i` or `j` is greater than 2.
160 #[inline]
161 #[must_use]
162 pub fn from_mat3a_minor(m: Mat3A, i: usize, j: usize) -> Self {
163 match (i, j) {
164 (0, 0) => Self::from_cols(m.y_axis.yz(), m.z_axis.yz()),
165 (0, 1) => Self::from_cols(m.y_axis.xz(), m.z_axis.xz()),
166 (0, 2) => Self::from_cols(m.y_axis.xy(), m.z_axis.xy()),
167 (1, 0) => Self::from_cols(m.x_axis.yz(), m.z_axis.yz()),
168 (1, 1) => Self::from_cols(m.x_axis.xz(), m.z_axis.xz()),
169 (1, 2) => Self::from_cols(m.x_axis.xy(), m.z_axis.xy()),
170 (2, 0) => Self::from_cols(m.x_axis.yz(), m.y_axis.yz()),
171 (2, 1) => Self::from_cols(m.x_axis.xz(), m.y_axis.xz()),
172 (2, 2) => Self::from_cols(m.x_axis.xy(), m.y_axis.xy()),
173 _ => panic!("index out of bounds"),
174 }
175 }
176
177 /// Creates a 2x2 matrix from the first 4 values in `slice`.
178 ///
179 /// # Panics
180 ///
181 /// Panics if `slice` is less than 4 elements long.
182 #[inline]
183 #[must_use]
184 pub const fn from_cols_slice(slice: &[f32]) -> Self {
185 Self::new(slice[0], slice[1], slice[2], slice[3])
186 }
187
188 /// Writes the columns of `self` to the first 4 elements in `slice`.
189 ///
190 /// # Panics
191 ///
192 /// Panics if `slice` is less than 4 elements long.
193 #[inline]
194 pub fn write_cols_to_slice(self, slice: &mut [f32]) {
195 slice[0] = self.x_axis.x;
196 slice[1] = self.x_axis.y;
197 slice[2] = self.y_axis.x;
198 slice[3] = self.y_axis.y;
199 }
200
201 /// Returns the matrix column for the given `index`.
202 ///
203 /// # Panics
204 ///
205 /// Panics if `index` is greater than 1.
206 #[inline]
207 #[must_use]
208 pub fn col(&self, index: usize) -> Vec2 {
209 match index {
210 0 => self.x_axis,
211 1 => self.y_axis,
212 _ => panic!("index out of bounds"),
213 }
214 }
215
216 /// Returns a mutable reference to the matrix column for the given `index`.
217 ///
218 /// # Panics
219 ///
220 /// Panics if `index` is greater than 1.
221 #[inline]
222 pub fn col_mut(&mut self, index: usize) -> &mut Vec2 {
223 match index {
224 0 => &mut self.x_axis,
225 1 => &mut self.y_axis,
226 _ => panic!("index out of bounds"),
227 }
228 }
229
230 /// Returns the matrix row for the given `index`.
231 ///
232 /// # Panics
233 ///
234 /// Panics if `index` is greater than 1.
235 #[inline]
236 #[must_use]
237 pub fn row(&self, index: usize) -> Vec2 {
238 match index {
239 0 => Vec2::new(self.x_axis.x, self.y_axis.x),
240 1 => Vec2::new(self.x_axis.y, self.y_axis.y),
241 _ => panic!("index out of bounds"),
242 }
243 }
244
245 /// Returns `true` if, and only if, all elements are finite.
246 /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
247 #[inline]
248 #[must_use]
249 pub fn is_finite(&self) -> bool {
250 self.x_axis.is_finite() && self.y_axis.is_finite()
251 }
252
253 /// Returns `true` if any elements are `NaN`.
254 #[inline]
255 #[must_use]
256 pub fn is_nan(&self) -> bool {
257 self.x_axis.is_nan() || self.y_axis.is_nan()
258 }
259
260 /// Returns the transpose of `self`.
261 #[inline]
262 #[must_use]
263 pub fn transpose(&self) -> Self {
264 Self(i32x4_shuffle::<0, 2, 5, 7>(self.0, self.0))
265 }
266
267 /// Returns the determinant of `self`.
268 #[inline]
269 #[must_use]
270 pub fn determinant(&self) -> f32 {
271 let abcd = self.0;
272 let dcba = i32x4_shuffle::<3, 2, 5, 4>(abcd, abcd);
273 let prod = f32x4_mul(abcd, dcba);
274 let det = f32x4_sub(prod, i32x4_shuffle::<1, 1, 5, 5>(prod, prod));
275 f32x4_extract_lane::<0>(det)
276 }
277
278 /// Returns the inverse of `self`.
279 ///
280 /// If the matrix is not invertible the returned matrix will be invalid.
281 ///
282 /// # Panics
283 ///
284 /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled.
285 #[inline]
286 #[must_use]
287 pub fn inverse(&self) -> Self {
288 const SIGN: v128 = crate::wasm32::v128_from_f32x4([1.0, -1.0, -1.0, 1.0]);
289 let abcd = self.0;
290 let dcba = i32x4_shuffle::<3, 2, 5, 4>(abcd, abcd);
291 let prod = f32x4_mul(abcd, dcba);
292 let sub = f32x4_sub(prod, i32x4_shuffle::<1, 1, 5, 5>(prod, prod));
293 let det = i32x4_shuffle::<0, 0, 4, 4>(sub, sub);
294 let tmp = f32x4_div(SIGN, det);
295 glam_assert!(Mat2(tmp).is_finite());
296 let dbca = i32x4_shuffle::<3, 1, 6, 4>(abcd, abcd);
297 Self(f32x4_mul(dbca, tmp))
298 }
299
300 /// Transforms a 2D vector.
301 #[inline]
302 #[must_use]
303 pub fn mul_vec2(&self, rhs: Vec2) -> Vec2 {
304 use core::mem::MaybeUninit;
305 let abcd = self.0;
306 let xxyy = f32x4(rhs.x, rhs.x, rhs.y, rhs.y);
307 let axbxcydy = f32x4_mul(abcd, xxyy);
308 let cydyaxbx = i32x4_shuffle::<2, 3, 4, 5>(axbxcydy, axbxcydy);
309 let result = f32x4_add(axbxcydy, cydyaxbx);
310 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
311 unsafe {
312 v128_store(out.as_mut_ptr(), result);
313 *(&out.assume_init() as *const v128 as *const Vec2)
314 }
315 }
316
317 /// Multiplies two 2x2 matrices.
318 #[inline]
319 #[must_use]
320 pub fn mul_mat2(&self, rhs: &Self) -> Self {
321 self.mul(rhs)
322 }
323
324 /// Adds two 2x2 matrices.
325 #[inline]
326 #[must_use]
327 pub fn add_mat2(&self, rhs: &Self) -> Self {
328 self.add(rhs)
329 }
330
331 /// Subtracts two 2x2 matrices.
332 #[inline]
333 #[must_use]
334 pub fn sub_mat2(&self, rhs: &Self) -> Self {
335 self.sub(rhs)
336 }
337
338 /// Multiplies a 2x2 matrix by a scalar.
339 #[inline]
340 #[must_use]
341 pub fn mul_scalar(&self, rhs: f32) -> Self {
342 Self(f32x4_mul(self.0, f32x4_splat(rhs)))
343 }
344
345 /// Divides a 2x2 matrix by a scalar.
346 #[inline]
347 #[must_use]
348 pub fn div_scalar(&self, rhs: f32) -> Self {
349 Self(f32x4_div(self.0, f32x4_splat(rhs)))
350 }
351
352 /// Returns true if the absolute difference of all elements between `self` and `rhs`
353 /// is less than or equal to `max_abs_diff`.
354 ///
355 /// This can be used to compare if two matrices contain similar elements. It works best
356 /// when comparing with a known value. The `max_abs_diff` that should be used used
357 /// depends on the values being compared against.
358 ///
359 /// For more see
360 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
361 #[inline]
362 #[must_use]
363 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
364 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
365 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
366 }
367
368 /// Takes the absolute value of each element in `self`
369 #[inline]
370 #[must_use]
371 pub fn abs(&self) -> Self {
372 Self::from_cols(self.x_axis.abs(), self.y_axis.abs())
373 }
374
375 #[inline]
376 pub fn as_dmat2(&self) -> DMat2 {
377 DMat2::from_cols(self.x_axis.as_dvec2(), self.y_axis.as_dvec2())
378 }
379 }
380
381 impl Default for Mat2 {
382 #[inline]
383 fn default() -> Self {
384 Self::IDENTITY
385 }
386 }
387
388 impl Add for Mat2 {
389 type Output = Self;
390 #[inline]
391 fn add(self, rhs: Self) -> Self {
392 Self(f32x4_add(self.0, rhs.0))
393 }
394 }
395
396 impl Add<&Self> for Mat2 {
397 type Output = Self;
398 #[inline]
399 fn add(self, rhs: &Self) -> Self {
400 self.add(*rhs)
401 }
402 }
403
404 impl Add<&Mat2> for &Mat2 {
405 type Output = Mat2;
406 #[inline]
407 fn add(self, rhs: &Mat2) -> Mat2 {
408 (*self).add(*rhs)
409 }
410 }
411
412 impl Add<Mat2> for &Mat2 {
413 type Output = Mat2;
414 #[inline]
415 fn add(self, rhs: Mat2) -> Mat2 {
416 (*self).add(rhs)
417 }
418 }
419
420 impl AddAssign for Mat2 {
421 #[inline]
422 fn add_assign(&mut self, rhs: Self) {
423 *self = self.add(rhs);
424 }
425 }
426
427 impl AddAssign<&Self> for Mat2 {
428 #[inline]
429 fn add_assign(&mut self, rhs: &Self) {
430 self.add_assign(*rhs);
431 }
432 }
433
434 impl Sub for Mat2 {
435 type Output = Self;
436 #[inline]
437 fn sub(self, rhs: Self) -> Self {
438 Self(f32x4_sub(self.0, rhs.0))
439 }
440 }
441
442 impl Sub<&Self> for Mat2 {
443 type Output = Self;
444 #[inline]
445 fn sub(self, rhs: &Self) -> Self {
446 self.sub(*rhs)
447 }
448 }
449
450 impl Sub<&Mat2> for &Mat2 {
451 type Output = Mat2;
452 #[inline]
453 fn sub(self, rhs: &Mat2) -> Mat2 {
454 (*self).sub(*rhs)
455 }
456 }
457
458 impl Sub<Mat2> for &Mat2 {
459 type Output = Mat2;
460 #[inline]
461 fn sub(self, rhs: Mat2) -> Mat2 {
462 (*self).sub(rhs)
463 }
464 }
465
466 impl SubAssign for Mat2 {
467 #[inline]
468 fn sub_assign(&mut self, rhs: Self) {
469 *self = self.sub(rhs);
470 }
471 }
472
473 impl SubAssign<&Self> for Mat2 {
474 #[inline]
475 fn sub_assign(&mut self, rhs: &Self) {
476 self.sub_assign(*rhs);
477 }
478 }
479
480 impl Neg for Mat2 {
481 type Output = Self;
482 #[inline]
483 fn neg(self) -> Self::Output {
484 Self(f32x4_neg(self.0))
485 }
486 }
487
488 impl Neg for &Mat2 {
489 type Output = Mat2;
490 #[inline]
491 fn neg(self) -> Mat2 {
492 (*self).neg()
493 }
494 }
495
496 impl Mul for Mat2 {
497 type Output = Self;
498 #[inline]
499 fn mul(self, rhs: Self) -> Self {
500 let abcd = self.0;
501 let rhs = rhs.0;
502 let xxyy0 = i32x4_shuffle::<0, 0, 5, 5>(rhs, rhs);
503 let xxyy1 = i32x4_shuffle::<2, 2, 7, 7>(rhs, rhs);
504 let axbxcydy0 = f32x4_mul(abcd, xxyy0);
505 let axbxcydy1 = f32x4_mul(abcd, xxyy1);
506 let cydyaxbx0 = i32x4_shuffle::<2, 3, 4, 5>(axbxcydy0, axbxcydy0);
507 let cydyaxbx1 = i32x4_shuffle::<2, 3, 4, 5>(axbxcydy1, axbxcydy1);
508 let result0 = f32x4_add(axbxcydy0, cydyaxbx0);
509 let result1 = f32x4_add(axbxcydy1, cydyaxbx1);
510 Self(i32x4_shuffle::<0, 1, 4, 5>(result0, result1))
511 }
512 }
513
514 impl Mul<&Self> for Mat2 {
515 type Output = Self;
516 #[inline]
517 fn mul(self, rhs: &Self) -> Self {
518 self.mul(*rhs)
519 }
520 }
521
522 impl Mul<&Mat2> for &Mat2 {
523 type Output = Mat2;
524 #[inline]
525 fn mul(self, rhs: &Mat2) -> Mat2 {
526 (*self).mul(*rhs)
527 }
528 }
529
530 impl Mul<Mat2> for &Mat2 {
531 type Output = Mat2;
532 #[inline]
533 fn mul(self, rhs: Mat2) -> Mat2 {
534 (*self).mul(rhs)
535 }
536 }
537
538 impl MulAssign for Mat2 {
539 #[inline]
540 fn mul_assign(&mut self, rhs: Self) {
541 *self = self.mul(rhs);
542 }
543 }
544
545 impl MulAssign<&Self> for Mat2 {
546 #[inline]
547 fn mul_assign(&mut self, rhs: &Self) {
548 self.mul_assign(*rhs);
549 }
550 }
551
552 impl Mul<Vec2> for Mat2 {
553 type Output = Vec2;
554 #[inline]
555 fn mul(self, rhs: Vec2) -> Self::Output {
556 self.mul_vec2(rhs)
557 }
558 }
559
560 impl Mul<&Vec2> for Mat2 {
561 type Output = Vec2;
562 #[inline]
563 fn mul(self, rhs: &Vec2) -> Vec2 {
564 self.mul(*rhs)
565 }
566 }
567
568 impl Mul<&Vec2> for &Mat2 {
569 type Output = Vec2;
570 #[inline]
571 fn mul(self, rhs: &Vec2) -> Vec2 {
572 (*self).mul(*rhs)
573 }
574 }
575
576 impl Mul<Vec2> for &Mat2 {
577 type Output = Vec2;
578 #[inline]
579 fn mul(self, rhs: Vec2) -> Vec2 {
580 (*self).mul(rhs)
581 }
582 }
583
584 impl Mul<Mat2> for f32 {
585 type Output = Mat2;
586 #[inline]
587 fn mul(self, rhs: Mat2) -> Self::Output {
588 rhs.mul_scalar(self)
589 }
590 }
591
592 impl Mul<&Mat2> for f32 {
593 type Output = Mat2;
594 #[inline]
595 fn mul(self, rhs: &Mat2) -> Mat2 {
596 self.mul(*rhs)
597 }
598 }
599
600 impl Mul<&Mat2> for &f32 {
601 type Output = Mat2;
602 #[inline]
603 fn mul(self, rhs: &Mat2) -> Mat2 {
604 (*self).mul(*rhs)
605 }
606 }
607
608 impl Mul<Mat2> for &f32 {
609 type Output = Mat2;
610 #[inline]
611 fn mul(self, rhs: Mat2) -> Mat2 {
612 (*self).mul(rhs)
613 }
614 }
615
616 impl Mul<f32> for Mat2 {
617 type Output = Self;
618 #[inline]
619 fn mul(self, rhs: f32) -> Self {
620 self.mul_scalar(rhs)
621 }
622 }
623
624 impl Mul<&f32> for Mat2 {
625 type Output = Self;
626 #[inline]
627 fn mul(self, rhs: &f32) -> Self {
628 self.mul(*rhs)
629 }
630 }
631
632 impl Mul<&f32> for &Mat2 {
633 type Output = Mat2;
634 #[inline]
635 fn mul(self, rhs: &f32) -> Mat2 {
636 (*self).mul(*rhs)
637 }
638 }
639
640 impl Mul<f32> for &Mat2 {
641 type Output = Mat2;
642 #[inline]
643 fn mul(self, rhs: f32) -> Mat2 {
644 (*self).mul(rhs)
645 }
646 }
647
648 impl MulAssign<f32> for Mat2 {
649 #[inline]
650 fn mul_assign(&mut self, rhs: f32) {
651 *self = self.mul(rhs);
652 }
653 }
654
655 impl MulAssign<&f32> for Mat2 {
656 #[inline]
657 fn mul_assign(&mut self, rhs: &f32) {
658 self.mul_assign(*rhs);
659 }
660 }
661
662 impl Div<Mat2> for f32 {
663 type Output = Mat2;
664 #[inline]
665 fn div(self, rhs: Mat2) -> Self::Output {
666 rhs.div_scalar(self)
667 }
668 }
669
670 impl Div<&Mat2> for f32 {
671 type Output = Mat2;
672 #[inline]
673 fn div(self, rhs: &Mat2) -> Mat2 {
674 self.div(*rhs)
675 }
676 }
677
678 impl Div<&Mat2> for &f32 {
679 type Output = Mat2;
680 #[inline]
681 fn div(self, rhs: &Mat2) -> Mat2 {
682 (*self).div(*rhs)
683 }
684 }
685
686 impl Div<Mat2> for &f32 {
687 type Output = Mat2;
688 #[inline]
689 fn div(self, rhs: Mat2) -> Mat2 {
690 (*self).div(rhs)
691 }
692 }
693
694 impl Div<f32> for Mat2 {
695 type Output = Self;
696 #[inline]
697 fn div(self, rhs: f32) -> Self {
698 self.div_scalar(rhs)
699 }
700 }
701
702 impl Div<&f32> for Mat2 {
703 type Output = Self;
704 #[inline]
705 fn div(self, rhs: &f32) -> Self {
706 self.div(*rhs)
707 }
708 }
709
710 impl Div<&f32> for &Mat2 {
711 type Output = Mat2;
712 #[inline]
713 fn div(self, rhs: &f32) -> Mat2 {
714 (*self).div(*rhs)
715 }
716 }
717
718 impl Div<f32> for &Mat2 {
719 type Output = Mat2;
720 #[inline]
721 fn div(self, rhs: f32) -> Mat2 {
722 (*self).div(rhs)
723 }
724 }
725
726 impl DivAssign<f32> for Mat2 {
727 #[inline]
728 fn div_assign(&mut self, rhs: f32) {
729 *self = self.div(rhs);
730 }
731 }
732
733 impl DivAssign<&f32> for Mat2 {
734 #[inline]
735 fn div_assign(&mut self, rhs: &f32) {
736 self.div_assign(*rhs);
737 }
738 }
739
740 impl Sum<Self> for Mat2 {
741 fn sum<I>(iter: I) -> Self
742 where
743 I: Iterator<Item = Self>,
744 {
745 iter.fold(Self::ZERO, Self::add)
746 }
747 }
748
749 impl<'a> Sum<&'a Self> for Mat2 {
750 fn sum<I>(iter: I) -> Self
751 where
752 I: Iterator<Item = &'a Self>,
753 {
754 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
755 }
756 }
757
758 impl Product for Mat2 {
759 fn product<I>(iter: I) -> Self
760 where
761 I: Iterator<Item = Self>,
762 {
763 iter.fold(Self::IDENTITY, Self::mul)
764 }
765 }
766
767 impl<'a> Product<&'a Self> for Mat2 {
768 fn product<I>(iter: I) -> Self
769 where
770 I: Iterator<Item = &'a Self>,
771 {
772 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
773 }
774 }
775
776 impl PartialEq for Mat2 {
777 #[inline]
778 fn eq(&self, rhs: &Self) -> bool {
779 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis)
780 }
781 }
782
783 impl AsRef<[f32; 4]> for Mat2 {
784 #[inline]
785 fn as_ref(&self) -> &[f32; 4] {
786 unsafe { &*(self as *const Self as *const [f32; 4]) }
787 }
788 }
789
790 impl AsMut<[f32; 4]> for Mat2 {
791 #[inline]
792 fn as_mut(&mut self) -> &mut [f32; 4] {
793 unsafe { &mut *(self as *mut Self as *mut [f32; 4]) }
794 }
795 }
796
797 impl core::ops::Deref for Mat2 {
798 type Target = crate::deref::Cols2<Vec2>;
799 #[inline]
800 fn deref(&self) -> &Self::Target {
801 unsafe { &*(self as *const Self as *const Self::Target) }
802 }
803 }
804
805 impl core::ops::DerefMut for Mat2 {
806 #[inline]
807 fn deref_mut(&mut self) -> &mut Self::Target {
808 unsafe { &mut *(self as *mut Self as *mut Self::Target) }
809 }
810 }
811
812 impl fmt::Debug for Mat2 {
813 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
814 fmt.debug_struct(stringify!(Mat2))
815 .field("x_axis", &self.x_axis)
816 .field("y_axis", &self.y_axis)
817 .finish()
818 }
819 }
820
821 impl fmt::Display for Mat2 {
822 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
823 if let Some(p) = f.precision() {
824 write!(f, "[{:.*}, {:.*}]", p, self.x_axis, p, self.y_axis)
825 } else {
826 write!(f, "[{}, {}]", self.x_axis, self.y_axis)
827 }
828 }
829 }