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 /// Creates a 2x2 matrix from two column vectors.
11 #[inline(always)]
12 #[must_use]
mat2(x_axis: Vec2, y_axis: Vec2) -> Mat213 pub const fn mat2(x_axis: Vec2, y_axis: Vec2) -> Mat2 {
14 Mat2::from_cols(x_axis, y_axis)
15 }
16
17 /// A 2x2 column major matrix.
18 ///
19 /// SIMD vector types are used for storage on supported platforms.
20 ///
21 /// This type is 16 byte aligned.
22 #[derive(Clone, Copy)]
23 #[repr(transparent)]
24 pub struct Mat2(pub(crate) v128);
25
26 impl Mat2 {
27 /// A 2x2 matrix with all elements set to `0.0`.
28 pub const ZERO: Self = Self::from_cols(Vec2::ZERO, Vec2::ZERO);
29
30 /// A 2x2 identity matrix, where all diagonal elements are `1`, and all off-diagonal elements are `0`.
31 pub const IDENTITY: Self = Self::from_cols(Vec2::X, Vec2::Y);
32
33 /// All NAN:s.
34 pub const NAN: Self = Self::from_cols(Vec2::NAN, Vec2::NAN);
35
36 #[allow(clippy::too_many_arguments)]
37 #[inline(always)]
38 #[must_use]
new(m00: f32, m01: f32, m10: f32, m11: f32) -> Self39 const fn new(m00: f32, m01: f32, m10: f32, m11: f32) -> Self {
40 Self(f32x4(m00, m01, m10, m11))
41 }
42
43 /// Creates a 2x2 matrix from two column vectors.
44 #[inline(always)]
45 #[must_use]
from_cols(x_axis: Vec2, y_axis: Vec2) -> Self46 pub const fn from_cols(x_axis: Vec2, y_axis: Vec2) -> Self {
47 Self(f32x4(x_axis.x, x_axis.y, y_axis.x, y_axis.y))
48 }
49
50 /// Creates a 2x2 matrix from a `[f32; 4]` array stored in column major order.
51 /// If your data is stored in row major you will need to `transpose` the returned
52 /// matrix.
53 #[inline]
54 #[must_use]
from_cols_array(m: &[f32; 4]) -> Self55 pub const fn from_cols_array(m: &[f32; 4]) -> Self {
56 Self::new(m[0], m[1], m[2], m[3])
57 }
58
59 /// Creates a `[f32; 4]` array storing data in column major order.
60 /// If you require data in row major order `transpose` the matrix first.
61 #[inline]
62 #[must_use]
to_cols_array(&self) -> [f32; 4]63 pub const fn to_cols_array(&self) -> [f32; 4] {
64 unsafe { *(self as *const Self as *const [f32; 4]) }
65 }
66
67 /// Creates a 2x2 matrix from a `[[f32; 2]; 2]` 2D array stored in column major order.
68 /// If your data is in row major order you will need to `transpose` the returned
69 /// matrix.
70 #[inline]
71 #[must_use]
from_cols_array_2d(m: &[[f32; 2]; 2]) -> Self72 pub const fn from_cols_array_2d(m: &[[f32; 2]; 2]) -> Self {
73 Self::from_cols(Vec2::from_array(m[0]), Vec2::from_array(m[1]))
74 }
75
76 /// Creates a `[[f32; 2]; 2]` 2D array storing data in column major order.
77 /// If you require data in row major order `transpose` the matrix first.
78 #[inline]
79 #[must_use]
to_cols_array_2d(&self) -> [[f32; 2]; 2]80 pub const fn to_cols_array_2d(&self) -> [[f32; 2]; 2] {
81 unsafe { *(self as *const Self as *const [[f32; 2]; 2]) }
82 }
83
84 /// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0.
85 #[doc(alias = "scale")]
86 #[inline]
87 #[must_use]
from_diagonal(diagonal: Vec2) -> Self88 pub const fn from_diagonal(diagonal: Vec2) -> Self {
89 Self::new(diagonal.x, 0.0, 0.0, diagonal.y)
90 }
91
92 /// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of
93 /// `angle` (in radians).
94 #[inline]
95 #[must_use]
from_scale_angle(scale: Vec2, angle: f32) -> Self96 pub fn from_scale_angle(scale: Vec2, angle: f32) -> Self {
97 let (sin, cos) = math::sin_cos(angle);
98 Self::new(cos * scale.x, sin * scale.x, -sin * scale.y, cos * scale.y)
99 }
100
101 /// Creates a 2x2 matrix containing a rotation of `angle` (in radians).
102 #[inline]
103 #[must_use]
from_angle(angle: f32) -> Self104 pub fn from_angle(angle: f32) -> Self {
105 let (sin, cos) = math::sin_cos(angle);
106 Self::new(cos, sin, -sin, cos)
107 }
108
109 /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column.
110 #[inline]
111 #[must_use]
from_mat3(m: Mat3) -> Self112 pub fn from_mat3(m: Mat3) -> Self {
113 Self::from_cols(m.x_axis.xy(), m.y_axis.xy())
114 }
115
116 /// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column
117 /// and `j`th row.
118 ///
119 /// # Panics
120 ///
121 /// Panics if `i` or `j` is greater than 2.
122 #[inline]
123 #[must_use]
from_mat3_minor(m: Mat3, i: usize, j: usize) -> Self124 pub fn from_mat3_minor(m: Mat3, i: usize, j: usize) -> Self {
125 match (i, j) {
126 (0, 0) => Self::from_cols(m.y_axis.yz(), m.z_axis.yz()),
127 (0, 1) => Self::from_cols(m.y_axis.xz(), m.z_axis.xz()),
128 (0, 2) => Self::from_cols(m.y_axis.xy(), m.z_axis.xy()),
129 (1, 0) => Self::from_cols(m.x_axis.yz(), m.z_axis.yz()),
130 (1, 1) => Self::from_cols(m.x_axis.xz(), m.z_axis.xz()),
131 (1, 2) => Self::from_cols(m.x_axis.xy(), m.z_axis.xy()),
132 (2, 0) => Self::from_cols(m.x_axis.yz(), m.y_axis.yz()),
133 (2, 1) => Self::from_cols(m.x_axis.xz(), m.y_axis.xz()),
134 (2, 2) => Self::from_cols(m.x_axis.xy(), m.y_axis.xy()),
135 _ => panic!("index out of bounds"),
136 }
137 }
138
139 /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column.
140 #[inline]
141 #[must_use]
from_mat3a(m: Mat3A) -> Self142 pub fn from_mat3a(m: Mat3A) -> Self {
143 Self::from_cols(m.x_axis.xy(), m.y_axis.xy())
144 }
145
146 /// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column
147 /// and `j`th row.
148 ///
149 /// # Panics
150 ///
151 /// Panics if `i` or `j` is greater than 2.
152 #[inline]
153 #[must_use]
from_mat3a_minor(m: Mat3A, i: usize, j: usize) -> Self154 pub fn from_mat3a_minor(m: Mat3A, i: usize, j: usize) -> Self {
155 match (i, j) {
156 (0, 0) => Self::from_cols(m.y_axis.yz(), m.z_axis.yz()),
157 (0, 1) => Self::from_cols(m.y_axis.xz(), m.z_axis.xz()),
158 (0, 2) => Self::from_cols(m.y_axis.xy(), m.z_axis.xy()),
159 (1, 0) => Self::from_cols(m.x_axis.yz(), m.z_axis.yz()),
160 (1, 1) => Self::from_cols(m.x_axis.xz(), m.z_axis.xz()),
161 (1, 2) => Self::from_cols(m.x_axis.xy(), m.z_axis.xy()),
162 (2, 0) => Self::from_cols(m.x_axis.yz(), m.y_axis.yz()),
163 (2, 1) => Self::from_cols(m.x_axis.xz(), m.y_axis.xz()),
164 (2, 2) => Self::from_cols(m.x_axis.xy(), m.y_axis.xy()),
165 _ => panic!("index out of bounds"),
166 }
167 }
168
169 /// Creates a 2x2 matrix from the first 4 values in `slice`.
170 ///
171 /// # Panics
172 ///
173 /// Panics if `slice` is less than 4 elements long.
174 #[inline]
175 #[must_use]
from_cols_slice(slice: &[f32]) -> Self176 pub const fn from_cols_slice(slice: &[f32]) -> Self {
177 Self::new(slice[0], slice[1], slice[2], slice[3])
178 }
179
180 /// Writes the columns of `self` to the first 4 elements in `slice`.
181 ///
182 /// # Panics
183 ///
184 /// Panics if `slice` is less than 4 elements long.
185 #[inline]
write_cols_to_slice(self, slice: &mut [f32])186 pub fn write_cols_to_slice(self, slice: &mut [f32]) {
187 slice[0] = self.x_axis.x;
188 slice[1] = self.x_axis.y;
189 slice[2] = self.y_axis.x;
190 slice[3] = self.y_axis.y;
191 }
192
193 /// Returns the matrix column for the given `index`.
194 ///
195 /// # Panics
196 ///
197 /// Panics if `index` is greater than 1.
198 #[inline]
199 #[must_use]
col(&self, index: usize) -> Vec2200 pub fn col(&self, index: usize) -> Vec2 {
201 match index {
202 0 => self.x_axis,
203 1 => self.y_axis,
204 _ => panic!("index out of bounds"),
205 }
206 }
207
208 /// Returns a mutable reference to the matrix column for the given `index`.
209 ///
210 /// # Panics
211 ///
212 /// Panics if `index` is greater than 1.
213 #[inline]
col_mut(&mut self, index: usize) -> &mut Vec2214 pub fn col_mut(&mut self, index: usize) -> &mut Vec2 {
215 match index {
216 0 => &mut self.x_axis,
217 1 => &mut self.y_axis,
218 _ => panic!("index out of bounds"),
219 }
220 }
221
222 /// Returns the matrix row for the given `index`.
223 ///
224 /// # Panics
225 ///
226 /// Panics if `index` is greater than 1.
227 #[inline]
228 #[must_use]
row(&self, index: usize) -> Vec2229 pub fn row(&self, index: usize) -> Vec2 {
230 match index {
231 0 => Vec2::new(self.x_axis.x, self.y_axis.x),
232 1 => Vec2::new(self.x_axis.y, self.y_axis.y),
233 _ => panic!("index out of bounds"),
234 }
235 }
236
237 /// Returns `true` if, and only if, all elements are finite.
238 /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
239 #[inline]
240 #[must_use]
is_finite(&self) -> bool241 pub fn is_finite(&self) -> bool {
242 self.x_axis.is_finite() && self.y_axis.is_finite()
243 }
244
245 /// Returns `true` if any elements are `NaN`.
246 #[inline]
247 #[must_use]
is_nan(&self) -> bool248 pub fn is_nan(&self) -> bool {
249 self.x_axis.is_nan() || self.y_axis.is_nan()
250 }
251
252 /// Returns the transpose of `self`.
253 #[inline]
254 #[must_use]
transpose(&self) -> Self255 pub fn transpose(&self) -> Self {
256 Self(i32x4_shuffle::<0, 2, 5, 7>(self.0, self.0))
257 }
258
259 /// Returns the determinant of `self`.
260 #[inline]
261 #[must_use]
determinant(&self) -> f32262 pub fn determinant(&self) -> f32 {
263 let abcd = self.0;
264 let dcba = i32x4_shuffle::<3, 2, 5, 4>(abcd, abcd);
265 let prod = f32x4_mul(abcd, dcba);
266 let det = f32x4_sub(prod, i32x4_shuffle::<1, 1, 5, 5>(prod, prod));
267 f32x4_extract_lane::<0>(det)
268 }
269
270 /// Returns the inverse of `self`.
271 ///
272 /// If the matrix is not invertible the returned matrix will be invalid.
273 ///
274 /// # Panics
275 ///
276 /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled.
277 #[inline]
278 #[must_use]
inverse(&self) -> Self279 pub fn inverse(&self) -> Self {
280 const SIGN: v128 = crate::wasm32::v128_from_f32x4([1.0, -1.0, -1.0, 1.0]);
281 let abcd = self.0;
282 let dcba = i32x4_shuffle::<3, 2, 5, 4>(abcd, abcd);
283 let prod = f32x4_mul(abcd, dcba);
284 let sub = f32x4_sub(prod, i32x4_shuffle::<1, 1, 5, 5>(prod, prod));
285 let det = i32x4_shuffle::<0, 0, 4, 4>(sub, sub);
286 let tmp = f32x4_div(SIGN, det);
287 glam_assert!(Mat2(tmp).is_finite());
288 let dbca = i32x4_shuffle::<3, 1, 6, 4>(abcd, abcd);
289 Self(f32x4_mul(dbca, tmp))
290 }
291
292 /// Transforms a 2D vector.
293 #[inline]
294 #[must_use]
mul_vec2(&self, rhs: Vec2) -> Vec2295 pub fn mul_vec2(&self, rhs: Vec2) -> Vec2 {
296 use core::mem::MaybeUninit;
297 let abcd = self.0;
298 let xxyy = f32x4(rhs.x, rhs.x, rhs.y, rhs.y);
299 let axbxcydy = f32x4_mul(abcd, xxyy);
300 let cydyaxbx = i32x4_shuffle::<2, 3, 4, 5>(axbxcydy, axbxcydy);
301 let result = f32x4_add(axbxcydy, cydyaxbx);
302 let mut out: MaybeUninit<v128> = MaybeUninit::uninit();
303 unsafe {
304 v128_store(out.as_mut_ptr(), result);
305 *(&out.assume_init() as *const v128 as *const Vec2)
306 }
307 }
308
309 /// Multiplies two 2x2 matrices.
310 #[inline]
311 #[must_use]
mul_mat2(&self, rhs: &Self) -> Self312 pub fn mul_mat2(&self, rhs: &Self) -> Self {
313 let abcd = self.0;
314 let rhs = rhs.0;
315 let xxyy0 = i32x4_shuffle::<0, 0, 5, 5>(rhs, rhs);
316 let xxyy1 = i32x4_shuffle::<2, 2, 7, 7>(rhs, rhs);
317 let axbxcydy0 = f32x4_mul(abcd, xxyy0);
318 let axbxcydy1 = f32x4_mul(abcd, xxyy1);
319 let cydyaxbx0 = i32x4_shuffle::<2, 3, 4, 5>(axbxcydy0, axbxcydy0);
320 let cydyaxbx1 = i32x4_shuffle::<2, 3, 4, 5>(axbxcydy1, axbxcydy1);
321 let result0 = f32x4_add(axbxcydy0, cydyaxbx0);
322 let result1 = f32x4_add(axbxcydy1, cydyaxbx1);
323 Self(i32x4_shuffle::<0, 1, 4, 5>(result0, result1))
324 }
325
326 /// Adds two 2x2 matrices.
327 #[inline]
328 #[must_use]
add_mat2(&self, rhs: &Self) -> Self329 pub fn add_mat2(&self, rhs: &Self) -> Self {
330 Self(f32x4_add(self.0, rhs.0))
331 }
332
333 /// Subtracts two 2x2 matrices.
334 #[inline]
335 #[must_use]
sub_mat2(&self, rhs: &Self) -> Self336 pub fn sub_mat2(&self, rhs: &Self) -> Self {
337 Self(f32x4_sub(self.0, rhs.0))
338 }
339
340 /// Multiplies a 2x2 matrix by a scalar.
341 #[inline]
342 #[must_use]
mul_scalar(&self, rhs: f32) -> Self343 pub fn mul_scalar(&self, rhs: f32) -> Self {
344 Self(f32x4_mul(self.0, f32x4_splat(rhs)))
345 }
346
347 /// Divides a 2x2 matrix by a scalar.
348 #[inline]
349 #[must_use]
div_scalar(&self, rhs: f32) -> Self350 pub fn div_scalar(&self, rhs: f32) -> Self {
351 Self(f32x4_div(self.0, f32x4_splat(rhs)))
352 }
353
354 /// Returns true if the absolute difference of all elements between `self` and `rhs`
355 /// is less than or equal to `max_abs_diff`.
356 ///
357 /// This can be used to compare if two matrices contain similar elements. It works best
358 /// when comparing with a known value. The `max_abs_diff` that should be used used
359 /// depends on the values being compared against.
360 ///
361 /// For more see
362 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
363 #[inline]
364 #[must_use]
abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool365 pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f32) -> bool {
366 self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff)
367 && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff)
368 }
369
370 /// Takes the absolute value of each element in `self`
371 #[inline]
372 #[must_use]
abs(&self) -> Self373 pub fn abs(&self) -> Self {
374 Self::from_cols(self.x_axis.abs(), self.y_axis.abs())
375 }
376
377 #[inline]
as_dmat2(&self) -> DMat2378 pub fn as_dmat2(&self) -> DMat2 {
379 DMat2::from_cols(self.x_axis.as_dvec2(), self.y_axis.as_dvec2())
380 }
381 }
382
383 impl Default for Mat2 {
384 #[inline]
default() -> Self385 fn default() -> Self {
386 Self::IDENTITY
387 }
388 }
389
390 impl Add<Mat2> for Mat2 {
391 type Output = Self;
392 #[inline]
add(self, rhs: Self) -> Self::Output393 fn add(self, rhs: Self) -> Self::Output {
394 self.add_mat2(&rhs)
395 }
396 }
397
398 impl AddAssign<Mat2> for Mat2 {
399 #[inline]
add_assign(&mut self, rhs: Self)400 fn add_assign(&mut self, rhs: Self) {
401 *self = self.add_mat2(&rhs);
402 }
403 }
404
405 impl Sub<Mat2> for Mat2 {
406 type Output = Self;
407 #[inline]
sub(self, rhs: Self) -> Self::Output408 fn sub(self, rhs: Self) -> Self::Output {
409 self.sub_mat2(&rhs)
410 }
411 }
412
413 impl SubAssign<Mat2> for Mat2 {
414 #[inline]
sub_assign(&mut self, rhs: Self)415 fn sub_assign(&mut self, rhs: Self) {
416 *self = self.sub_mat2(&rhs);
417 }
418 }
419
420 impl Neg for Mat2 {
421 type Output = Self;
422 #[inline]
neg(self) -> Self::Output423 fn neg(self) -> Self::Output {
424 Self(f32x4_neg(self.0))
425 }
426 }
427
428 impl Mul<Mat2> for Mat2 {
429 type Output = Self;
430 #[inline]
mul(self, rhs: Self) -> Self::Output431 fn mul(self, rhs: Self) -> Self::Output {
432 self.mul_mat2(&rhs)
433 }
434 }
435
436 impl MulAssign<Mat2> for Mat2 {
437 #[inline]
mul_assign(&mut self, rhs: Self)438 fn mul_assign(&mut self, rhs: Self) {
439 *self = self.mul_mat2(&rhs);
440 }
441 }
442
443 impl Mul<Vec2> for Mat2 {
444 type Output = Vec2;
445 #[inline]
mul(self, rhs: Vec2) -> Self::Output446 fn mul(self, rhs: Vec2) -> Self::Output {
447 self.mul_vec2(rhs)
448 }
449 }
450
451 impl Mul<Mat2> for f32 {
452 type Output = Mat2;
453 #[inline]
mul(self, rhs: Mat2) -> Self::Output454 fn mul(self, rhs: Mat2) -> Self::Output {
455 rhs.mul_scalar(self)
456 }
457 }
458
459 impl Mul<f32> for Mat2 {
460 type Output = Self;
461 #[inline]
mul(self, rhs: f32) -> Self::Output462 fn mul(self, rhs: f32) -> Self::Output {
463 self.mul_scalar(rhs)
464 }
465 }
466
467 impl MulAssign<f32> for Mat2 {
468 #[inline]
mul_assign(&mut self, rhs: f32)469 fn mul_assign(&mut self, rhs: f32) {
470 *self = self.mul_scalar(rhs);
471 }
472 }
473
474 impl Div<Mat2> for f32 {
475 type Output = Mat2;
476 #[inline]
div(self, rhs: Mat2) -> Self::Output477 fn div(self, rhs: Mat2) -> Self::Output {
478 rhs.div_scalar(self)
479 }
480 }
481
482 impl Div<f32> for Mat2 {
483 type Output = Self;
484 #[inline]
div(self, rhs: f32) -> Self::Output485 fn div(self, rhs: f32) -> Self::Output {
486 self.div_scalar(rhs)
487 }
488 }
489
490 impl DivAssign<f32> for Mat2 {
491 #[inline]
div_assign(&mut self, rhs: f32)492 fn div_assign(&mut self, rhs: f32) {
493 *self = self.div_scalar(rhs);
494 }
495 }
496
497 impl Sum<Self> for Mat2 {
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,498 fn sum<I>(iter: I) -> Self
499 where
500 I: Iterator<Item = Self>,
501 {
502 iter.fold(Self::ZERO, Self::add)
503 }
504 }
505
506 impl<'a> Sum<&'a Self> for Mat2 {
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,507 fn sum<I>(iter: I) -> Self
508 where
509 I: Iterator<Item = &'a Self>,
510 {
511 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
512 }
513 }
514
515 impl Product for Mat2 {
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,516 fn product<I>(iter: I) -> Self
517 where
518 I: Iterator<Item = Self>,
519 {
520 iter.fold(Self::IDENTITY, Self::mul)
521 }
522 }
523
524 impl<'a> Product<&'a Self> for Mat2 {
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,525 fn product<I>(iter: I) -> Self
526 where
527 I: Iterator<Item = &'a Self>,
528 {
529 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
530 }
531 }
532
533 impl PartialEq for Mat2 {
534 #[inline]
eq(&self, rhs: &Self) -> bool535 fn eq(&self, rhs: &Self) -> bool {
536 self.x_axis.eq(&rhs.x_axis) && self.y_axis.eq(&rhs.y_axis)
537 }
538 }
539
540 #[cfg(not(target_arch = "spirv"))]
541 impl AsRef<[f32; 4]> for Mat2 {
542 #[inline]
as_ref(&self) -> &[f32; 4]543 fn as_ref(&self) -> &[f32; 4] {
544 unsafe { &*(self as *const Self as *const [f32; 4]) }
545 }
546 }
547
548 #[cfg(not(target_arch = "spirv"))]
549 impl AsMut<[f32; 4]> for Mat2 {
550 #[inline]
as_mut(&mut self) -> &mut [f32; 4]551 fn as_mut(&mut self) -> &mut [f32; 4] {
552 unsafe { &mut *(self as *mut Self as *mut [f32; 4]) }
553 }
554 }
555
556 impl core::ops::Deref for Mat2 {
557 type Target = crate::deref::Cols2<Vec2>;
558 #[inline]
deref(&self) -> &Self::Target559 fn deref(&self) -> &Self::Target {
560 unsafe { &*(self as *const Self as *const Self::Target) }
561 }
562 }
563
564 impl core::ops::DerefMut for Mat2 {
565 #[inline]
deref_mut(&mut self) -> &mut Self::Target566 fn deref_mut(&mut self) -> &mut Self::Target {
567 unsafe { &mut *(self as *mut Self as *mut Self::Target) }
568 }
569 }
570
571 impl fmt::Debug for Mat2 {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result572 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
573 fmt.debug_struct(stringify!(Mat2))
574 .field("x_axis", &self.x_axis)
575 .field("y_axis", &self.y_axis)
576 .finish()
577 }
578 }
579
580 impl fmt::Display for Mat2 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result581 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
582 if let Some(p) = f.precision() {
583 write!(f, "[{:.*}, {:.*}]", p, self.x_axis, p, self.y_axis)
584 } else {
585 write!(f, "[{}, {}]", self.x_axis, self.y_axis)
586 }
587 }
588 }
589