diff options
Diffstat (limited to 'src/f64/dmat2.rs')
-rw-r--r-- | src/f64/dmat2.rs | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/f64/dmat2.rs b/src/f64/dmat2.rs index bd52c8c..dbc61c5 100644 --- a/src/f64/dmat2.rs +++ b/src/f64/dmat2.rs @@ -1,17 +1,14 @@ // Generated from mat.rs.tera template. Edit the template, not the generated file. -use crate::{swizzles::*, DMat3, DVec2, Mat2}; +use crate::{f64::math, swizzles::*, DMat3, DVec2, Mat2}; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; -#[cfg(feature = "libm")] -#[allow(unused_imports)] -use num_traits::Float; - -/// Creates a 2x2 matrix from column vectors. +/// Creates a 2x2 matrix from two column vectors. #[inline(always)] +#[must_use] pub const fn dmat2(x_axis: DVec2, y_axis: DVec2) -> DMat2 { DMat2::from_cols(x_axis, y_axis) } @@ -37,6 +34,7 @@ impl DMat2 { #[allow(clippy::too_many_arguments)] #[inline(always)] + #[must_use] const fn new(m00: f64, m01: f64, m10: f64, m11: f64) -> Self { Self { x_axis: DVec2::new(m00, m01), @@ -46,6 +44,7 @@ impl DMat2 { /// Creates a 2x2 matrix from two column vectors. #[inline(always)] + #[must_use] pub const fn from_cols(x_axis: DVec2, y_axis: DVec2) -> Self { Self { x_axis, y_axis } } @@ -54,6 +53,7 @@ impl DMat2 { /// If your data is stored in row major you will need to `transpose` the returned /// matrix. #[inline] + #[must_use] pub const fn from_cols_array(m: &[f64; 4]) -> Self { Self::new(m[0], m[1], m[2], m[3]) } @@ -61,6 +61,7 @@ impl DMat2 { /// Creates a `[f64; 4]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. #[inline] + #[must_use] pub const fn to_cols_array(&self) -> [f64; 4] { [self.x_axis.x, self.x_axis.y, self.y_axis.x, self.y_axis.y] } @@ -69,6 +70,7 @@ impl DMat2 { /// If your data is in row major order you will need to `transpose` the returned /// matrix. #[inline] + #[must_use] pub const fn from_cols_array_2d(m: &[[f64; 2]; 2]) -> Self { Self::from_cols(DVec2::from_array(m[0]), DVec2::from_array(m[1])) } @@ -76,6 +78,7 @@ impl DMat2 { /// Creates a `[[f64; 2]; 2]` 2D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. #[inline] + #[must_use] pub const fn to_cols_array_2d(&self) -> [[f64; 2]; 2] { [self.x_axis.to_array(), self.y_axis.to_array()] } @@ -83,6 +86,7 @@ impl DMat2 { /// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. #[doc(alias = "scale")] #[inline] + #[must_use] pub const fn from_diagonal(diagonal: DVec2) -> Self { Self::new(diagonal.x, 0.0, 0.0, diagonal.y) } @@ -90,20 +94,23 @@ impl DMat2 { /// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of /// `angle` (in radians). #[inline] + #[must_use] pub fn from_scale_angle(scale: DVec2, angle: f64) -> Self { - let (sin, cos) = angle.sin_cos(); + let (sin, cos) = math::sin_cos(angle); Self::new(cos * scale.x, sin * scale.x, -sin * scale.y, cos * scale.y) } /// Creates a 2x2 matrix containing a rotation of `angle` (in radians). #[inline] + #[must_use] pub fn from_angle(angle: f64) -> Self { - let (sin, cos) = angle.sin_cos(); + let (sin, cos) = math::sin_cos(angle); Self::new(cos, sin, -sin, cos) } /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. #[inline] + #[must_use] pub fn from_mat3(m: DMat3) -> Self { Self::from_cols(m.x_axis.xy(), m.y_axis.xy()) } @@ -114,6 +121,7 @@ impl DMat2 { /// /// Panics if `slice` is less than 4 elements long. #[inline] + #[must_use] pub const fn from_cols_slice(slice: &[f64]) -> Self { Self::new(slice[0], slice[1], slice[2], slice[3]) } @@ -137,6 +145,7 @@ impl DMat2 { /// /// Panics if `index` is greater than 1. #[inline] + #[must_use] pub fn col(&self, index: usize) -> DVec2 { match index { 0 => self.x_axis, @@ -165,6 +174,7 @@ impl DMat2 { /// /// Panics if `index` is greater than 1. #[inline] + #[must_use] pub fn row(&self, index: usize) -> DVec2 { match index { 0 => DVec2::new(self.x_axis.x, self.y_axis.x), @@ -176,19 +186,21 @@ impl DMat2 { /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. #[inline] + #[must_use] pub fn is_finite(&self) -> bool { self.x_axis.is_finite() && self.y_axis.is_finite() } /// Returns `true` if any elements are `NaN`. #[inline] + #[must_use] pub fn is_nan(&self) -> bool { self.x_axis.is_nan() || self.y_axis.is_nan() } /// Returns the transpose of `self`. - #[must_use] #[inline] + #[must_use] pub fn transpose(&self) -> Self { Self { x_axis: DVec2::new(self.x_axis.x, self.y_axis.x), @@ -198,6 +210,7 @@ impl DMat2 { /// Returns the determinant of `self`. #[inline] + #[must_use] pub fn determinant(&self) -> f64 { self.x_axis.x * self.y_axis.y - self.x_axis.y * self.y_axis.x } @@ -209,8 +222,8 @@ impl DMat2 { /// # Panics /// /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[must_use] #[inline] + #[must_use] pub fn inverse(&self) -> Self { let inv_det = { let det = self.determinant(); @@ -227,6 +240,7 @@ impl DMat2 { /// Transforms a 2D vector. #[inline] + #[must_use] pub fn mul_vec2(&self, rhs: DVec2) -> DVec2 { #[allow(clippy::suspicious_operation_groupings)] DVec2::new( @@ -237,24 +251,28 @@ impl DMat2 { /// Multiplies two 2x2 matrices. #[inline] + #[must_use] pub fn mul_mat2(&self, rhs: &Self) -> Self { Self::from_cols(self.mul(rhs.x_axis), self.mul(rhs.y_axis)) } /// Adds two 2x2 matrices. #[inline] + #[must_use] pub fn add_mat2(&self, rhs: &Self) -> Self { Self::from_cols(self.x_axis.add(rhs.x_axis), self.y_axis.add(rhs.y_axis)) } /// Subtracts two 2x2 matrices. #[inline] + #[must_use] pub fn sub_mat2(&self, rhs: &Self) -> Self { Self::from_cols(self.x_axis.sub(rhs.x_axis), self.y_axis.sub(rhs.y_axis)) } /// Multiplies a 2x2 matrix by a scalar. #[inline] + #[must_use] pub fn mul_scalar(&self, rhs: f64) -> Self { Self::from_cols(self.x_axis.mul(rhs), self.y_axis.mul(rhs)) } @@ -269,6 +287,7 @@ impl DMat2 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). #[inline] + #[must_use] pub fn abs_diff_eq(&self, rhs: Self, max_abs_diff: f64) -> bool { self.x_axis.abs_diff_eq(rhs.x_axis, max_abs_diff) && self.y_axis.abs_diff_eq(rhs.y_axis, max_abs_diff) |