From ea9a9e8b7f4afb1dd173b65e9cd93b3fd049dcef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lauzier?= Date: Sun, 15 Aug 2021 12:12:17 -0400 Subject: [PATCH] Fix some clippy warnings --- examples/mvp.rs | 3 ++- examples/raw_pointer.rs | 1 + examples/screen_to_view_coords.rs | 3 ++- examples/transform_conversion.rs | 5 ++-- examples/transform_matrix4.rs | 3 ++- examples/transformation_pointer.rs | 1 + examples/unit_wrapper.rs | 1 + src/base/edition.rs | 6 ++--- src/base/indexing.rs | 43 +++++++++++++++--------------- src/base/matrix.rs | 2 +- src/base/min_max.rs | 4 +-- src/base/norm.rs | 7 +---- src/base/uninit.rs | 4 +-- src/geometry/dual_quaternion.rs | 2 +- src/geometry/orthographic.rs | 2 +- src/geometry/quaternion.rs | 14 +++++----- src/linalg/determinant.rs | 2 +- src/linalg/exp.rs | 1 + src/linalg/givens.rs | 2 +- 19 files changed, 54 insertions(+), 52 deletions(-) diff --git a/examples/mvp.rs b/examples/mvp.rs index 3ccb2549..add7ac8f 100644 --- a/examples/mvp.rs +++ b/examples/mvp.rs @@ -3,6 +3,7 @@ extern crate nalgebra as na; use na::{Isometry3, Perspective3, Point3, Vector3}; +use std::f32::consts; fn main() { // Our object is translated along the x axis. @@ -15,7 +16,7 @@ fn main() { let view = Isometry3::look_at_rh(&eye, &target, &Vector3::y()); // A perspective projection. - let projection = Perspective3::new(16.0 / 9.0, 3.14 / 2.0, 1.0, 1000.0); + let projection = Perspective3::new(16.0 / 9.0, consts::PI / 2.0, 1.0, 1000.0); // The combination of the model with the view is still an isometry. let model_view = view * model; diff --git a/examples/raw_pointer.rs b/examples/raw_pointer.rs index d8c84917..bb3dccd5 100644 --- a/examples/raw_pointer.rs +++ b/examples/raw_pointer.rs @@ -19,6 +19,7 @@ fn main() { /* Then pass the raw pointers to some graphics API. */ + #[allow(clippy::float_cmp)] unsafe { assert_eq!(*v_pointer, 1.0); assert_eq!(*v_pointer.offset(1), 0.0); diff --git a/examples/screen_to_view_coords.rs b/examples/screen_to_view_coords.rs index b4d3d255..e16baa98 100644 --- a/examples/screen_to_view_coords.rs +++ b/examples/screen_to_view_coords.rs @@ -3,9 +3,10 @@ extern crate nalgebra as na; use na::{Perspective3, Point2, Point3, Unit}; +use std::f32::consts; fn main() { - let projection = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0); + let projection = Perspective3::new(800.0 / 600.0, consts::PI / 2.0, 1.0, 1000.0); let screen_point = Point2::new(10.0f32, 20.0); // Compute two points in clip-space. diff --git a/examples/transform_conversion.rs b/examples/transform_conversion.rs index 71660a07..f284e4b3 100644 --- a/examples/transform_conversion.rs +++ b/examples/transform_conversion.rs @@ -1,6 +1,7 @@ extern crate nalgebra as na; use na::{Isometry2, Similarity2, Vector2}; +use std::f32::consts; fn main() { // Isometry -> Similarity conversion always succeeds. @@ -8,8 +9,8 @@ fn main() { let _: Similarity2 = na::convert(iso); // Similarity -> Isometry conversion fails if the scaling factor is not 1.0. - let sim_without_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), 3.14, 1.0); - let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), 3.14, 2.0); + let sim_without_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 1.0); + let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 2.0); let iso_success: Option> = na::try_convert(sim_without_scaling); let iso_fail: Option> = na::try_convert(sim_with_scaling); diff --git a/examples/transform_matrix4.rs b/examples/transform_matrix4.rs index 74649d74..b7228e51 100644 --- a/examples/transform_matrix4.rs +++ b/examples/transform_matrix4.rs @@ -3,6 +3,7 @@ extern crate approx; extern crate nalgebra as na; use na::{Matrix4, Point3, Vector3}; +use std::f32::consts; fn main() { // Create a uniform scaling matrix with scaling factor 2. @@ -28,7 +29,7 @@ fn main() { ); // Create rotation. - let rot = Matrix4::from_scaled_axis(&Vector3::x() * 3.14); + let rot = Matrix4::from_scaled_axis(Vector3::x() * consts::PI); let rot_then_m = m * rot; // Right-multiplication is equivalent to prepending `rot` to `m`. let m_then_rot = rot * m; // Left-multiplication is equivalent to appending `rot` to `m`. diff --git a/examples/transformation_pointer.rs b/examples/transformation_pointer.rs index a39c5568..f2074906 100644 --- a/examples/transformation_pointer.rs +++ b/examples/transformation_pointer.rs @@ -12,6 +12,7 @@ fn main() { /* Then pass the raw pointer to some graphics API. */ + #[allow(clippy::float_cmp)] unsafe { assert_eq!(*iso_pointer, 1.0); assert_eq!(*iso_pointer.offset(5), 1.0); diff --git a/examples/unit_wrapper.rs b/examples/unit_wrapper.rs index 229fad1a..81339ddf 100644 --- a/examples/unit_wrapper.rs +++ b/examples/unit_wrapper.rs @@ -1,3 +1,4 @@ +#![allow(clippy::float_cmp)] extern crate nalgebra as na; use na::{Unit, Vector3}; diff --git a/src/base/edition.rs b/src/base/edition.rs index 9569294e..45ba1846 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -95,9 +95,7 @@ impl> Matrix { for (destination, source) in icols.enumerate() { // NOTE: this is basically a copy_frow but wrapping the values insnide of MaybeUninit. res.column_mut(destination) - .zip_apply(&self.column(*source), |out, e| { - *out = MaybeUninit::new(e.clone()) - }); + .zip_apply(&self.column(*source), |out, e| *out = MaybeUninit::new(e)); } // Safety: res is now fully initialized. @@ -1094,7 +1092,7 @@ unsafe fn compress_rows( if new_nrows == 0 || ncols == 0 { // The output matrix is empty, drop everything. - ptr::drop_in_place(data.as_mut()); + ptr::drop_in_place(data); return; } diff --git a/src/base/indexing.rs b/src/base/indexing.rs index 93f41ed3..de48a67c 100644 --- a/src/base/indexing.rs +++ b/src/base/indexing.rs @@ -1,4 +1,5 @@ //! Indexing +#![allow(clippy::reversed_empty_ranges)] use crate::base::storage::{RawStorage, RawStorageMut}; use crate::base::{ @@ -43,7 +44,7 @@ impl DimRange for usize { #[test] fn dimrange_usize() { - assert_eq!(DimRange::contained_by(&0, Const::<0>), false); + assert!(!DimRange::contained_by(&0, Const::<0>)); assert!(DimRange::contained_by(&0, Const::<1>)); } @@ -68,8 +69,8 @@ impl DimRange for ops::Range { #[test] fn dimrange_range_usize() { - assert_eq!(DimRange::contained_by(&(0..0), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(0..1), Const::<0>), false); + assert!(!DimRange::contained_by(&(0..0), Const::<0>)); + assert!(!DimRange::contained_by(&(0..1), Const::<0>)); assert!(DimRange::contained_by(&(0..1), Const::<1>)); assert!(DimRange::contained_by( &((usize::MAX - 1)..usize::MAX), @@ -110,8 +111,8 @@ impl DimRange for ops::RangeFrom { #[test] fn dimrange_rangefrom_usize() { - assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false); + assert!(!DimRange::contained_by(&(0..), Const::<0>)); + assert!(!DimRange::contained_by(&(0..), Const::<0>)); assert!(DimRange::contained_by(&(0..), Const::<1>)); assert!(DimRange::contained_by( &((usize::MAX - 1)..), @@ -204,16 +205,16 @@ impl DimRange for ops::RangeInclusive { #[test] fn dimrange_rangeinclusive_usize() { - assert_eq!(DimRange::contained_by(&(0..=0), Const::<0>), false); + assert!(!DimRange::contained_by(&(0..=0), Const::<0>)); assert!(DimRange::contained_by(&(0..=0), Const::<1>)); - assert_eq!( - DimRange::contained_by(&(usize::MAX..=usize::MAX), Dynamic::new(usize::MAX)), - false - ); - assert_eq!( - DimRange::contained_by(&((usize::MAX - 1)..=usize::MAX), Dynamic::new(usize::MAX)), - false - ); + assert!(!DimRange::contained_by( + &(usize::MAX..=usize::MAX), + Dynamic::new(usize::MAX) + )); + assert!(!DimRange::contained_by( + &((usize::MAX - 1)..=usize::MAX), + Dynamic::new(usize::MAX) + )); assert!(DimRange::contained_by( &((usize::MAX - 1)..=(usize::MAX - 1)), Dynamic::new(usize::MAX) @@ -255,7 +256,7 @@ impl DimRange for ops::RangeTo { #[test] fn dimrange_rangeto_usize() { assert!(DimRange::contained_by(&(..0), Const::<0>)); - assert_eq!(DimRange::contained_by(&(..1), Const::<0>), false); + assert!(!DimRange::contained_by(&(..1), Const::<0>)); assert!(DimRange::contained_by(&(..0), Const::<1>)); assert!(DimRange::contained_by( &(..(usize::MAX - 1)), @@ -292,13 +293,13 @@ impl DimRange for ops::RangeToInclusive { #[test] fn dimrange_rangetoinclusive_usize() { - assert_eq!(DimRange::contained_by(&(..=0), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(..=1), Const::<0>), false); + assert!(!DimRange::contained_by(&(..=0), Const::<0>)); + assert!(!DimRange::contained_by(&(..=1), Const::<0>)); assert!(DimRange::contained_by(&(..=0), Const::<1>)); - assert_eq!( - DimRange::contained_by(&(..=(usize::MAX)), Dynamic::new(usize::MAX)), - false - ); + assert!(!DimRange::contained_by( + &(..=(usize::MAX)), + Dynamic::new(usize::MAX) + )); assert!(DimRange::contained_by( &(..=(usize::MAX - 1)), Dynamic::new(usize::MAX) diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 4dccc439..bc4f1f27 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -1777,7 +1777,7 @@ where assert!(self.shape() == other.shape()); self.iter() .zip(other.iter()) - .all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps.clone())) + .all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps)) } } diff --git a/src/base/min_max.rs b/src/base/min_max.rs index 0876fe67..324da0a0 100644 --- a/src/base/min_max.rs +++ b/src/base/min_max.rs @@ -60,7 +60,7 @@ impl> Matrix { T: SimdPartialOrd + Zero, { self.fold_with( - |e| e.map(|e| e.clone()).unwrap_or_else(T::zero), + |e| e.cloned().unwrap_or_else(T::zero), |a, b| a.simd_max(b.clone()), ) } @@ -123,7 +123,7 @@ impl> Matrix { T: SimdPartialOrd + Zero, { self.fold_with( - |e| e.map(|e| e.clone()).unwrap_or_else(T::zero), + |e| e.cloned().unwrap_or_else(T::zero), |a, b| a.simd_min(b.clone()), ) } diff --git a/src/base/norm.rs b/src/base/norm.rs index 3968885b..11f5661f 100644 --- a/src/base/norm.rs +++ b/src/base/norm.rs @@ -434,12 +434,7 @@ impl> Matrix { { let n = self.norm(); let le = n.clone().simd_le(min_norm); - self.apply(|e| { - *e = e - .clone() - .simd_unscale(n.clone()) - .select(le.clone(), e.clone()) - }); + self.apply(|e| *e = e.clone().simd_unscale(n.clone()).select(le, e.clone())); SimdOption::new(n, le) } diff --git a/src/base/uninit.rs b/src/base/uninit.rs index 92d246df..ad2759eb 100644 --- a/src/base/uninit.rs +++ b/src/base/uninit.rs @@ -66,11 +66,11 @@ unsafe impl InitStatus for Uninit { #[inline(always)] unsafe fn assume_init_ref(t: &MaybeUninit) -> &T { - std::mem::transmute(t.as_ptr()) // TODO: use t.assume_init_ref() + &*t.as_ptr() // TODO: use t.assume_init_ref() } #[inline(always)] unsafe fn assume_init_mut(t: &mut MaybeUninit) -> &mut T { - std::mem::transmute(t.as_mut_ptr()) // TODO: use t.assume_init_mut() + &mut *t.as_mut_ptr() // TODO: use t.assume_init_mut() } } diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 11ff46d4..4050fbfb 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -353,7 +353,7 @@ impl> UlpsEq for DualQuaternion { fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { self.clone().to_vector().ulps_eq(&other.clone().to_vector(), epsilon.clone(), max_ulps.clone()) || // Account for the double-covering of S², i.e. q = -q. - self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone())) + self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps)) } } diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 731b46a1..d4008173 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -175,7 +175,7 @@ impl Orthographic3 { ); let half: T = crate::convert(0.5); - let width = zfar.clone() * (vfov.clone() * half.clone()).tan(); + let width = zfar.clone() * (vfov * half.clone()).tan(); let height = width.clone() / aspect; Self::new( diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 0c2c01c7..6d53863a 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -1039,9 +1039,9 @@ impl> UlpsEq for Quaternion { #[inline] fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { - self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps.clone()) || + self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps) || // Account for the double-covering of S², i.e. q = -q. - self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone())) + self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps)) } } @@ -1492,18 +1492,18 @@ where let wk = w.clone() * k.clone() * crate::convert(2.0f64); let wj = w.clone() * j.clone() * crate::convert(2.0f64); let ik = i.clone() * k.clone() * crate::convert(2.0f64); - let jk = j.clone() * k.clone() * crate::convert(2.0f64); - let wi = w.clone() * i.clone() * crate::convert(2.0f64); + let jk = j * k * crate::convert(2.0f64); + let wi = w * i * crate::convert(2.0f64); Rotation::from_matrix_unchecked(Matrix3::new( ww.clone() + ii.clone() - jj.clone() - kk.clone(), ij.clone() - wk.clone(), wj.clone() + ik.clone(), - wk.clone() + ij.clone(), + wk + ij, ww.clone() - ii.clone() + jj.clone() - kk.clone(), jk.clone() - wi.clone(), - ik.clone() - wj.clone(), - wi.clone() + jk.clone(), + ik - wj, + wi + jk, ww - ii - jj + kk, )) } diff --git a/src/linalg/determinant.rs b/src/linalg/determinant.rs index 7b5d6b2c..fe1ae82f 100644 --- a/src/linalg/determinant.rs +++ b/src/linalg/determinant.rs @@ -49,7 +49,7 @@ impl, S: Storage> SquareMatri let m33 = self.get_unchecked((2, 2)).clone(); let minor_m12_m23 = m22.clone() * m33.clone() - m32.clone() * m23.clone(); - let minor_m11_m23 = m21.clone() * m33.clone() - m31.clone() * m23.clone(); + let minor_m11_m23 = m21.clone() * m33 - m31.clone() * m23; let minor_m11_m22 = m21 * m32 - m31 * m22; m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22 diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index 835730da..074e801c 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -510,6 +510,7 @@ where #[cfg(test)] mod tests { #[test] + #[allow(clippy::float_cmp)] fn one_norm() { use crate::Matrix3; let m = Matrix3::new(-3.0, 5.0, 7.0, 2.0, 6.0, 4.0, 0.0, 2.0, 8.0); diff --git a/src/linalg/givens.rs b/src/linalg/givens.rs index c719deb6..30e2bed3 100644 --- a/src/linalg/givens.rs +++ b/src/linalg/givens.rs @@ -47,7 +47,7 @@ impl GivensRotation { if denom > eps { let norm = sign0.scale(denom.clone()); let c = mod0 / denom; - let s = s.clone() / norm.clone(); + let s = s / norm.clone(); Some((Self { c, s }, norm)) } else { None