diff options
Diffstat (limited to 'src/f32/wasm32/mat3a.rs')
-rw-r--r-- | src/f32/wasm32/mat3a.rs | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/src/f32/wasm32/mat3a.rs b/src/f32/wasm32/mat3a.rs index 573ea1f..96c039b 100644 --- a/src/f32/wasm32/mat3a.rs +++ b/src/f32/wasm32/mat3a.rs @@ -1,6 +1,6 @@ // Generated from mat.rs.tera template. Edit the template, not the generated file. -use crate::{swizzles::*, DMat3, EulerRot, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A}; +use crate::{f32::math, swizzles::*, DMat3, EulerRot, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A}; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; @@ -8,12 +8,9 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; use core::arch::wasm32::*; -#[cfg(feature = "libm")] -#[allow(unused_imports)] -use num_traits::Float; - -/// Creates a 3x3 matrix from column vectors. +/// Creates a 3x3 matrix from three column vectors. #[inline(always)] +#[must_use] pub const fn mat3a(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Mat3A { Mat3A::from_cols(x_axis, y_axis, z_axis) } @@ -62,6 +59,7 @@ impl Mat3A { #[allow(clippy::too_many_arguments)] #[inline(always)] + #[must_use] const fn new( m00: f32, m01: f32, @@ -80,8 +78,9 @@ impl Mat3A { } } - /// Creates a 3x3 matrix from two column vectors. + /// Creates a 3x3 matrix from three column vectors. #[inline(always)] + #[must_use] pub const fn from_cols(x_axis: Vec3A, y_axis: Vec3A, z_axis: Vec3A) -> Self { Self { x_axis, @@ -94,6 +93,7 @@ impl Mat3A { /// 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: &[f32; 9]) -> Self { Self::new(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]) } @@ -101,6 +101,7 @@ impl Mat3A { /// Creates a `[f32; 9]` 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) -> [f32; 9] { let [x_axis_x, x_axis_y, x_axis_z] = self.x_axis.to_array(); let [y_axis_x, y_axis_y, y_axis_z] = self.y_axis.to_array(); @@ -116,6 +117,7 @@ impl Mat3A { /// 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: &[[f32; 3]; 3]) -> Self { Self::from_cols( Vec3A::from_array(m[0]), @@ -127,6 +129,7 @@ impl Mat3A { /// Creates a `[[f32; 3]; 3]` 3D 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) -> [[f32; 3]; 3] { [ self.x_axis.to_array(), @@ -138,6 +141,7 @@ impl Mat3A { /// Creates a 3x3 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: Vec3) -> Self { Self::new( diagonal.x, 0.0, 0.0, 0.0, diagonal.y, 0.0, 0.0, 0.0, diagonal.z, @@ -145,6 +149,8 @@ impl Mat3A { } /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + #[inline] + #[must_use] pub fn from_mat4(m: Mat4) -> Self { Self::from_cols(m.x_axis.into(), m.y_axis.into(), m.z_axis.into()) } @@ -155,6 +161,7 @@ impl Mat3A { /// /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. #[inline] + #[must_use] pub fn from_quat(rotation: Quat) -> Self { glam_assert!(rotation.is_normalized()); @@ -185,10 +192,11 @@ impl Mat3A { /// /// Will panic if `axis` is not normalized when `glam_assert` is enabled. #[inline] + #[must_use] pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self { glam_assert!(axis.is_normalized()); - let (sin, cos) = angle.sin_cos(); + let (sin, cos) = math::sin_cos(angle); let (xsin, ysin, zsin) = axis.mul(sin).into(); let (x, y, z) = axis.into(); let (x2, y2, z2) = axis.mul(axis).into(); @@ -203,9 +211,10 @@ impl Mat3A { ) } - #[inline] /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in /// radians). + #[inline] + #[must_use] pub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Self { let quat = Quat::from_euler(order, a, b, c); Self::from_quat(quat) @@ -213,8 +222,9 @@ impl Mat3A { /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. #[inline] + #[must_use] pub fn from_rotation_x(angle: f32) -> Self { - let (sina, cosa) = angle.sin_cos(); + let (sina, cosa) = math::sin_cos(angle); Self::from_cols( Vec3A::X, Vec3A::new(0.0, cosa, sina), @@ -224,8 +234,9 @@ impl Mat3A { /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. #[inline] + #[must_use] pub fn from_rotation_y(angle: f32) -> Self { - let (sina, cosa) = angle.sin_cos(); + let (sina, cosa) = math::sin_cos(angle); Self::from_cols( Vec3A::new(cosa, 0.0, -sina), Vec3A::Y, @@ -235,8 +246,9 @@ impl Mat3A { /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. #[inline] + #[must_use] pub fn from_rotation_z(angle: f32) -> Self { - let (sina, cosa) = angle.sin_cos(); + let (sina, cosa) = math::sin_cos(angle); Self::from_cols( Vec3A::new(cosa, sina, 0.0), Vec3A::new(-sina, cosa, 0.0), @@ -249,6 +261,7 @@ impl Mat3A { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. #[inline] + #[must_use] pub fn from_translation(translation: Vec2) -> Self { Self::from_cols( Vec3A::X, @@ -263,8 +276,9 @@ impl Mat3A { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. #[inline] + #[must_use] pub fn from_angle(angle: f32) -> Self { - let (sin, cos) = angle.sin_cos(); + let (sin, cos) = math::sin_cos(angle); Self::from_cols( Vec3A::new(cos, sin, 0.0), Vec3A::new(-sin, cos, 0.0), @@ -278,8 +292,9 @@ impl Mat3A { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. #[inline] + #[must_use] pub fn from_scale_angle_translation(scale: Vec2, angle: f32, translation: Vec2) -> Self { - let (sin, cos) = angle.sin_cos(); + let (sin, cos) = math::sin_cos(angle); Self::from_cols( Vec3A::new(cos * scale.x, sin * scale.x, 0.0), Vec3A::new(-sin * scale.y, cos * scale.y, 0.0), @@ -296,6 +311,7 @@ impl Mat3A { /// /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. #[inline] + #[must_use] pub fn from_scale(scale: Vec2) -> Self { // Do not panic as long as any component is non-zero glam_assert!(scale.cmpne(Vec2::ZERO).any()); @@ -322,6 +338,7 @@ impl Mat3A { /// /// Panics if `slice` is less than 9 elements long. #[inline] + #[must_use] pub const fn from_cols_slice(slice: &[f32]) -> Self { Self::new( slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7], @@ -353,6 +370,7 @@ impl Mat3A { /// /// Panics if `index` is greater than 2. #[inline] + #[must_use] pub fn col(&self, index: usize) -> Vec3A { match index { 0 => self.x_axis, @@ -383,6 +401,7 @@ impl Mat3A { /// /// Panics if `index` is greater than 2. #[inline] + #[must_use] pub fn row(&self, index: usize) -> Vec3A { match index { 0 => Vec3A::new(self.x_axis.x, self.y_axis.x, self.z_axis.x), @@ -395,19 +414,21 @@ impl Mat3A { /// 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() && self.z_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() || self.z_axis.is_nan() } /// Returns the transpose of `self`. - #[must_use] #[inline] + #[must_use] pub fn transpose(&self) -> Self { let tmp0 = i32x4_shuffle::<0, 1, 4, 5>(self.x_axis.0, self.y_axis.0); let tmp1 = i32x4_shuffle::<2, 3, 6, 7>(self.x_axis.0, self.y_axis.0); @@ -421,6 +442,7 @@ impl Mat3A { /// Returns the determinant of `self`. #[inline] + #[must_use] pub fn determinant(&self) -> f32 { self.z_axis.dot(self.x_axis.cross(self.y_axis)) } @@ -432,8 +454,8 @@ impl Mat3A { /// # 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 tmp0 = self.y_axis.cross(self.z_axis); let tmp1 = self.z_axis.cross(self.x_axis); @@ -454,6 +476,7 @@ impl Mat3A { /// /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. #[inline] + #[must_use] pub fn transform_point2(&self, rhs: Vec2) -> Vec2 { glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6)); Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs + self.z_axis.xy() @@ -469,6 +492,7 @@ impl Mat3A { /// /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. #[inline] + #[must_use] pub fn transform_vector2(&self, rhs: Vec2) -> Vec2 { glam_assert!(self.row(2).abs_diff_eq(Vec3A::Z, 1e-6)); Mat2::from_cols(self.x_axis.xy(), self.y_axis.xy()) * rhs @@ -476,12 +500,14 @@ impl Mat3A { /// Transforms a 3D vector. #[inline] + #[must_use] pub fn mul_vec3(&self, rhs: Vec3) -> Vec3 { self.mul_vec3a(rhs.into()).into() } - /// Transforms a `Vec3A`. + /// Transforms a [`Vec3A`]. #[inline] + #[must_use] pub fn mul_vec3a(&self, rhs: Vec3A) -> Vec3A { let mut res = self.x_axis.mul(rhs.xxx()); res = res.add(self.y_axis.mul(rhs.yyy())); @@ -491,6 +517,7 @@ impl Mat3A { /// Multiplies two 3x3 matrices. #[inline] + #[must_use] pub fn mul_mat3(&self, rhs: &Self) -> Self { Self::from_cols( self.mul(rhs.x_axis), @@ -501,6 +528,7 @@ impl Mat3A { /// Adds two 3x3 matrices. #[inline] + #[must_use] pub fn add_mat3(&self, rhs: &Self) -> Self { Self::from_cols( self.x_axis.add(rhs.x_axis), @@ -511,6 +539,7 @@ impl Mat3A { /// Subtracts two 3x3 matrices. #[inline] + #[must_use] pub fn sub_mat3(&self, rhs: &Self) -> Self { Self::from_cols( self.x_axis.sub(rhs.x_axis), @@ -521,6 +550,7 @@ impl Mat3A { /// Multiplies a 3x3 matrix by a scalar. #[inline] + #[must_use] pub fn mul_scalar(&self, rhs: f32) -> Self { Self::from_cols( self.x_axis.mul(rhs), @@ -539,6 +569,7 @@ impl Mat3A { /// 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: f32) -> 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) |