From df218547d144f835f4a118abad99cd2e97ea9c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lauzier?= Date: Mon, 14 Jun 2021 19:49:37 -0400 Subject: [PATCH] Fix some clippy warnings and some typo --- CHANGELOG.md | 2 +- build.rs | 4 ++-- src/conv.rs | 2 +- src/macros.rs | 2 +- src/matrix.rs | 32 ++++++++++++++++---------------- src/point.rs | 6 +++--- src/quaternion_simd.rs | 2 +- src/rotation.rs | 4 ++-- src/structure.rs | 8 ++++---- src/transform.rs | 16 ++++++---------- src/vector.rs | 8 ++++---- src/vector_simd.rs | 6 +++--- tests/quaternion.rs | 4 ++-- tests/transform.rs | 2 +- 14 files changed, 47 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 899a0f7..f9dad94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,7 +51,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Add `Array::len` - Re-export `Bounded` and implement for vectors, points, and angles - Add vector subtraction to `EuclideanSpace` -- Add swizzle functions behinde that `"swizzle"` feature +- Add swizzle functions behind that `"swizzle"` feature - Add `Matrix4::look_at_dir` ### Changed diff --git a/build.rs b/build.rs index e2cb378..6cc198b 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,7 @@ use std::string::String; /// Generate the name of the swizzle function and what it returns. /// NOTE: This function assumes that variables are in ASCII format #[cfg(feature = "swizzle")] -fn gen_swizzle_nth<'a>(variables: &'a str, mut i: usize, upto: usize) -> Option<(String, String)> { +fn gen_swizzle_nth(variables: &str, mut i: usize, upto: usize) -> Option<(String, String)> { debug_assert!(i > 0); // zeroth permutation is empty let mut swizzle_impl = String::new(); let mut swizzle = String::new(); @@ -22,7 +22,7 @@ fn gen_swizzle_nth<'a>(variables: &'a str, mut i: usize, upto: usize) -> Option< let c = variables.as_bytes()[i % n - 1] as char; swizzle.push(c); swizzle_impl.push_str(&format!("self.{}, ", c)); - i = i / n; + i /= n; } Some((swizzle, swizzle_impl)) } diff --git a/src/conv.rs b/src/conv.rs index a6abd42..5e184f8 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -20,7 +20,7 @@ //! let uniforms = uniform! { //! point: Into::<[_; 2]>::into(point), //! matrix: Into::<[[_; 4]; 4]>::into(matrix), -//! // Yuck!! (ノಥ益ಥ)ノ ┻━┻ +//! // Yuck!! (ノಥ益ಥ)ノ ┻━┻) //! }; //! # } //! ` ` ` diff --git a/src/macros.rs b/src/macros.rs index f45d287..35f248a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -218,7 +218,7 @@ macro_rules! impl_tuple_conversions { impl<$S> From<$Tuple> for $ArrayN<$S> { #[inline] fn from(v: $Tuple) -> $ArrayN<$S> { - match v { ($($field),+,) => $ArrayN { $($field: $field),+ } } + match v { ($($field),+,) => $ArrayN { $($field),+ } } } } diff --git a/src/matrix.rs b/src/matrix.rs index e61eac3..7a591be 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -563,8 +563,8 @@ impl VectorSpace for Matrix4 { } impl Matrix for Matrix2 { - type Column = Vector2; type Row = Vector2; + type Column = Vector2; type Transpose = Matrix2; #[inline] @@ -661,8 +661,8 @@ impl SquareMatrix for Matrix2 { } impl Matrix for Matrix3 { - type Column = Vector3; type Row = Vector3; + type Column = Vector3; type Transpose = Matrix3; #[inline] @@ -776,8 +776,8 @@ impl SquareMatrix for Matrix3 { } impl Matrix for Matrix4 { - type Column = Vector4; type Row = Vector4; + type Column = Vector4; type Transpose = Matrix4; #[inline] @@ -1092,13 +1092,13 @@ impl Transform> for Matrix3 { Matrix3::from(Matrix2::look_at(dir, up)) } - fn look_at_lh(eye: Point2, center: Point2, up: Vector2) -> Matrix3 { - let dir = center - eye; + fn look_at_rh(eye: Point2, center: Point2, up: Vector2) -> Matrix3 { + let dir = eye - center; Matrix3::from(Matrix2::look_at(dir, up)) } - fn look_at_rh(eye: Point2, center: Point2, up: Vector2) -> Matrix3 { - let dir = eye - center; + fn look_at_lh(eye: Point2, center: Point2, up: Vector2) -> Matrix3 { + let dir = center - eye; Matrix3::from(Matrix2::look_at(dir, up)) } @@ -1125,16 +1125,16 @@ impl Transform> for Matrix3 { Matrix3::look_to_lh(dir, up) } - fn look_at_lh(eye: Point3, center: Point3, up: Vector3) -> Matrix3 { - let dir = center - eye; - Matrix3::look_to_lh(dir, up) - } - fn look_at_rh(eye: Point3, center: Point3, up: Vector3) -> Matrix3 { let dir = center - eye; Matrix3::look_to_rh(dir, up) } + fn look_at_lh(eye: Point3, center: Point3, up: Vector3) -> Matrix3 { + let dir = center - eye; + Matrix3::look_to_lh(dir, up) + } + fn transform_vector(&self, vec: Vector3) -> Vector3 { self * vec } @@ -1157,14 +1157,14 @@ impl Transform> for Matrix4 { Matrix4::look_at_rh(eye, center, up) } - fn look_at_lh(eye: Point3, center: Point3, up: Vector3) -> Matrix4 { - Matrix4::look_at_lh(eye, center, up) - } - fn look_at_rh(eye: Point3, center: Point3, up: Vector3) -> Matrix4 { Matrix4::look_at_rh(eye, center, up) } + fn look_at_lh(eye: Point3, center: Point3, up: Vector3) -> Matrix4 { + Matrix4::look_at_lh(eye, center, up) + } + fn transform_vector(&self, vec: Vector3) -> Vector3 { (self * vec.extend(S::zero())).truncate() } diff --git a/src/point.rs b/src/point.rs index 928f9b7..f8ffbc7 100644 --- a/src/point.rs +++ b/src/point.rs @@ -83,7 +83,7 @@ macro_rules! impl_point { /// Construct a new point, using the provided values. #[inline] pub const fn new($($field: S),+) -> $PointN { - $PointN { $($field: $field),+ } + $PointN { $($field),+ } } /// Perform the given operation on each field in the point, returning a new point @@ -405,7 +405,7 @@ mod tests { #[test] fn test_index_mut() { let mut p = POINT2; - *&mut p[0] = 0; + p[0] = 0; assert_eq!(p, [0, 2].into()); } @@ -518,7 +518,7 @@ mod tests { #[test] fn test_index_mut() { let mut p = POINT3; - *&mut p[1] = 0; + p[1] = 0; assert_eq!(p, [1, 0, 3].into()); } diff --git a/src/quaternion_simd.rs b/src/quaternion_simd.rs index 10821fa..0238fdc 100644 --- a/src/quaternion_simd.rs +++ b/src/quaternion_simd.rs @@ -26,7 +26,7 @@ impl From for Quaternion { #[inline] fn from(f: Simdf32x4) -> Self { unsafe { - let mut ret: Self = mem::uninitialized(); + let mut ret: Self = mem::MaybeUninit(); { let ret_mut: &mut [f32; 4] = ret.as_mut(); f.store(ret_mut.as_mut(), 0 as usize); diff --git a/src/rotation.rs b/src/rotation.rs index 1e801b6..ae5a7d5 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -149,7 +149,7 @@ pub trait Rotation3: /// let unit_y = rot.rotate_vector(unit_x); /// /// // Since sin(π/2) may not be exactly zero due to rounding errors, we can -/// // use approx's assert_ulps_eq!() feature to show that it is close enough. +/// // use approx assert_ulps_eq!() feature to show that it is close enough. /// // assert_ulps_eq!(&unit_y, &Vector2::unit_y()); // TODO: Figure out how to use this /// /// // This is exactly equivalent to using the raw matrix itself: @@ -319,7 +319,7 @@ impl Basis3 { #[inline] pub fn from_quaternion(quaternion: &Quaternion) -> Basis3 { Basis3 { - mat: quaternion.clone().into(), + mat: (*quaternion).into(), } } } diff --git a/src/structure.rs b/src/structure.rs index 9fe7928..9344814 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -580,10 +580,10 @@ where fn is_symmetric(&self) -> bool; } -/// Angles and their associated trigonometric functions. +/// Angles, and their associated trigonometric functions. /// /// Typed angles allow for the writing of self-documenting code that makes it -/// clear when semantic violations have occured - for example, adding degrees to +/// clear when semantic violations have occurred - for example, adding degrees to /// radians, or adding a number to an angle. /// pub trait Angle @@ -609,7 +609,7 @@ where { type Unitless: BaseFloat; - /// Return the angle, normalized to the range `[0, full_turn)`. + /// Return the angle, normalized to the range `[0, full_turn]`. #[inline] fn normalize(self) -> Self { let rem = self % Self::full_turn(); @@ -620,7 +620,7 @@ where } } - /// Return the angle, normalized to the range `[-turn_div_2, turn_div_2)`. + /// Return the angle, normalized to the range `[-turn_div_2, turn_div_2]`. #[inline] fn normalize_signed(self) -> Self { let rem = self.normalize(); diff --git a/src/transform.rs b/src/transform.rs index 72e08ed..63db8fe 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -123,8 +123,8 @@ where } #[inline] - fn look_at_lh(eye: P, center: P, up: P::Diff) -> Decomposed { - let rot = R::look_at(center - eye, up); + fn look_at_rh(eye: P, center: P, up: P::Diff) -> Decomposed { + let rot = R::look_at(eye - center, up); let disp = rot.rotate_vector(P::origin() - eye); Decomposed { scale: P::Scalar::one(), @@ -134,8 +134,8 @@ where } #[inline] - fn look_at_rh(eye: P, center: P, up: P::Diff) -> Decomposed { - let rot = R::look_at(eye - center, up); + fn look_at_lh(eye: P, center: P, up: P::Diff) -> Decomposed { + let rot = R::look_at(center - eye, up); let disp = rot.rotate_vector(P::origin() - eye); Decomposed { scale: P::Scalar::one(), @@ -366,7 +366,7 @@ mod serde_de { where D: serde::de::Deserializer<'a>, { - const FIELDS: &'static [&'static str] = &["scale", "rot", "disp"]; + const FIELDS: &[&str] = &["scale", "rot", "disp"]; deserializer.deserialize_struct("Decomposed", FIELDS, DecomposedVisitor(PhantomData)) } } @@ -422,11 +422,7 @@ mod serde_de { None => return Err(serde::de::Error::missing_field("disp")), }; - Ok(Decomposed { - scale: scale, - rot: rot, - disp: disp, - }) + Ok(Decomposed { scale, rot, disp }) } } } diff --git a/src/vector.rs b/src/vector.rs index 1f28848..231fc16 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -96,7 +96,7 @@ macro_rules! impl_vector { /// Construct a new vector, using the provided values. #[inline] pub const fn new($($field: S),+) -> $VectorN { - $VectorN { $($field: $field),+ } + $VectorN { $($field),+ } } /// Perform the given operation on each field in the vector, returning a new point @@ -620,7 +620,7 @@ mod tests { #[test] fn test_index_mut() { let mut v = VECTOR2; - *&mut v[0] = 0; + v[0] = 0; assert_eq!(v, [0, 2].into()); } @@ -741,7 +741,7 @@ mod tests { #[test] fn test_index_mut() { let mut v = VECTOR3; - *&mut v[1] = 0; + v[1] = 0; assert_eq!(v, [1, 0, 3].into()); } @@ -868,7 +868,7 @@ mod tests { #[test] fn test_index_mut() { let mut v = VECTOR4; - *&mut v[2] = 0; + v[2] = 0; assert_eq!(v, [1, 2, 0, 4].into()); } diff --git a/src/vector_simd.rs b/src/vector_simd.rs index 72b156e..328290d 100644 --- a/src/vector_simd.rs +++ b/src/vector_simd.rs @@ -28,7 +28,7 @@ impl From for Vector4 { #[inline] fn from(f: Simdf32x4) -> Self { unsafe { - let mut ret: Self = mem::uninitialized(); + let mut ret: Self = mem::MaybeUninit(); { let ret_mut: &mut [f32; 4] = ret.as_mut(); f.store(ret_mut.as_mut(), 0 as usize); @@ -244,7 +244,7 @@ impl From for Vector4 { #[inline] fn from(f: Simdi32x4) -> Self { unsafe { - let mut ret: Self = mem::uninitialized(); + let mut ret: Self = mem::MaybeUninit(); { let ret_mut: &mut [i32; 4] = ret.as_mut(); f.store(ret_mut.as_mut(), 0 as usize); @@ -324,7 +324,7 @@ impl From for Vector4 { #[inline] fn from(f: Simdu32x4) -> Self { unsafe { - let mut ret: Self = mem::uninitialized(); + let mut ret: Self = mem::MaybeUninit(); { let ret_mut: &mut [u32; 4] = ret.as_mut(); f.store(ret_mut.as_mut(), 0 as usize); diff --git a/tests/quaternion.rs b/tests/quaternion.rs index daddb91..8bd43d8 100644 --- a/tests/quaternion.rs +++ b/tests/quaternion.rs @@ -220,7 +220,7 @@ mod from { use cgmath::*; fn check_with_euler(x: Rad, y: Rad, z: Rad) { - let matrix3 = Matrix3::from(Euler { x: x, y: y, z: z }); + let matrix3 = Matrix3::from(Euler { x, y, z }); let quaternion = Quaternion::from(matrix3); let quaternion_matrix3 = Matrix3::from(quaternion); assert_ulps_eq!(matrix3, quaternion_matrix3); @@ -265,7 +265,7 @@ mod arc { #[test] fn test_same() { let v = Vector3::unit_x(); - let q = Quaternion::from_arc(v, v, None); + let q = Quaternion::from_arc(v.clone(), v, None); assert_eq!(q, Quaternion::new(1.0, 0.0, 0.0, 0.0)); } diff --git a/tests/transform.rs b/tests/transform.rs index ee22977..ed49a77 100644 --- a/tests/transform.rs +++ b/tests/transform.rs @@ -122,7 +122,7 @@ fn test_look_at_lh() { assert_ulps_eq!(t, Matrix4::::look_at_lh(eye, center, up)); assert_ulps_eq!(&t.transform_point(point), &view_point); - // Decomposed::look_at is inconsistent and deprecated, but verify that the behvaior + // Decomposed::look_at is inconsistent and deprecated, but verify that the behavior // remains the same until removed. #[allow(deprecated)] let t: Decomposed, Quaternion> = Transform::look_at(eye, center, up);