From bbd60fbc8c0d4cc02dd8495e7968cfa6995dab27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lauzier?= Date: Mon, 5 Jul 2021 17:51:27 -0400 Subject: [PATCH] Fix some clippy warnings and typo --- CHANGELOG.md | 38 +++++----- src/base/indexing.rs | 95 ++++++++++++------------- src/base/storage.rs | 2 + src/geometry/dual_quaternion.rs | 6 +- src/geometry/orthographic.rs | 4 +- src/geometry/perspective.rs | 4 +- src/geometry/quaternion.rs | 6 +- src/geometry/rotation_specialization.rs | 2 +- src/geometry/unit_complex.rs | 4 +- src/sparse/cs_matrix.rs | 8 +-- 10 files changed, 82 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d5c374..956ba534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ conversions targeting the versions 0.13, 0.14, and 0.15 of `glam`. Fix a regression introduced in 0.26.0 preventing `DVector` from being serialized with `serde`. ## [0.26.0] -This releases integrates `min-const-generics` to nalgebra. See +This release integrates `min-const-generics` to nalgebra. See [our blog post](https://www.dimforge.com/blog/2021/04/12/integrating-const-generics-to-nalgebra) for details about this release. @@ -78,7 +78,7 @@ for details about this release. ## [0.25.3] ### Added -- The `Vector::simd_cap_magnitude` method to cap the magnitude of the a vector with +- The `Vector::simd_cap_magnitude` method to cap the magnitude of the vector with SIMD components. ## [0.25.2] @@ -109,7 +109,7 @@ This updates all the dependencies of nalgebra to their latest version, including ### New crate: nalgebra-sparse Alongside this release of `nalgebra`, we are releasing `nalgebra-sparse`: a crate dedicated to sparse matrix -computation with `nalgebra`. The `sparse` module of `nalgebra`itself still exists for backward compatibility +computation with `nalgebra`. The `sparse` module of `nalgebra`itself still exists for backward compatibility, but it will be deprecated soon in favor of the `nalgebra-sparse` crate. ### Added @@ -125,12 +125,12 @@ but it will be deprecated soon in favor of the `nalgebra-sparse` crate. ## [0.24.0] ### Added -* The `DualQuaternion` type. It is still work-in-progress but the basics are here: +* The `DualQuaternion` type. It is still work-in-progress, but the basics are here: creation from its real and dual part, multiplication of two dual quaternions, and normalization. ### Removed -* There is no blanket `impl PartialEq for Unit` any more. Instead, it is +* There is no blanket `impl PartialEq for Unit` anymore. Instead, it is implemented specifically for `UnitComplex`, `UnitQuaternion` and `Unit`. ## [0.23.2] @@ -157,7 +157,7 @@ In this release we improved the documentation of the matrix and vector types by: and `Vector.apply(f)`. * The `Quaternion::from([N; 4])` conversion to build a quaternion from an array of four elements. * The `Isometry::from(Translation)` conversion to build an isometry from a translation. - * The `Vector::ith_axis(i)` which build a unit vector, e.g., `Unit>` with its i-th component set to 1.0 and the + * The `Vector::ith_axis(i)` which build a unit vector, e.g., `Unit>` with its i-th component set to 1.0, and the others set to zero. * The `Isometry.lerp_slerp` and `Isometry.try_lerp_slerp` methods to interpolate between two isometries using linear interpolation for the translational part, and spherical interpolation for the rotational part. @@ -166,7 +166,7 @@ In this release we improved the documentation of the matrix and vector types by: ## [0.22.0] In this release, we are using the new version 0.2 of simba. One major change of that version is that the -use of `libm` is now opt-in when building targetting `no-std` environment. If you are using floating-point +use of `libm` is now opt-in when building targeting `no-std` environment. If you are using floating-point operations with nalgebra in a `no-std` environment, you will need to enable the new `libm` feature of nalgebra for your code to compile again. @@ -174,7 +174,7 @@ of nalgebra for your code to compile again. * The `libm` feature that enables `libm` when building for `no-std` environment. * The `libm-force` feature that enables `libm` even when building for a not `no-std` environment. * `Cholesky::new_unchecked` which build a Cholesky decomposition without checking that its input is - positive-definite. It can be use with SIMD types. + positive-definite. It can be used with SIMD types. * The `Default` trait is now implemented for matrices, and quaternions. They are all filled with zeros, except for `UnitQuaternion` which is initialized with the identity. * Matrix exponential `matrix.exp()`. @@ -345,7 +345,7 @@ library (i.e. it supports `#![no_std]`). See the corresponding [documentation](h * Add methods `.rotation_between_axis(...)` and `.scaled_rotation_between_axis(...)` to `UnitComplex` to compute the rotation matrix between two 2D **unit** vectors. * Add methods `.axis_angle()` to `UnitComplex` and `UnitQuaternion` in order to retrieve both the - unit rotation axis and the rotation angle simultaneously. + unit rotation axis, and the rotation angle simultaneously. * Add functions to construct a random matrix with a user-defined distribution: `::from_distribution(...)`. ## [0.14.0] @@ -366,7 +366,7 @@ library (i.e. it supports `#![no_std]`). See the corresponding [documentation](h the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`. * `.iamin()` that returns the index of the vector entry with - smallest absolute value. + the smallest absolute value. * The `mint` feature that can be enabled in order to allow conversions from and to types of the [mint](https://crates.io/crates/mint) crate. * Aliases for matrix and vector slices. Their are named by adding `Slice` @@ -404,7 +404,7 @@ This adds support for serialization using the * The alias `MatrixNM` is now deprecated. Use `MatrixMN` instead (we reordered M and N to be in alphabetical order). * In-place componentwise multiplication and division - `.component_mul_mut(...)` and `.component_div_mut(...)` have bee deprecated + `.component_mul_mut(...)` and `.component_div_mut(...)` have been deprecated for a future renaming. Use `.component_mul_assign(...)` and `.component_div_assign(...)` instead. @@ -506,7 +506,7 @@ This version is a major rewrite of the library. Major changes are: All other mathematical traits, except `Axpy` have been removed from **nalgebra**. * Methods are now preferred to free functions because they do not require any - trait to be used any more. + trait to be used anymore. * Most algebraic entities can be parametrized by type-level integers to specify their dimensions. Using `Dynamic` instead of a type-level integer indicates that the dimension known at run-time only. @@ -582,7 +582,7 @@ only: * The free functions `::prepend_rotation`, `::append_rotation`, `::append_rotation_wrt_center`, `::append_rotation_wrt_point`, `::append_transformation`, and `::append_translation ` have been removed. - Instead create the rotation or translation object explicitly and use + Instead, create the rotation or translation object explicitly and use multiplication to compose it with anything else. * The free function `::outer` has been removed. Use column-vector × @@ -608,7 +608,7 @@ Binary operations are now allowed between references as well. For example ### Modified Removed unused parameters to methods from the `ApproxEq` trait. Those were -required before rust 1.0 to help type inference. The are not needed any more +required before rust 1.0 to help type inference. They are not needed any more since it now allowed to write for a type `T` that implements `ApproxEq`: `::approx_epsilon()`. This replaces the old form: `ApproxEq::approx_epsilon(None::)`. @@ -627,7 +627,7 @@ since it now allowed to write for a type `T` that implements `ApproxEq`: `UnitQuaternion::from_axisangle`. The new `::new` method now requires a not-normalized quaternion. -Methods names starting with `new_with_` now start with `from_`. This is more +Method names starting with `new_with_` now start with `from_`. This is more idiomatic in Rust. The `Norm` trait now uses an associated type instead of a type parameter. @@ -658,8 +658,8 @@ crate for vectors, rotations and points. To enable them, activate the ## [0.8.0] ### Modified - * Almost everything (types, methods, and traits) now use full names instead - of abbreviations (e.g. `Vec3` becomes `Vector3`). Most changes are abvious. + * Almost everything (types, methods, and traits) now use fulls names instead + of abbreviations (e.g. `Vec3` becomes `Vector3`). Most changes are obvious. Note however that: - `::sqnorm` becomes `::norm_squared`. - `::sqdist` becomes `::distance_squared`. @@ -693,11 +693,11 @@ you [there](https://users.nphysics.org)! ### Removed * Removed zero-sized elements `Vector0`, `Point0`. - * Removed 4-dimensional transformations `Rotation4` and `Isometry4` (which had an implementation to incomplete to be useful). + * Removed 4-dimensional transformations `Rotation4` and `Isometry4` (which had an implementation too incomplete to be useful). ### Modified * Vectors are now multipliable with isometries. This will result into a pure rotation (this is how - vectors differ from point semantically: they design directions so they are not translatable). + vectors differ from point semantically: they design directions, so they are not translatable). * `{Isometry3, Rotation3}::look_at` reimplemented and renamed to `::look_at_rh` and `::look_at_lh` to agree with the computer graphics community (in particular, the GLM library). Use the `::look_at_rh` variant to build a view matrix that diff --git a/src/base/indexing.rs b/src/base/indexing.rs index 5bc06020..5107035c 100644 --- a/src/base/indexing.rs +++ b/src/base/indexing.rs @@ -44,7 +44,7 @@ impl DimRange for usize { #[test] fn dimrange_usize() { assert_eq!(DimRange::contained_by(&0, Const::<0>), false); - assert_eq!(DimRange::contained_by(&0, Const::<1>), true); + assert!(DimRange::contained_by(&0, Const::<1>)); } impl DimRange for ops::Range { @@ -68,24 +68,23 @@ impl DimRange for ops::Range { #[test] fn dimrange_range_usize() { - use std::usize::MAX; assert_eq!(DimRange::contained_by(&(0..0), Const::<0>), false); assert_eq!(DimRange::contained_by(&(0..1), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(0..1), Const::<1>), true); + assert!(DimRange::contained_by(&(0..1), Const::<1>)); + assert!(DimRange::contained_by( + &((usize::MAX - 1)..usize::MAX), + Dynamic::new(usize::MAX) + )); assert_eq!( - DimRange::contained_by(&((MAX - 1)..MAX), Dynamic::new(MAX)), - true - ); - assert_eq!( - DimRange::length(&((MAX - 1)..MAX), Dynamic::new(MAX)), + DimRange::length(&((usize::MAX - 1)..usize::MAX), Dynamic::new(usize::MAX)), Dynamic::new(1) ); assert_eq!( - DimRange::length(&(MAX..(MAX - 1)), Dynamic::new(MAX)), + DimRange::length(&(usize::MAX..(usize::MAX - 1)), Dynamic::new(usize::MAX)), Dynamic::new(0) ); assert_eq!( - DimRange::length(&(MAX..MAX), Dynamic::new(MAX)), + DimRange::length(&(usize::MAX..usize::MAX), Dynamic::new(usize::MAX)), Dynamic::new(0) ); } @@ -111,20 +110,19 @@ impl DimRange for ops::RangeFrom { #[test] fn dimrange_rangefrom_usize() { - use std::usize::MAX; assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false); assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(0..), Const::<1>), true); + assert!(DimRange::contained_by(&(0..), Const::<1>)); + assert!(DimRange::contained_by( + &((usize::MAX - 1)..), + Dynamic::new(usize::MAX) + )); assert_eq!( - DimRange::contained_by(&((MAX - 1)..), Dynamic::new(MAX)), - true - ); - assert_eq!( - DimRange::length(&((MAX - 1)..), Dynamic::new(MAX)), + DimRange::length(&((usize::MAX - 1)..), Dynamic::new(usize::MAX)), Dynamic::new(1) ); assert_eq!( - DimRange::length(&(MAX..), Dynamic::new(MAX)), + DimRange::length(&(usize::MAX..), Dynamic::new(usize::MAX)), Dynamic::new(0) ); } @@ -177,7 +175,7 @@ impl DimRange for ops::RangeFull { #[test] fn dimrange_rangefull() { - assert_eq!(DimRange::contained_by(&(..), Const::<0>), true); + assert!(DimRange::contained_by(&(..), Const::<0>)); assert_eq!(DimRange::length(&(..), Const::<1>), Const::<1>); } @@ -206,32 +204,31 @@ impl DimRange for ops::RangeInclusive { #[test] fn dimrange_rangeinclusive_usize() { - use std::usize::MAX; assert_eq!(DimRange::contained_by(&(0..=0), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(0..=0), Const::<1>), true); + assert!(DimRange::contained_by(&(0..=0), Const::<1>)); assert_eq!( - DimRange::contained_by(&(MAX..=MAX), Dynamic::new(MAX)), + DimRange::contained_by(&(usize::MAX..=usize::MAX), Dynamic::new(usize::MAX)), false ); assert_eq!( - DimRange::contained_by(&((MAX - 1)..=MAX), Dynamic::new(MAX)), + DimRange::contained_by(&((usize::MAX - 1)..=usize::MAX), Dynamic::new(usize::MAX)), false ); - assert_eq!( - DimRange::contained_by(&((MAX - 1)..=(MAX - 1)), Dynamic::new(MAX)), - true - ); + assert!(DimRange::contained_by( + &((usize::MAX - 1)..=(usize::MAX - 1)), + Dynamic::new(usize::MAX) + )); assert_eq!(DimRange::length(&(0..=0), Const::<1>), Dynamic::new(1)); assert_eq!( - DimRange::length(&((MAX - 1)..=MAX), Dynamic::new(MAX)), + DimRange::length(&((usize::MAX - 1)..=usize::MAX), Dynamic::new(usize::MAX)), Dynamic::new(2) ); assert_eq!( - DimRange::length(&(MAX..=(MAX - 1)), Dynamic::new(MAX)), + DimRange::length(&(usize::MAX..=(usize::MAX - 1)), Dynamic::new(usize::MAX)), Dynamic::new(0) ); assert_eq!( - DimRange::length(&(MAX..=MAX), Dynamic::new(MAX)), + DimRange::length(&(usize::MAX..=usize::MAX), Dynamic::new(usize::MAX)), Dynamic::new(1) ); } @@ -257,21 +254,20 @@ impl DimRange for ops::RangeTo { #[test] fn dimrange_rangeto_usize() { - use std::usize::MAX; - assert_eq!(DimRange::contained_by(&(..0), Const::<0>), true); + assert!(DimRange::contained_by(&(..0), Const::<0>)); assert_eq!(DimRange::contained_by(&(..1), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(..0), Const::<1>), true); + assert!(DimRange::contained_by(&(..0), Const::<1>)); + assert!(DimRange::contained_by( + &(..(usize::MAX - 1)), + Dynamic::new(usize::MAX) + )); assert_eq!( - DimRange::contained_by(&(..(MAX - 1)), Dynamic::new(MAX)), - true + DimRange::length(&(..(usize::MAX - 1)), Dynamic::new(usize::MAX)), + Dynamic::new(usize::MAX - 1) ); assert_eq!( - DimRange::length(&(..(MAX - 1)), Dynamic::new(MAX)), - Dynamic::new(MAX - 1) - ); - assert_eq!( - DimRange::length(&(..MAX), Dynamic::new(MAX)), - Dynamic::new(MAX) + DimRange::length(&(..usize::MAX), Dynamic::new(usize::MAX)), + Dynamic::new(usize::MAX) ); } @@ -296,21 +292,20 @@ impl DimRange for ops::RangeToInclusive { #[test] fn dimrange_rangetoinclusive_usize() { - use std::usize::MAX; assert_eq!(DimRange::contained_by(&(..=0), Const::<0>), false); assert_eq!(DimRange::contained_by(&(..=1), Const::<0>), false); - assert_eq!(DimRange::contained_by(&(..=0), Const::<1>), true); + assert!(DimRange::contained_by(&(..=0), Const::<1>)); assert_eq!( - DimRange::contained_by(&(..=(MAX)), Dynamic::new(MAX)), + DimRange::contained_by(&(..=(usize::MAX)), Dynamic::new(usize::MAX)), false ); + assert!(DimRange::contained_by( + &(..=(usize::MAX - 1)), + Dynamic::new(usize::MAX) + )); assert_eq!( - DimRange::contained_by(&(..=(MAX - 1)), Dynamic::new(MAX)), - true - ); - assert_eq!( - DimRange::length(&(..=(MAX - 1)), Dynamic::new(MAX)), - Dynamic::new(MAX) + DimRange::length(&(..=(usize::MAX - 1)), Dynamic::new(usize::MAX)), + Dynamic::new(usize::MAX) ); } diff --git a/src/base/storage.rs b/src/base/storage.rs index 6aa6a7c8..c5afbad7 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -102,6 +102,7 @@ pub unsafe trait Storage: Debug + Sized { /// Retrieves the data buffer as a contiguous slice. /// + /// # Safety /// The matrix components may not be stored in a contiguous way, depending on the strides. /// This method is unsafe because this can yield to invalid aliasing when called on some pairs /// of matrix slices originating from the same matrix with strides. @@ -175,6 +176,7 @@ pub unsafe trait StorageMut: Storage { /// /// Matrix components may not be contiguous, depending on its strides. /// + /// # Safety /// The matrix components may not be stored in a contiguous way, depending on the strides. /// This method is unsafe because this can yield to invalid aliasing when called on some pairs /// of matrix slices originating from the same matrix with strides. diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 63148836..6e1e6cb9 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -275,7 +275,7 @@ where } impl DualQuaternion { - fn to_vector(&self) -> OVector { + fn to_vector(self) -> OVector { (*self.as_ref()).into() } } @@ -724,7 +724,7 @@ where /// ``` #[inline] #[must_use] - pub fn to_isometry(&self) -> Isometry3 { + pub fn to_isometry(self) -> Isometry3 { Isometry3::from_parts(self.translation(), self.rotation()) } @@ -875,7 +875,7 @@ where /// ``` #[inline] #[must_use] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(self) -> Matrix4 { self.to_isometry().to_homogeneous() } } diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 17a5b969..7a151f8c 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -222,7 +222,7 @@ impl Orthographic3 { /// ``` #[inline] #[must_use] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(self) -> Matrix4 { self.matrix } @@ -270,7 +270,7 @@ impl Orthographic3 { /// ``` #[inline] #[must_use] - pub fn to_projective(&self) -> Projective3 { + pub fn to_projective(self) -> Projective3 { Projective3::from_matrix_unchecked(self.matrix) } diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 359976fe..d2c107c0 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -124,7 +124,7 @@ impl Perspective3 { /// Computes the corresponding homogeneous matrix. #[inline] #[must_use] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(self) -> Matrix4 { self.matrix.clone_owned() } @@ -145,7 +145,7 @@ impl Perspective3 { /// This transformation seen as a `Projective3`. #[inline] #[must_use] - pub fn to_projective(&self) -> Projective3 { + pub fn to_projective(self) -> Projective3 { Projective3::from_matrix_unchecked(self.matrix) } diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 927a3849..3449f1ae 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -1478,7 +1478,7 @@ where /// ``` #[inline] #[must_use] - pub fn to_rotation_matrix(&self) -> Rotation { + pub fn to_rotation_matrix(self) -> Rotation { let i = self.as_ref()[0]; let j = self.as_ref()[1]; let k = self.as_ref()[2]; @@ -1513,7 +1513,7 @@ where /// The angles are produced in the form (roll, pitch, yaw). #[inline] #[deprecated(note = "This is renamed to use `.euler_angles()`.")] - pub fn to_euler_angles(&self) -> (T, T, T) + pub fn to_euler_angles(self) -> (T, T, T) where T: RealField, { @@ -1561,7 +1561,7 @@ where /// ``` #[inline] #[must_use] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(self) -> Matrix4 { self.to_rotation_matrix().to_homogeneous() } diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index e7f79888..2ad73c69 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -883,7 +883,7 @@ impl Rotation3 { /// /// The angles are produced in the form (roll, pitch, yaw). #[deprecated(note = "This is renamed to use `.euler_angles()`.")] - pub fn to_euler_angles(&self) -> (T, T, T) + pub fn to_euler_angles(self) -> (T, T, T) where T: RealField, { diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index be0c8980..d6a7316c 100755 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -261,7 +261,7 @@ where /// ``` #[inline] #[must_use] - pub fn to_rotation_matrix(&self) -> Rotation2 { + pub fn to_rotation_matrix(self) -> Rotation2 { let r = self.re; let i = self.im; @@ -282,7 +282,7 @@ where /// ``` #[inline] #[must_use] - pub fn to_homogeneous(&self) -> Matrix3 { + pub fn to_homogeneous(self) -> Matrix3 { self.to_rotation_matrix().to_homogeneous() } } diff --git a/src/sparse/cs_matrix.rs b/src/sparse/cs_matrix.rs index 3a60fb5b..cdacd044 100644 --- a/src/sparse/cs_matrix.rs +++ b/src/sparse/cs_matrix.rs @@ -31,11 +31,9 @@ impl<'a, T: Clone> Iterator for ColumnEntries<'a, T> { if self.curr >= self.i.len() { None } else { - let res = Some( - (unsafe { self.i.get_unchecked(self.curr).clone() }, unsafe { - self.v.get_unchecked(self.curr).clone() - }), - ); + let res = Some((unsafe { *self.i.get_unchecked(self.curr) }, unsafe { + self.v.get_unchecked(self.curr).clone() + })); self.curr += 1; res }