diff --git a/src/base/blas.rs b/src/base/blas.rs index 35133bb6..a6a188bc 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -278,6 +278,7 @@ where } } +#[allow(clippy::too_many_arguments)] fn array_axcpy( y: &mut [T], a: T, @@ -334,6 +335,7 @@ where /// assert_eq!(vec1, Vector3::new(6.0, 12.0, 18.0)); /// ``` #[inline] + #[allow(clippy::many_single_char_names)] pub fn axcpy(&mut self, a: T, x: &Vector, c: T, b: T) where SB: Storage, diff --git a/src/base/construction.rs b/src/base/construction.rs index e3e56b53..ac9023ec 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -906,6 +906,7 @@ macro_rules! componentwise_constructors_impl( impl Matrix, Const<$C>, ArrayStorage> { /// Initializes this matrix from its components. #[inline] + #[allow(clippy::too_many_arguments)] pub const fn new($($($args: T),*),*) -> Self { unsafe { Self::from_data_statically_unchecked( diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 532ab8ed..99639991 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -2,7 +2,6 @@ use alloc::vec::Vec; use simba::scalar::{SubsetOf, SupersetOf}; use std::convert::{AsMut, AsRef, From, Into}; -use std::mem; use simba::simd::{PrimitiveSimdValue, SimdValue}; @@ -110,11 +109,11 @@ impl From<[T; D]> for SVector { } } -impl Into<[T; D]> for SVector { +impl From> for [T; D] { #[inline] - fn into(self) -> [T; D] { + fn from(vec: SVector) -> Self { // TODO: unfortunately, we must clone because we can move out of an array. - self.data.0[0].clone() + vec.data.0[0].clone() } } @@ -128,13 +127,13 @@ where } } -impl Into<[T; D]> for RowSVector +impl From> for [T; D] where Const: IsNotStaticOne, { #[inline] - fn into(self) -> [T; D] { - self.transpose().into() + fn from(vec: RowSVector) -> [T; D] { + vec.transpose().into() } } @@ -146,7 +145,7 @@ macro_rules! impl_from_into_asref_1D( #[inline] fn as_ref(&self) -> &[T; $SZ] { unsafe { - mem::transmute(self.data.ptr()) + &*(self.data.ptr() as *const [T; $SZ]) } } } @@ -157,7 +156,7 @@ macro_rules! impl_from_into_asref_1D( #[inline] fn as_mut(&mut self) -> &mut [T; $SZ] { unsafe { - mem::transmute(self.data.ptr_mut()) + &mut *(self.data.ptr_mut() as *mut [T; $SZ]) } } } @@ -186,10 +185,10 @@ impl From<[[T; R]; C]> for SMatrix Into<[[T; R]; C]> for SMatrix { +impl From> for [[T; R]; C] { #[inline] - fn into(self) -> [[T; R]; C] { - self.data.0 + fn from(vec: SMatrix) -> Self { + vec.data.0 } } @@ -200,7 +199,7 @@ macro_rules! impl_from_into_asref_2D( #[inline] fn as_ref(&self) -> &[[T; $SZRows]; $SZCols] { unsafe { - mem::transmute(self.data.ptr()) + &*(self.data.ptr() as *const [[T; $SZRows]; $SZCols]) } } } @@ -210,7 +209,7 @@ macro_rules! impl_from_into_asref_2D( #[inline] fn as_mut(&mut self) -> &mut [[T; $SZRows]; $SZCols] { unsafe { - mem::transmute(self.data.ptr_mut()) + &mut *(self.data.ptr_mut() as *mut [[T; $SZRows]; $SZCols]) } } } @@ -427,21 +426,21 @@ impl<'a, T: Scalar> From> for DVector { } } -impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage> Into<&'a [T]> - for &'a Matrix +impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage> + From<&'a Matrix> for &'a [T] { #[inline] - fn into(self) -> &'a [T] { - self.as_slice() + fn from(matrix: &'a Matrix) -> Self { + matrix.as_slice() } } -impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut> Into<&'a mut [T]> - for &'a mut Matrix +impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut> + From<&'a mut Matrix> for &'a mut [T] { #[inline] - fn into(self) -> &'a mut [T] { - self.as_mut_slice() + fn from(matrix: &'a mut Matrix) -> Self { + matrix.as_mut_slice() } } diff --git a/src/base/coordinates.rs b/src/base/coordinates.rs index bf69b09e..be05d3e5 100644 --- a/src/base/coordinates.rs +++ b/src/base/coordinates.rs @@ -4,7 +4,6 @@ //! components using their names. For example, if `v` is a 3D vector, one can write `v.z` instead //! of `v[2]`. -use std::mem; use std::ops::{Deref, DerefMut}; use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; @@ -38,7 +37,7 @@ macro_rules! deref_impl( #[inline] fn deref(&self) -> &Self::Target { - unsafe { mem::transmute(self.data.ptr()) } + unsafe { &*(self.data.ptr() as *const Self::Target) } } } @@ -46,7 +45,7 @@ macro_rules! deref_impl( where S: ContiguousStorageMut { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { mem::transmute(self.data.ptr_mut()) } + unsafe { &mut *(self.data.ptr_mut() as *mut Self::Target) } } } } diff --git a/src/base/iter.rs b/src/base/iter.rs index 1592299d..0e13e4d3 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -96,6 +96,10 @@ macro_rules! iterator { let stride = self.strides.0.value(); self.ptr = self.ptr.add(stride); } + + // We want either `& *last` or `&mut *last` here, depending + // on the mutability of `$Ref`. + #[allow(clippy::transmute_ptr_to_ref)] Some(mem::transmute(old)) } } @@ -139,13 +143,13 @@ macro_rules! iterator { let inner_remaining = self.size % inner_size; // Compute pointer to last element - let last = self.ptr.offset( - (outer_remaining * outer_stride + inner_remaining * inner_stride) - as isize, - ); + let last = self + .ptr + .add((outer_remaining * outer_stride + inner_remaining * inner_stride)); // We want either `& *last` or `&mut *last` here, depending // on the mutability of `$Ref`. + #[allow(clippy::transmute_ptr_to_ref)] Some(mem::transmute(last)) } } diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 5214bb6f..f2da8a8a 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -567,6 +567,7 @@ impl> Matrix { /// Tests whether `self` and `rhs` are exactly equal. #[inline] #[must_use] + #[allow(clippy::should_implement_trait)] pub fn eq(&self, other: &Matrix) -> bool where T: PartialEq, diff --git a/src/base/ops.rs b/src/base/ops.rs index f0780f7f..852f6490 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -529,7 +529,7 @@ macro_rules! left_scalar_mul_impl( // for rhs in res.iter_mut() { for rhs in res.as_mut_slice().iter_mut() { - *rhs = self * *rhs + *rhs *= self } res diff --git a/src/base/unit.rs b/src/base/unit.rs index b5a4096f..32eff82f 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -1,6 +1,5 @@ #[cfg(feature = "abomonation-serialize")] use std::io::{Result as IOResult, Write}; -use std::mem; use std::ops::Deref; #[cfg(feature = "serde-serialize-no-std")] @@ -228,8 +227,8 @@ impl Unit { /// Wraps the given reference, assuming it is already normalized. #[inline] - pub fn from_ref_unchecked<'a>(value: &'a T) -> &'a Self { - unsafe { mem::transmute(value) } + pub fn from_ref_unchecked(value: &T) -> &Self { + unsafe { &*(value as *const T as *const Self) } } /// Retrieves the underlying value. @@ -332,7 +331,7 @@ impl Deref for Unit { #[inline] fn deref(&self) -> &T { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const Self as *const T) } } } diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index cc5f0ab3..c312c048 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -143,9 +143,9 @@ impl VecStorage { } } -impl Into> for VecStorage { - fn into(self) -> Vec { - self.data +impl From> for Vec { + fn from(vec: VecStorage) -> Self { + vec.data } } diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 83912b9e..63148836 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + use crate::{ Isometry3, Matrix4, Normed, OVector, Point3, Quaternion, Scalar, SimdRealField, Translation3, Unit, UnitQuaternion, Vector3, Zero, U8, @@ -273,7 +276,7 @@ where impl DualQuaternion { fn to_vector(&self) -> OVector { - self.as_ref().clone().into() + (*self.as_ref()).into() } } @@ -618,9 +621,9 @@ where let other = { let dot_product = self.as_ref().real.coords.dot(&other.as_ref().real.coords); if dot_product < T::zero() { - -other.clone() + -*other } else { - other.clone() + *other } }; diff --git a/src/geometry/dual_quaternion_construction.rs b/src/geometry/dual_quaternion_construction.rs index be274cf4..ea4c7ee2 100644 --- a/src/geometry/dual_quaternion_construction.rs +++ b/src/geometry/dual_quaternion_construction.rs @@ -186,9 +186,9 @@ where pub fn from_parts(translation: Translation3, rotation: UnitQuaternion) -> Self { let half: T = crate::convert(0.5f64); UnitDualQuaternion::new_unchecked(DualQuaternion { - real: rotation.clone().into_inner(), + real: rotation.into_inner(), dual: Quaternion::from_parts(T::zero(), translation.vector) - * rotation.clone().into_inner() + * rotation.into_inner() * half, }) } diff --git a/src/geometry/dual_quaternion_ops.rs b/src/geometry/dual_quaternion_ops.rs index 46bc22b5..2a1527ec 100644 --- a/src/geometry/dual_quaternion_ops.rs +++ b/src/geometry/dual_quaternion_ops.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + /* * This file provides: * @@ -49,7 +52,6 @@ use crate::{ DualQuaternion, Isometry3, Point, Point3, Quaternion, SimdRealField, Translation3, Unit, UnitDualQuaternion, UnitQuaternion, Vector, Vector3, U3, }; -use std::mem; use std::ops::{ Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, }; @@ -57,14 +59,14 @@ use std::ops::{ impl AsRef<[T; 8]> for DualQuaternion { #[inline] fn as_ref(&self) -> &[T; 8] { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const Self as *const [T; 8]) } } } impl AsMut<[T; 8]> for DualQuaternion { #[inline] fn as_mut(&mut self) -> &mut [T; 8] { - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut Self as *mut [T; 8]) } } } @@ -564,7 +566,7 @@ dual_quaternion_op_impl!( (U4, U1), (U3, U1); self: &'a UnitDualQuaternion, rhs: &'b Translation3, Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); + self * UnitDualQuaternion::::from_parts(*rhs, UnitQuaternion::identity()); 'a, 'b); dual_quaternion_op_impl!( @@ -580,7 +582,7 @@ dual_quaternion_op_impl!( (U4, U1), (U3, U3); self: UnitDualQuaternion, rhs: &'b Translation3, Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); + self * UnitDualQuaternion::::from_parts(*rhs, UnitQuaternion::identity()); 'b); dual_quaternion_op_impl!( @@ -632,7 +634,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'b Translation3, rhs: &'a UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; + UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) * rhs; 'a, 'b); dual_quaternion_op_impl!( @@ -640,7 +642,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'a Translation3, rhs: UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; + UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) * rhs; 'a); dual_quaternion_op_impl!( @@ -664,7 +666,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'b Translation3, rhs: &'a UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; + UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) / rhs; 'a, 'b); dual_quaternion_op_impl!( @@ -672,7 +674,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'a Translation3, rhs: UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; + UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) / rhs; 'a); dual_quaternion_op_impl!( @@ -860,7 +862,7 @@ dual_quaternion_op_impl!( Output = Point3 => U3, U1; { let two: T = crate::convert(2.0f64); - let q_point = Quaternion::from_parts(T::zero(), rhs.coords.clone()); + let q_point = Quaternion::from_parts(T::zero(), rhs.coords); Point::from( ((self.as_ref().real * q_point + self.as_ref().dual * two) * self.as_ref().real.conjugate()) .vector() @@ -1115,7 +1117,7 @@ dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); self: UnitDualQuaternion, rhs: &'b UnitQuaternion; - *self *= rhs.clone(); 'b); + *self *= *rhs; 'b); // UnitDualQuaternion ÷= UnitQuaternion dual_quaternion_op_impl!( @@ -1151,7 +1153,7 @@ dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); self: UnitDualQuaternion, rhs: &'b Translation3; - *self *= rhs.clone(); 'b); + *self *= *rhs; 'b); // UnitDualQuaternion ÷= Translation3 dual_quaternion_op_impl!( diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 6d3e9127..7d8c6e95 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -270,7 +270,7 @@ where #[must_use] pub fn inv_mul(&self, rhs: &Isometry) -> Self { let inv_rot1 = self.rotation.inverse(); - let tr_12 = rhs.translation.vector.clone() - self.translation.vector.clone(); + let tr_12 = rhs.translation.vector - self.translation.vector; Isometry::from_parts( inv_rot1.transform_vector(&tr_12).into(), inv_rot1 * rhs.rotation.clone(), @@ -435,7 +435,7 @@ where #[must_use] pub fn inverse_transform_point(&self, pt: &Point) -> Point { self.rotation - .inverse_transform_point(&(pt - &self.translation.vector)) + .inverse_transform_point(&(pt - self.translation.vector)) } /// Transform the given vector by the inverse of this isometry, ignoring the diff --git a/src/geometry/isometry_conversion.rs b/src/geometry/isometry_conversion.rs index 75c0d98d..627ea3ee 100644 --- a/src/geometry/isometry_conversion.rs +++ b/src/geometry/isometry_conversion.rs @@ -239,7 +239,7 @@ where { #[inline] fn from(arr: [Isometry; 2]) -> Self { - let tra = Translation::from([arr[0].translation.clone(), arr[1].translation.clone()]); + let tra = Translation::from([arr[0].translation, arr[1].translation]); let rot = R::from([arr[0].rotation, arr[0].rotation]); Self::from_parts(tra, rot) @@ -258,10 +258,10 @@ where #[inline] fn from(arr: [Isometry; 4]) -> Self { let tra = Translation::from([ - arr[0].translation.clone(), - arr[1].translation.clone(), - arr[2].translation.clone(), - arr[3].translation.clone(), + arr[0].translation, + arr[1].translation, + arr[2].translation, + arr[3].translation, ]); let rot = R::from([ arr[0].rotation, @@ -286,14 +286,14 @@ where #[inline] fn from(arr: [Isometry; 8]) -> Self { let tra = Translation::from([ - arr[0].translation.clone(), - arr[1].translation.clone(), - arr[2].translation.clone(), - arr[3].translation.clone(), - arr[4].translation.clone(), - arr[5].translation.clone(), - arr[6].translation.clone(), - arr[7].translation.clone(), + arr[0].translation, + arr[1].translation, + arr[2].translation, + arr[3].translation, + arr[4].translation, + arr[5].translation, + arr[6].translation, + arr[7].translation, ]); let rot = R::from([ arr[0].rotation, @@ -322,22 +322,22 @@ where #[inline] fn from(arr: [Isometry; 16]) -> Self { let tra = Translation::from([ - arr[0].translation.clone(), - arr[1].translation.clone(), - arr[2].translation.clone(), - arr[3].translation.clone(), - arr[4].translation.clone(), - arr[5].translation.clone(), - arr[6].translation.clone(), - arr[7].translation.clone(), - arr[8].translation.clone(), - arr[9].translation.clone(), - arr[10].translation.clone(), - arr[11].translation.clone(), - arr[12].translation.clone(), - arr[13].translation.clone(), - arr[14].translation.clone(), - arr[15].translation.clone(), + arr[0].translation, + arr[1].translation, + arr[2].translation, + arr[3].translation, + arr[4].translation, + arr[5].translation, + arr[6].translation, + arr[7].translation, + arr[8].translation, + arr[9].translation, + arr[10].translation, + arr[11].translation, + arr[12].translation, + arr[13].translation, + arr[14].translation, + arr[15].translation, ]); let rot = R::from([ arr[0].rotation, diff --git a/src/geometry/isometry_ops.rs b/src/geometry/isometry_ops.rs index 2e6477b5..5cf5ec35 100644 --- a/src/geometry/isometry_ops.rs +++ b/src/geometry/isometry_ops.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + use num::{One, Zero}; use std::ops::{Div, DivAssign, Mul, MulAssign}; @@ -198,7 +201,7 @@ md_assign_impl_all!( const D; for; where; self: Isometry, D>, rhs: Rotation; [val] => self.rotation *= rhs; - [ref] => self.rotation *= rhs.clone(); + [ref] => self.rotation *= *rhs; ); md_assign_impl_all!( @@ -365,9 +368,9 @@ isometry_from_composition_impl_all!( D; self: Rotation, right: Translation, Output = Isometry, D>; [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); - [ref val] => Isometry::from_parts(Translation::from(self * right.vector), self.clone()); + [ref val] => Isometry::from_parts(Translation::from(self * right.vector), *self); [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); - [ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), self.clone()); + [ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), *self); ); // UnitQuaternion × Translation @@ -389,9 +392,9 @@ isometry_from_composition_impl_all!( self: Isometry, D>, rhs: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); - [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); // TODO: do not clone. - [val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone()); - [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs.clone()); + [ref val] => Isometry::from_parts(self.translation, self.rotation * rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); + [ref ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); ); // Rotation × Isometry @@ -416,9 +419,9 @@ isometry_from_composition_impl_all!( self: Isometry, D>, rhs: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); - [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); // TODO: do not clone. - [val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone()); - [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs.clone()); + [ref val] => Isometry::from_parts(self.translation, self.rotation / rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); + [ref ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); ); // Rotation ÷ Isometry @@ -441,9 +444,9 @@ isometry_from_composition_impl_all!( self: Isometry, 3>, rhs: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); - [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation * rhs); // TODO: do not clone. + [ref val] => Isometry::from_parts(self.translation, self.rotation * rhs); [val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); - [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation * *rhs); + [ref ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); ); // UnitQuaternion × Isometry @@ -468,9 +471,9 @@ isometry_from_composition_impl_all!( self: Isometry, 3>, rhs: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); - [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation / rhs); // TODO: do not clone. + [ref val] => Isometry::from_parts(self.translation, self.rotation / rhs); [val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); - [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation / *rhs); + [ref ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); ); // UnitQuaternion ÷ Isometry @@ -492,9 +495,9 @@ isometry_from_composition_impl_all!( D; self: Translation, right: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self, right); - [ref val] => Isometry::from_parts(self.clone(), right); - [val ref] => Isometry::from_parts(self, right.clone()); - [ref ref] => Isometry::from_parts(self.clone(), right.clone()); + [ref val] => Isometry::from_parts(*self, right); + [val ref] => Isometry::from_parts(self, *right); + [ref ref] => Isometry::from_parts(*self, *right); ); // Translation × UnitQuaternion @@ -503,9 +506,9 @@ isometry_from_composition_impl_all!( ; self: Translation, right: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self, right); - [ref val] => Isometry::from_parts(self.clone(), right); + [ref val] => Isometry::from_parts(*self, right); [val ref] => Isometry::from_parts(self, *right); - [ref ref] => Isometry::from_parts(self.clone(), *right); + [ref ref] => Isometry::from_parts(*self, *right); ); // Isometry × UnitComplex @@ -515,9 +518,9 @@ isometry_from_composition_impl_all!( self: Isometry, 2>, rhs: UnitComplex, Output = Isometry, 2>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); - [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation * rhs); // TODO: do not clone. + [ref val] => Isometry::from_parts(self.translation, self.rotation * rhs); [val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); - [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation * *rhs); + [ref ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); ); // Isometry ÷ UnitComplex @@ -527,7 +530,7 @@ isometry_from_composition_impl_all!( self: Isometry, 2>, rhs: UnitComplex, Output = Isometry, 2>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); - [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation / rhs); // TODO: do not clone. + [ref val] => Isometry::from_parts(self.translation, self.rotation / rhs); [val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); - [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation / *rhs); + [ref ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); ); diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 6cc4dacc..17a5b969 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -8,7 +8,6 @@ use rand::{ #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; -use std::mem; use simba::scalar::RealField; @@ -258,7 +257,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn as_projective(&self) -> &Projective3 { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const Orthographic3 as *const Projective3) } } /// This transformation seen as a `Projective3`. diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 65aee5fd..6ad9707f 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -9,7 +9,6 @@ use rand::{ #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; -use std::mem; use simba::scalar::RealField; @@ -140,7 +139,7 @@ impl Perspective3 { #[inline] #[must_use] pub fn as_projective(&self) -> &Projective3 { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const Perspective3 as *const Projective3) } } /// This transformation seen as a `Projective3`. @@ -256,8 +255,9 @@ impl Perspective3 { #[inline] pub fn set_fovy(&mut self, fovy: T) { let old_m22 = self.matrix[(1, 1)]; - self.matrix[(1, 1)] = T::one() / (fovy / crate::convert(2.0)).tan(); - self.matrix[(0, 0)] = self.matrix[(0, 0)] * (self.matrix[(1, 1)] / old_m22); + let new_m22 = T::one() / (fovy / crate::convert(2.0)).tan(); + self.matrix[(1, 1)] = new_m22; + self.matrix[(0, 0)] *= new_m22 / old_m22; } /// Updates this perspective matrix with a new near plane offset of the view frustum. diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index 91cd62ce..e5ab8272 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -90,10 +90,10 @@ impl From<[T; D]> for Point { } } -impl Into<[T; D]> for Point { +impl From> for [T; D] { #[inline] - fn into(self) -> [T; D] { - self.coords.into() + fn from(p: Point) -> Self { + p.coords.into() } } diff --git a/src/geometry/quaternion_coordinates.rs b/src/geometry/quaternion_coordinates.rs index d9901888..cb16e59e 100644 --- a/src/geometry/quaternion_coordinates.rs +++ b/src/geometry/quaternion_coordinates.rs @@ -1,4 +1,3 @@ -use std::mem; use std::ops::{Deref, DerefMut}; use simba::simd::SimdValue; @@ -13,13 +12,13 @@ impl Deref for Quaternion { #[inline] fn deref(&self) -> &Self::Target { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const Self as *const Self::Target) } } } impl DerefMut for Quaternion { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut Self as *mut Self::Target) } } } diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index 6a2c87a0..eb7a15cd 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + /* * This file provides: * =================== diff --git a/src/geometry/rotation_conversion.rs b/src/geometry/rotation_conversion.rs index 0e83d60f..517010a0 100644 --- a/src/geometry/rotation_conversion.rs +++ b/src/geometry/rotation_conversion.rs @@ -267,10 +267,7 @@ where { #[inline] fn from(arr: [Rotation; 2]) -> Self { - Self::from_matrix_unchecked(OMatrix::from([ - arr[0].clone().into_inner(), - arr[1].clone().into_inner(), - ])) + Self::from_matrix_unchecked(OMatrix::from([arr[0].into_inner(), arr[1].into_inner()])) } } @@ -283,10 +280,10 @@ where #[inline] fn from(arr: [Rotation; 4]) -> Self { Self::from_matrix_unchecked(OMatrix::from([ - arr[0].clone().into_inner(), - arr[1].clone().into_inner(), - arr[2].clone().into_inner(), - arr[3].clone().into_inner(), + arr[0].into_inner(), + arr[1].into_inner(), + arr[2].into_inner(), + arr[3].into_inner(), ])) } } @@ -300,14 +297,14 @@ where #[inline] fn from(arr: [Rotation; 8]) -> Self { Self::from_matrix_unchecked(OMatrix::from([ - arr[0].clone().into_inner(), - arr[1].clone().into_inner(), - arr[2].clone().into_inner(), - arr[3].clone().into_inner(), - arr[4].clone().into_inner(), - arr[5].clone().into_inner(), - arr[6].clone().into_inner(), - arr[7].clone().into_inner(), + arr[0].into_inner(), + arr[1].into_inner(), + arr[2].into_inner(), + arr[3].into_inner(), + arr[4].into_inner(), + arr[5].into_inner(), + arr[6].into_inner(), + arr[7].into_inner(), ])) } } @@ -321,22 +318,22 @@ where #[inline] fn from(arr: [Rotation; 16]) -> Self { Self::from_matrix_unchecked(OMatrix::from([ - arr[0].clone().into_inner(), - arr[1].clone().into_inner(), - arr[2].clone().into_inner(), - arr[3].clone().into_inner(), - arr[4].clone().into_inner(), - arr[5].clone().into_inner(), - arr[6].clone().into_inner(), - arr[7].clone().into_inner(), - arr[8].clone().into_inner(), - arr[9].clone().into_inner(), - arr[10].clone().into_inner(), - arr[11].clone().into_inner(), - arr[12].clone().into_inner(), - arr[13].clone().into_inner(), - arr[14].clone().into_inner(), - arr[15].clone().into_inner(), + arr[0].into_inner(), + arr[1].into_inner(), + arr[2].into_inner(), + arr[3].into_inner(), + arr[4].into_inner(), + arr[5].into_inner(), + arr[6].into_inner(), + arr[7].into_inner(), + arr[8].into_inner(), + arr[9].into_inner(), + arr[10].into_inner(), + arr[11].into_inner(), + arr[12].into_inner(), + arr[13].into_inner(), + arr[14].into_inner(), + arr[15].into_inner(), ])) } } diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index a89f5845..6c9ecf21 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -857,11 +857,7 @@ impl Rotation3 { where T: RealField, { - if let Some(axis) = self.axis() { - Some((axis, self.angle())) - } else { - None - } + self.axis().map(|axis| (axis, self.angle())) } /// The rotation angle needed to make `self` and `other` coincide. diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 516b95c5..48ce6a85 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -178,7 +178,7 @@ where ); Self::from_parts( - Translation::from(&self.isometry.translation.vector * scaling), + Translation::from(self.isometry.translation.vector * scaling), self.isometry.rotation.clone(), self.scaling * scaling, ) diff --git a/src/geometry/similarity_conversion.rs b/src/geometry/similarity_conversion.rs index 2a2338b0..6bc12814 100644 --- a/src/geometry/similarity_conversion.rs +++ b/src/geometry/similarity_conversion.rs @@ -197,7 +197,7 @@ where { #[inline] fn from(arr: [Similarity; 2]) -> Self { - let iso = Isometry::from([arr[0].isometry.clone(), arr[1].isometry.clone()]); + let iso = Isometry::from([arr[0].isometry, arr[1].isometry]); let scale = T::from([arr[0].scaling(), arr[1].scaling()]); Self::from_isometry(iso, scale) @@ -216,10 +216,10 @@ where #[inline] fn from(arr: [Similarity; 4]) -> Self { let iso = Isometry::from([ - arr[0].isometry.clone(), - arr[1].isometry.clone(), - arr[2].isometry.clone(), - arr[3].isometry.clone(), + arr[0].isometry, + arr[1].isometry, + arr[2].isometry, + arr[3].isometry, ]); let scale = T::from([ arr[0].scaling(), @@ -244,14 +244,14 @@ where #[inline] fn from(arr: [Similarity; 8]) -> Self { let iso = Isometry::from([ - arr[0].isometry.clone(), - arr[1].isometry.clone(), - arr[2].isometry.clone(), - arr[3].isometry.clone(), - arr[4].isometry.clone(), - arr[5].isometry.clone(), - arr[6].isometry.clone(), - arr[7].isometry.clone(), + arr[0].isometry, + arr[1].isometry, + arr[2].isometry, + arr[3].isometry, + arr[4].isometry, + arr[5].isometry, + arr[6].isometry, + arr[7].isometry, ]); let scale = T::from([ arr[0].scaling(), @@ -280,22 +280,22 @@ where #[inline] fn from(arr: [Similarity; 16]) -> Self { let iso = Isometry::from([ - arr[0].isometry.clone(), - arr[1].isometry.clone(), - arr[2].isometry.clone(), - arr[3].isometry.clone(), - arr[4].isometry.clone(), - arr[5].isometry.clone(), - arr[6].isometry.clone(), - arr[7].isometry.clone(), - arr[8].isometry.clone(), - arr[9].isometry.clone(), - arr[10].isometry.clone(), - arr[11].isometry.clone(), - arr[12].isometry.clone(), - arr[13].isometry.clone(), - arr[14].isometry.clone(), - arr[15].isometry.clone(), + arr[0].isometry, + arr[1].isometry, + arr[2].isometry, + arr[3].isometry, + arr[4].isometry, + arr[5].isometry, + arr[6].isometry, + arr[7].isometry, + arr[8].isometry, + arr[9].isometry, + arr[10].isometry, + arr[11].isometry, + arr[12].isometry, + arr[13].isometry, + arr[14].isometry, + arr[15].isometry, ]); let scale = T::from([ arr[0].scaling(), diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index c164acaa..b88f9442 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + use num::{One, Zero}; use std::ops::{Div, DivAssign, Mul, MulAssign}; @@ -219,7 +222,7 @@ md_assign_impl_all!( const D; for; where; self: Similarity, D>, rhs: Rotation; [val] => self.isometry.rotation *= rhs; - [ref] => self.isometry.rotation *= rhs.clone(); + [ref] => self.isometry.rotation *= *rhs; ); md_assign_impl_all!( diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 8c294b15..682d2bd6 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -399,11 +399,9 @@ where #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn try_inverse(self) -> Option> { - if let Some(m) = self.matrix.try_inverse() { - Some(Transform::from_matrix_unchecked(m)) - } else { - None - } + self.matrix + .try_inverse() + .map(Transform::from_matrix_unchecked) } /// Inverts this transformation. Use `.try_inverse` if this transform has the `TGeneral` diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index 29781c3c..efbfa67b 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + use num::{One, Zero}; use std::ops::{Div, DivAssign, Index, IndexMut, Mul, MulAssign}; diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 1476e75b..18fa7e04 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -38,7 +38,7 @@ where } } -impl Copy for Translation where Owned>: Copy {} +impl Copy for Translation {} impl Clone for Translation where diff --git a/src/geometry/translation_conversion.rs b/src/geometry/translation_conversion.rs index ff8e797f..d443a2f4 100644 --- a/src/geometry/translation_conversion.rs +++ b/src/geometry/translation_conversion.rs @@ -77,7 +77,7 @@ where { #[inline] fn to_superset(&self) -> UnitDualQuaternion { - let dq = UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()); + let dq = UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()); dq.to_superset() } @@ -212,16 +212,14 @@ impl From<[T; D]> for Translation { impl From> for Translation { #[inline] fn from(pt: Point) -> Self { - Translation { - vector: pt.coords.into(), - } + Translation { vector: pt.coords } } } -impl Into<[T; D]> for Translation { +impl From> for [T; D] { #[inline] - fn into(self) -> [T; D] { - self.vector.into() + fn from(t: Translation) -> Self { + t.vector.into() } } diff --git a/src/geometry/translation_coordinates.rs b/src/geometry/translation_coordinates.rs index 9a9bf44a..80267e06 100644 --- a/src/geometry/translation_coordinates.rs +++ b/src/geometry/translation_coordinates.rs @@ -1,4 +1,3 @@ -use std::mem; use std::ops::{Deref, DerefMut}; use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB}; @@ -19,15 +18,14 @@ macro_rules! deref_impl( #[inline] fn deref(&self) -> &Self::Target { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const Translation as *const Self::Target) } } } - impl DerefMut for Translation - { + impl DerefMut for Translation { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut Translation as *mut Self::Target) } } } } diff --git a/src/geometry/unit_complex_ops.rs b/src/geometry/unit_complex_ops.rs index abaa9d4f..efa91a95 100644 --- a/src/geometry/unit_complex_ops.rs +++ b/src/geometry/unit_complex_ops.rs @@ -1,3 +1,6 @@ +// The macros break if the references are taken out, for some reason. +#![allow(clippy::op_ref)] + use std::ops::{Div, DivAssign, Mul, MulAssign}; use crate::base::storage::Storage; @@ -314,10 +317,10 @@ complex_op_impl_all!( ; self: Translation, right: UnitComplex, Output = Isometry, 2>; - [val val] => Isometry::from_parts(self, right); - [ref val] => Isometry::from_parts(self.clone(), right); - [val ref] => Isometry::from_parts(self, *right); - [ref ref] => Isometry::from_parts(self.clone(), *right); + [val val] => Isometry::from_parts(self, right); + [ref val] => Isometry::from_parts(*self, right); + [val ref] => Isometry::from_parts(self, *right); + [ref ref] => Isometry::from_parts(*self, *right); ); // UnitComplex ×= UnitComplex @@ -327,7 +330,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: UnitComplex) { - *self = &*self * rhs + *self = *self * rhs } } @@ -337,7 +340,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: &'b UnitComplex) { - *self = &*self * rhs + *self = *self * rhs } } @@ -348,7 +351,7 @@ where { #[inline] fn div_assign(&mut self, rhs: UnitComplex) { - *self = &*self / rhs + *self = *self / rhs } } @@ -358,7 +361,7 @@ where { #[inline] fn div_assign(&mut self, rhs: &'b UnitComplex) { - *self = &*self / rhs + *self = *self / rhs } } @@ -369,7 +372,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: Rotation) { - *self = &*self * rhs + *self = *self * rhs } } @@ -379,7 +382,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: &'b Rotation) { - *self = &*self * rhs + *self = *self * rhs } } @@ -390,7 +393,7 @@ where { #[inline] fn div_assign(&mut self, rhs: Rotation) { - *self = &*self / rhs + *self = *self / rhs } } @@ -400,7 +403,7 @@ where { #[inline] fn div_assign(&mut self, rhs: &'b Rotation) { - *self = &*self / rhs + *self = *self / rhs } } diff --git a/src/lib.rs b/src/lib.rs index a978d5f5..04bc4002 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::type_complexity)] /*! # nalgebra @@ -199,19 +200,15 @@ where while val < min { val += width } - - val } else if val > max { val -= width; while val > max { val -= width } - - val - } else { - val } + + val } /// Returns a reference to the input value clamped to the interval `[min, max]`. @@ -393,7 +390,7 @@ pub fn center( p1: &Point, p2: &Point, ) -> Point { - ((&p1.coords + &p2.coords) * convert::<_, T>(0.5)).into() + ((p1.coords + p2.coords) * convert::<_, T>(0.5)).into() } /// The distance between two points. @@ -407,7 +404,7 @@ pub fn distance( p1: &Point, p2: &Point, ) -> T::SimdRealField { - (&p2.coords - &p1.coords).norm() + (p2.coords - p1.coords).norm() } /// The squared distance between two points. @@ -421,7 +418,7 @@ pub fn distance_squared( p1: &Point, p2: &Point, ) -> T::SimdRealField { - (&p2.coords - &p1.coords).norm_squared() + (p2.coords - p1.coords).norm_squared() } /* diff --git a/src/linalg/balancing.rs b/src/linalg/balancing.rs index 3b834563..3965caf1 100644 --- a/src/linalg/balancing.rs +++ b/src/linalg/balancing.rs @@ -8,17 +8,17 @@ use crate::base::dimension::Dim; use crate::base::storage::Storage; use crate::base::{Const, DefaultAllocator, OMatrix, OVector}; -/// Applies in-place a modified Parlett and Reinsch matrix balancing with 2-norm to the matrix `m` and returns +/// Applies in-place a modified Parlett and Reinsch matrix balancing with 2-norm to the matrix and returns /// the corresponding diagonal transformation. /// /// See https://arxiv.org/pdf/1401.5766.pdf -pub fn balance_parlett_reinsch(m: &mut OMatrix) -> OVector +pub fn balance_parlett_reinsch(matrix: &mut OMatrix) -> OVector where DefaultAllocator: Allocator + Allocator, { - assert!(m.is_square(), "Unable to balance a non-square matrix."); + assert!(matrix.is_square(), "Unable to balance a non-square matrix."); - let dim = m.data.shape().0; + let dim = matrix.data.shape().0; let radix: T = crate::convert(2.0f64); let mut d = OVector::from_element_generic(dim, Const::<1>, T::one()); @@ -28,36 +28,37 @@ where converged = true; for i in 0..dim.value() { - let mut c = m.column(i).norm_squared(); - let mut r = m.row(i).norm_squared(); + let mut n_col = matrix.column(i).norm_squared(); + let mut n_row = matrix.row(i).norm_squared(); let mut f = T::one(); - let s = c + r; - c = c.sqrt(); - r = r.sqrt(); + let s = n_col + n_row; + n_col = n_col.sqrt(); + n_row = n_row.sqrt(); - if c.is_zero() || r.is_zero() { + if n_col.is_zero() || n_row.is_zero() { continue; } - while c < r / radix { - c *= radix; - r /= radix; + while n_col < n_row / radix { + n_col *= radix; + n_row /= radix; f *= radix; } - while c >= r * radix { - c /= radix; - r *= radix; + while n_col >= n_row * radix { + n_col /= radix; + n_row *= radix; f /= radix; } let eps: T = crate::convert(0.95); - if c * c + r * r < eps * s { + #[allow(clippy::suspicious_operation_groupings)] + if n_col * n_col + n_row * n_row < eps * s { converged = false; d[i] *= f; - m.column_mut(i).mul_assign(f); - m.row_mut(i).div_assign(f); + matrix.column_mut(i).mul_assign(f); + matrix.row_mut(i).div_assign(f); } } } diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index acb2b9e3..c2816ff0 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -442,31 +442,31 @@ where return self.map(|v| v.exp()); } - let mut h = ExpmPadeHelper::new(self.clone(), true); + let mut helper = ExpmPadeHelper::new(self.clone(), true); - let eta_1 = T::RealField::max(h.d4_loose(), h.d6_loose()); - if eta_1 < convert(1.495_585_217_958_292e-2) && ell(&h.a, 3) == 0 { - let (u, v) = h.pade3(); + let eta_1 = T::RealField::max(helper.d4_loose(), helper.d6_loose()); + if eta_1 < convert(1.495_585_217_958_292e-2) && ell(&helper.a, 3) == 0 { + let (u, v) = helper.pade3(); return solve_p_q(u, v); } - let eta_2 = T::RealField::max(h.d4_tight(), h.d6_loose()); - if eta_2 < convert(2.539_398_330_063_230e-1) && ell(&h.a, 5) == 0 { - let (u, v) = h.pade5(); + let eta_2 = T::RealField::max(helper.d4_tight(), helper.d6_loose()); + if eta_2 < convert(2.539_398_330_063_23e-1) && ell(&helper.a, 5) == 0 { + let (u, v) = helper.pade5(); return solve_p_q(u, v); } - let eta_3 = T::RealField::max(h.d6_tight(), h.d8_loose()); - if eta_3 < convert(9.504_178_996_162_932e-1) && ell(&h.a, 7) == 0 { - let (u, v) = h.pade7(); + let eta_3 = T::RealField::max(helper.d6_tight(), helper.d8_loose()); + if eta_3 < convert(9.504_178_996_162_932e-1) && ell(&helper.a, 7) == 0 { + let (u, v) = helper.pade7(); return solve_p_q(u, v); } - if eta_3 < convert(2.097_847_961_257_068e+0) && ell(&h.a, 9) == 0 { - let (u, v) = h.pade9(); + if eta_3 < convert(2.097_847_961_257_068e0) && ell(&helper.a, 9) == 0 { + let (u, v) = helper.pade9(); return solve_p_q(u, v); } - let eta_4 = T::RealField::max(h.d8_loose(), h.d10_loose()); + let eta_4 = T::RealField::max(helper.d8_loose(), helper.d10_loose()); let eta_5 = T::RealField::min(eta_3, eta_4); let theta_13 = convert(4.25); @@ -482,9 +482,12 @@ where } }; - s += ell(&(&h.a * convert::(2.0_f64.powf(-(s as f64)))), 13); + s += ell( + &(&helper.a * convert::(2.0_f64.powf(-(s as f64)))), + 13, + ); - let (u, v) = h.pade13_scaled(s); + let (u, v) = helper.pade13_scaled(s); let mut x = solve_p_q(u, v); for _ in 0..s { diff --git a/src/linalg/pow.rs b/src/linalg/pow.rs index 74da2cfe..df513643 100644 --- a/src/linalg/pow.rs +++ b/src/linalg/pow.rs @@ -31,10 +31,8 @@ where // If e is negative, we compute the inverse matrix, then raise it to the // power of -e. - if e < zero { - if !self.try_inverse_mut() { - return false; - } + if e < zero && !self.try_inverse_mut() { + return false; } let one = I::one(); diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index 16b8c66d..c03f6f08 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -1,3 +1,4 @@ +#![allow(clippy::suspicious_operation_groupings)] #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Serialize}; diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index f559c9fa..241f00ce 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -121,11 +121,15 @@ where matrix.unscale_mut(m_amax); } - let b = Bidiagonal::new(matrix); - let mut u = if compute_u { Some(b.u()) } else { None }; - let mut v_t = if compute_v { Some(b.v_t()) } else { None }; - let mut diagonal = b.diagonal(); - let mut off_diagonal = b.off_diagonal(); + let bi_matrix = Bidiagonal::new(matrix); + let mut u = if compute_u { Some(bi_matrix.u()) } else { None }; + let mut v_t = if compute_v { + Some(bi_matrix.v_t()) + } else { + None + }; + let mut diagonal = bi_matrix.diagonal(); + let mut off_diagonal = bi_matrix.off_diagonal(); let mut niter = 0; let (mut start, mut end) = Self::delimit_subproblem( @@ -133,7 +137,7 @@ where &mut off_diagonal, &mut u, &mut v_t, - b.is_upper_diagonal(), + bi_matrix.is_upper_diagonal(), dim - 1, eps, ); @@ -142,6 +146,7 @@ where let subdim = end - start + 1; // Solve the subproblem. + #[allow(clippy::comparison_chain)] if subdim > 2 { let m = end - 1; let n = end; @@ -201,7 +206,7 @@ where subm[(0, 0)] = norm2; if let Some(ref mut v_t) = v_t { - if b.is_upper_diagonal() { + if bi_matrix.is_upper_diagonal() { rot1.rotate(&mut v_t.fixed_rows_mut::<2>(k)); } else { rot2.rotate(&mut v_t.fixed_rows_mut::<2>(k)); @@ -209,7 +214,7 @@ where } if let Some(ref mut u) = u { - if b.is_upper_diagonal() { + if bi_matrix.is_upper_diagonal() { rot2.inverse().rotate_rows(&mut u.fixed_columns_mut::<2>(k)); } else { rot1.inverse().rotate_rows(&mut u.fixed_columns_mut::<2>(k)); @@ -236,8 +241,10 @@ where diagonal[start], off_diagonal[start], diagonal[start + 1], - compute_u && b.is_upper_diagonal() || compute_v && !b.is_upper_diagonal(), - compute_v && b.is_upper_diagonal() || compute_u && !b.is_upper_diagonal(), + compute_u && bi_matrix.is_upper_diagonal() + || compute_v && !bi_matrix.is_upper_diagonal(), + compute_v && bi_matrix.is_upper_diagonal() + || compute_u && !bi_matrix.is_upper_diagonal(), ); let u2 = u2.map(|u2| GivensRotation::new_unchecked(u2.c(), T::from_real(u2.s()))); let v2 = v2.map(|v2| GivensRotation::new_unchecked(v2.c(), T::from_real(v2.s()))); @@ -247,7 +254,7 @@ where off_diagonal[start] = T::RealField::zero(); if let Some(ref mut u) = u { - let rot = if b.is_upper_diagonal() { + let rot = if bi_matrix.is_upper_diagonal() { u2.unwrap() } else { v2.unwrap() @@ -256,7 +263,7 @@ where } if let Some(ref mut v_t) = v_t { - let rot = if b.is_upper_diagonal() { + let rot = if bi_matrix.is_upper_diagonal() { v2.unwrap() } else { u2.unwrap() @@ -273,7 +280,7 @@ where &mut off_diagonal, &mut u, &mut v_t, - b.is_upper_diagonal(), + bi_matrix.is_upper_diagonal(), end, eps, ); diff --git a/src/linalg/symmetric_eigen.rs b/src/linalg/symmetric_eigen.rs index 25dab08c..5ac6d5da 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -87,7 +87,7 @@ where } fn do_decompose( - mut m: OMatrix, + mut matrix: OMatrix, eigenvectors: bool, eps: T::RealField, max_niter: usize, @@ -97,33 +97,33 @@ where DefaultAllocator: Allocator> + Allocator>, { assert!( - m.is_square(), + matrix.is_square(), "Unable to compute the eigendecomposition of a non-square matrix." ); - let dim = m.nrows(); - let m_amax = m.camax(); + let dim = matrix.nrows(); + let m_amax = matrix.camax(); if !m_amax.is_zero() { - m.unscale_mut(m_amax); + matrix.unscale_mut(m_amax); } - let (mut q, mut diag, mut off_diag); + let (mut q_mat, mut diag, mut off_diag); if eigenvectors { - let res = SymmetricTridiagonal::new(m).unpack(); - q = Some(res.0); + let res = SymmetricTridiagonal::new(matrix).unpack(); + q_mat = Some(res.0); diag = res.1; off_diag = res.2; } else { - let res = SymmetricTridiagonal::new(m).unpack_tridiagonal(); - q = None; + let res = SymmetricTridiagonal::new(matrix).unpack_tridiagonal(); + q_mat = None; diag = res.0; off_diag = res.1; } if dim == 1 { diag.scale_mut(m_amax); - return Some((diag, q)); + return Some((diag, q_mat)); } let mut niter = 0; @@ -132,11 +132,12 @@ where while end != start { let subdim = end - start + 1; + #[allow(clippy::comparison_chain)] if subdim > 2 { let m = end - 1; let n = end; - let mut v = Vector2::new( + let mut vec = Vector2::new( diag[start] - wilkinson_shift(diag[m], diag[n], off_diag[m]), off_diag[start], ); @@ -144,7 +145,7 @@ where for i in start..n { let j = i + 1; - if let Some((rot, norm)) = GivensRotation::cancel_y(&v) { + if let Some((rot, norm)) = GivensRotation::cancel_y(&vec) { if i > start { // Not the first iteration. off_diag[i - 1] = norm; @@ -165,12 +166,12 @@ where off_diag[i] = cs * (mii - mjj) + mij * (cc - ss); if i != n - 1 { - v.x = off_diag[i]; - v.y = -rot.s() * off_diag[i + 1]; + vec.x = off_diag[i]; + vec.y = -rot.s() * off_diag[i + 1]; off_diag[i + 1] *= rot.c(); } - if let Some(ref mut q) = q { + if let Some(ref mut q) = q_mat { let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); rot.inverse().rotate_rows(&mut q.fixed_columns_mut::<2>(i)); } @@ -195,7 +196,7 @@ where diag[start] = eigvals[0]; diag[start + 1] = eigvals[1]; - if let Some(ref mut q) = q { + if let Some(ref mut q) = q_mat { if let Some((rot, _)) = GivensRotation::try_new(basis.x, basis.y, eps) { let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); rot.rotate_rows(&mut q.fixed_columns_mut::<2>(start)); @@ -219,7 +220,7 @@ where diag.scale_mut(m_amax); - Some((diag, q)) + Some((diag, q_mat)) } fn delimit_subproblem( diff --git a/tests/linalg/convolution.rs b/tests/linalg/convolution.rs index 84f42a6e..b2e151d3 100644 --- a/tests/linalg/convolution.rs +++ b/tests/linalg/convolution.rs @@ -26,18 +26,20 @@ fn convolve_same_check() { // Panic Tests // These really only apply to dynamic sized vectors assert!(panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0]) + let _ = DVector::from_vec(vec![1.0, 2.0]) .convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); }) .is_err()); assert!(panic::catch_unwind(|| { - DVector::::from_vec(vec![]).convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + let _ = DVector::::from_vec(vec![]) + .convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); }) .is_err()); assert!(panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_same(DVector::::from_vec(vec![])); + let _ = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]) + .convolve_same(DVector::::from_vec(vec![])); }) .is_err()); }