diff options
Diffstat (limited to 'src/f64/daffine3.rs')
-rw-r--r-- | src/f64/daffine3.rs | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/src/f64/daffine3.rs b/src/f64/daffine3.rs index a5f4535..6a261bf 100644 --- a/src/f64/daffine3.rs +++ b/src/f64/daffine3.rs @@ -1,7 +1,7 @@ // Generated from affine.rs.tera template. Edit the template, not the generated file. use crate::{DMat3, DMat4, DQuat, DVec3}; -use core::ops::{Deref, DerefMut, Mul}; +use core::ops::{Deref, DerefMut, Mul, MulAssign}; /// A 3D affine transform, which can represent translation, rotation, scaling and shear. #[derive(Copy, Clone)] @@ -37,6 +37,7 @@ impl DAffine3 { /// Creates an affine transform from three column vectors. #[inline(always)] + #[must_use] pub const fn from_cols(x_axis: DVec3, y_axis: DVec3, z_axis: DVec3, w_axis: DVec3) -> Self { Self { matrix3: DMat3::from_cols(x_axis, y_axis, z_axis), @@ -46,6 +47,7 @@ impl DAffine3 { /// Creates an affine transform from a `[f64; 12]` array stored in column major order. #[inline] + #[must_use] pub fn from_cols_array(m: &[f64; 12]) -> Self { Self { matrix3: DMat3::from_cols_slice(&m[0..9]), @@ -55,6 +57,7 @@ impl DAffine3 { /// Creates a `[f64; 12]` array storing data in column major order. #[inline] + #[must_use] pub fn to_cols_array(&self) -> [f64; 12] { let x = &self.matrix3.x_axis; let y = &self.matrix3.y_axis; @@ -68,6 +71,7 @@ impl DAffine3 { /// If your data is in row major order you will need to `transpose` the returned /// matrix. #[inline] + #[must_use] pub fn from_cols_array_2d(m: &[[f64; 3]; 4]) -> Self { Self { matrix3: DMat3::from_cols(m[0].into(), m[1].into(), m[2].into()), @@ -79,6 +83,7 @@ impl DAffine3 { /// column major order. /// If you require data in row major order `transpose` the matrix first. #[inline] + #[must_use] pub fn to_cols_array_2d(&self) -> [[f64; 3]; 4] { [ self.matrix3.x_axis.into(), @@ -94,6 +99,7 @@ impl DAffine3 { /// /// Panics if `slice` is less than 12 elements long. #[inline] + #[must_use] pub fn from_cols_slice(slice: &[f64]) -> Self { Self { matrix3: DMat3::from_cols_slice(&slice[0..9]), @@ -115,6 +121,7 @@ impl DAffine3 { /// Creates an affine transform that changes scale. /// Note that if any scale is zero the transform will be non-invertible. #[inline] + #[must_use] pub fn from_scale(scale: DVec3) -> Self { Self { matrix3: DMat3::from_diagonal(scale), @@ -123,6 +130,7 @@ impl DAffine3 { } /// Creates an affine transform from the given `rotation` quaternion. #[inline] + #[must_use] pub fn from_quat(rotation: DQuat) -> Self { Self { matrix3: DMat3::from_quat(rotation), @@ -133,6 +141,7 @@ impl DAffine3 { /// Creates an affine transform containing a 3D rotation around a normalized /// rotation `axis` of `angle` (in radians). #[inline] + #[must_use] pub fn from_axis_angle(axis: DVec3, angle: f64) -> Self { Self { matrix3: DMat3::from_axis_angle(axis, angle), @@ -143,6 +152,7 @@ impl DAffine3 { /// Creates an affine transform containing a 3D rotation around the x axis of /// `angle` (in radians). #[inline] + #[must_use] pub fn from_rotation_x(angle: f64) -> Self { Self { matrix3: DMat3::from_rotation_x(angle), @@ -153,6 +163,7 @@ impl DAffine3 { /// Creates an affine transform containing a 3D rotation around the y axis of /// `angle` (in radians). #[inline] + #[must_use] pub fn from_rotation_y(angle: f64) -> Self { Self { matrix3: DMat3::from_rotation_y(angle), @@ -163,6 +174,7 @@ impl DAffine3 { /// Creates an affine transform containing a 3D rotation around the z axis of /// `angle` (in radians). #[inline] + #[must_use] pub fn from_rotation_z(angle: f64) -> Self { Self { matrix3: DMat3::from_rotation_z(angle), @@ -172,6 +184,7 @@ impl DAffine3 { /// Creates an affine transformation from the given 3D `translation`. #[inline] + #[must_use] pub fn from_translation(translation: DVec3) -> Self { #[allow(clippy::useless_conversion)] Self { @@ -183,6 +196,7 @@ impl DAffine3 { /// Creates an affine transform from a 3x3 matrix (expressing scale, shear and /// rotation) #[inline] + #[must_use] pub fn from_mat3(mat3: DMat3) -> Self { #[allow(clippy::useless_conversion)] Self { @@ -196,6 +210,7 @@ impl DAffine3 { /// /// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` #[inline] + #[must_use] pub fn from_mat3_translation(mat3: DMat3, translation: DVec3) -> Self { #[allow(clippy::useless_conversion)] Self { @@ -210,6 +225,7 @@ impl DAffine3 { /// Equivalent to `DAffine3::from_translation(translation) * /// DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` #[inline] + #[must_use] pub fn from_scale_rotation_translation( scale: DVec3, rotation: DQuat, @@ -231,6 +247,7 @@ impl DAffine3 { /// /// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` #[inline] + #[must_use] pub fn from_rotation_translation(rotation: DQuat, translation: DVec3) -> Self { #[allow(clippy::useless_conversion)] Self { @@ -242,6 +259,7 @@ impl DAffine3 { /// The given `DMat4` must be an affine transform, /// i.e. contain no perspective transform. #[inline] + #[must_use] pub fn from_mat4(m: DMat4) -> Self { Self { matrix3: DMat3::from_cols( @@ -263,16 +281,14 @@ impl DAffine3 { /// Will panic if the determinant `self.matrix3` is zero or if the resulting scale /// vector contains any zero elements when `glam_assert` is enabled. #[inline] + #[must_use] pub fn to_scale_rotation_translation(&self) -> (DVec3, DQuat, DVec3) { - #[cfg(feature = "libm")] - #[allow(unused_imports)] - use num_traits::Float; - + use crate::f64::math; let det = self.matrix3.determinant(); glam_assert!(det != 0.0); let scale = DVec3::new( - self.matrix3.x_axis.length() * det.signum(), + self.matrix3.x_axis.length() * math::signum(det), self.matrix3.y_axis.length(), self.matrix3.z_axis.length(), ); @@ -297,6 +313,7 @@ impl DAffine3 { /// /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. #[inline] + #[must_use] pub fn look_to_lh(eye: DVec3, dir: DVec3, up: DVec3) -> Self { Self::look_to_rh(eye, -dir, up) } @@ -306,6 +323,7 @@ impl DAffine3 { /// /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. #[inline] + #[must_use] pub fn look_to_rh(eye: DVec3, dir: DVec3, up: DVec3) -> Self { let f = dir.normalize(); let s = f.cross(up).normalize(); @@ -329,6 +347,7 @@ impl DAffine3 { /// /// Will panic if `up` is not normalized when `glam_assert` is enabled. #[inline] + #[must_use] pub fn look_at_lh(eye: DVec3, center: DVec3, up: DVec3) -> Self { glam_assert!(up.is_normalized()); Self::look_to_lh(eye, center - eye, up) @@ -342,6 +361,7 @@ impl DAffine3 { /// /// Will panic if `up` is not normalized when `glam_assert` is enabled. #[inline] + #[must_use] pub fn look_at_rh(eye: DVec3, center: DVec3, up: DVec3) -> Self { glam_assert!(up.is_normalized()); Self::look_to_rh(eye, center - eye, up) @@ -361,8 +381,9 @@ impl DAffine3 { /// Transforms the given 3D vector, applying shear, scale and rotation (but NOT /// translation). /// - /// To also apply translation, use [`Self::transform_point3`] instead. + /// To also apply translation, use [`Self::transform_point3()`] instead. #[inline] + #[must_use] pub fn transform_vector3(&self, rhs: DVec3) -> DVec3 { #[allow(clippy::useless_conversion)] ((self.matrix3.x_axis * rhs.x) @@ -376,12 +397,14 @@ impl DAffine3 { /// If any element is either `NaN`, positive or negative infinity, this will return /// `false`. #[inline] + #[must_use] pub fn is_finite(&self) -> bool { self.matrix3.is_finite() && self.translation.is_finite() } /// Returns `true` if any elements are `NaN`. #[inline] + #[must_use] pub fn is_nan(&self) -> bool { self.matrix3.is_nan() || self.translation.is_nan() } @@ -396,6 +419,7 @@ impl DAffine3 { /// 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.matrix3.abs_diff_eq(rhs.matrix3, max_abs_diff) && self.translation.abs_diff_eq(rhs.translation, max_abs_diff) @@ -404,8 +428,8 @@ impl DAffine3 { /// Return the inverse of this transform. /// /// Note that if the transform is not invertible the result will be invalid. - #[must_use] #[inline] + #[must_use] pub fn inverse(&self) -> Self { let matrix3 = self.matrix3.inverse(); // transform negative translation by the matrix inverse: @@ -489,6 +513,13 @@ impl Mul for DAffine3 { } } +impl MulAssign for DAffine3 { + #[inline] + fn mul_assign(&mut self, rhs: DAffine3) { + *self = self.mul(rhs); + } +} + impl From<DAffine3> for DMat4 { #[inline] fn from(m: DAffine3) -> DMat4 { |