Fix some clippy warnings and some typo

This commit is contained in:
Rémi Lauzier 2021-06-14 19:49:37 -04:00 committed by Dzmitry Malyshau
parent 575c458705
commit df218547d1
14 changed files with 47 additions and 51 deletions

View file

@ -51,7 +51,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Add `Array::len` - Add `Array::len`
- Re-export `Bounded` and implement for vectors, points, and angles - Re-export `Bounded` and implement for vectors, points, and angles
- Add vector subtraction to `EuclideanSpace` - Add vector subtraction to `EuclideanSpace`
- Add swizzle functions behinde that `"swizzle"` feature - Add swizzle functions behind that `"swizzle"` feature
- Add `Matrix4::look_at_dir` - Add `Matrix4::look_at_dir`
### Changed ### Changed

View file

@ -7,7 +7,7 @@ use std::string::String;
/// Generate the name of the swizzle function and what it returns. /// Generate the name of the swizzle function and what it returns.
/// NOTE: This function assumes that variables are in ASCII format /// NOTE: This function assumes that variables are in ASCII format
#[cfg(feature = "swizzle")] #[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 debug_assert!(i > 0); // zeroth permutation is empty
let mut swizzle_impl = String::new(); let mut swizzle_impl = String::new();
let mut swizzle = 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; let c = variables.as_bytes()[i % n - 1] as char;
swizzle.push(c); swizzle.push(c);
swizzle_impl.push_str(&format!("self.{}, ", c)); swizzle_impl.push_str(&format!("self.{}, ", c));
i = i / n; i /= n;
} }
Some((swizzle, swizzle_impl)) Some((swizzle, swizzle_impl))
} }

View file

@ -20,7 +20,7 @@
//! let uniforms = uniform! { //! let uniforms = uniform! {
//! point: Into::<[_; 2]>::into(point), //! point: Into::<[_; 2]>::into(point),
//! matrix: Into::<[[_; 4]; 4]>::into(matrix), //! matrix: Into::<[[_; 4]; 4]>::into(matrix),
//! // Yuck!! (ノಥ益ಥ)ノ ┻━┻ //! // Yuck!! (ノಥ益ಥ)ノ ┻━┻)
//! }; //! };
//! # } //! # }
//! ` ` ` //! ` ` `

View file

@ -218,7 +218,7 @@ macro_rules! impl_tuple_conversions {
impl<$S> From<$Tuple> for $ArrayN<$S> { impl<$S> From<$Tuple> for $ArrayN<$S> {
#[inline] #[inline]
fn from(v: $Tuple) -> $ArrayN<$S> { fn from(v: $Tuple) -> $ArrayN<$S> {
match v { ($($field),+,) => $ArrayN { $($field: $field),+ } } match v { ($($field),+,) => $ArrayN { $($field),+ } }
} }
} }

View file

@ -563,8 +563,8 @@ impl<S: BaseFloat> VectorSpace for Matrix4<S> {
} }
impl<S: BaseFloat> Matrix for Matrix2<S> { impl<S: BaseFloat> Matrix for Matrix2<S> {
type Column = Vector2<S>;
type Row = Vector2<S>; type Row = Vector2<S>;
type Column = Vector2<S>;
type Transpose = Matrix2<S>; type Transpose = Matrix2<S>;
#[inline] #[inline]
@ -661,8 +661,8 @@ impl<S: BaseFloat> SquareMatrix for Matrix2<S> {
} }
impl<S: BaseFloat> Matrix for Matrix3<S> { impl<S: BaseFloat> Matrix for Matrix3<S> {
type Column = Vector3<S>;
type Row = Vector3<S>; type Row = Vector3<S>;
type Column = Vector3<S>;
type Transpose = Matrix3<S>; type Transpose = Matrix3<S>;
#[inline] #[inline]
@ -776,8 +776,8 @@ impl<S: BaseFloat> SquareMatrix for Matrix3<S> {
} }
impl<S: BaseFloat> Matrix for Matrix4<S> { impl<S: BaseFloat> Matrix for Matrix4<S> {
type Column = Vector4<S>;
type Row = Vector4<S>; type Row = Vector4<S>;
type Column = Vector4<S>;
type Transpose = Matrix4<S>; type Transpose = Matrix4<S>;
#[inline] #[inline]
@ -1092,13 +1092,13 @@ impl<S: BaseFloat> Transform<Point2<S>> for Matrix3<S> {
Matrix3::from(Matrix2::look_at(dir, up)) Matrix3::from(Matrix2::look_at(dir, up))
} }
fn look_at_lh(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> { fn look_at_rh(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> {
let dir = center - eye; let dir = eye - center;
Matrix3::from(Matrix2::look_at(dir, up)) Matrix3::from(Matrix2::look_at(dir, up))
} }
fn look_at_rh(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> { fn look_at_lh(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> {
let dir = eye - center; let dir = center - eye;
Matrix3::from(Matrix2::look_at(dir, up)) Matrix3::from(Matrix2::look_at(dir, up))
} }
@ -1125,16 +1125,16 @@ impl<S: BaseFloat> Transform<Point3<S>> for Matrix3<S> {
Matrix3::look_to_lh(dir, up) Matrix3::look_to_lh(dir, up)
} }
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = center - eye;
Matrix3::look_to_lh(dir, up)
}
fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> { fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = center - eye; let dir = center - eye;
Matrix3::look_to_rh(dir, up) Matrix3::look_to_rh(dir, up)
} }
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = center - eye;
Matrix3::look_to_lh(dir, up)
}
fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> { fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> {
self * vec self * vec
} }
@ -1157,14 +1157,14 @@ impl<S: BaseFloat> Transform<Point3<S>> for Matrix4<S> {
Matrix4::look_at_rh(eye, center, up) Matrix4::look_at_rh(eye, center, up)
} }
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at_lh(eye, center, up)
}
fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> { fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at_rh(eye, center, up) Matrix4::look_at_rh(eye, center, up)
} }
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at_lh(eye, center, up)
}
fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> { fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> {
(self * vec.extend(S::zero())).truncate() (self * vec.extend(S::zero())).truncate()
} }

View file

@ -83,7 +83,7 @@ macro_rules! impl_point {
/// Construct a new point, using the provided values. /// Construct a new point, using the provided values.
#[inline] #[inline]
pub const fn new($($field: S),+) -> $PointN<S> { pub const fn new($($field: S),+) -> $PointN<S> {
$PointN { $($field: $field),+ } $PointN { $($field),+ }
} }
/// Perform the given operation on each field in the point, returning a new point /// Perform the given operation on each field in the point, returning a new point
@ -405,7 +405,7 @@ mod tests {
#[test] #[test]
fn test_index_mut() { fn test_index_mut() {
let mut p = POINT2; let mut p = POINT2;
*&mut p[0] = 0; p[0] = 0;
assert_eq!(p, [0, 2].into()); assert_eq!(p, [0, 2].into());
} }
@ -518,7 +518,7 @@ mod tests {
#[test] #[test]
fn test_index_mut() { fn test_index_mut() {
let mut p = POINT3; let mut p = POINT3;
*&mut p[1] = 0; p[1] = 0;
assert_eq!(p, [1, 0, 3].into()); assert_eq!(p, [1, 0, 3].into());
} }

View file

@ -26,7 +26,7 @@ impl From<Simdf32x4> for Quaternion<f32> {
#[inline] #[inline]
fn from(f: Simdf32x4) -> Self { fn from(f: Simdf32x4) -> Self {
unsafe { unsafe {
let mut ret: Self = mem::uninitialized(); let mut ret: Self = mem::MaybeUninit();
{ {
let ret_mut: &mut [f32; 4] = ret.as_mut(); let ret_mut: &mut [f32; 4] = ret.as_mut();
f.store(ret_mut.as_mut(), 0 as usize); f.store(ret_mut.as_mut(), 0 as usize);

View file

@ -149,7 +149,7 @@ pub trait Rotation3:
/// let unit_y = rot.rotate_vector(unit_x); /// let unit_y = rot.rotate_vector(unit_x);
/// ///
/// // Since sin(π/2) may not be exactly zero due to rounding errors, we can /// // 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 /// // 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: /// // This is exactly equivalent to using the raw matrix itself:
@ -319,7 +319,7 @@ impl<S: BaseFloat> Basis3<S> {
#[inline] #[inline]
pub fn from_quaternion(quaternion: &Quaternion<S>) -> Basis3<S> { pub fn from_quaternion(quaternion: &Quaternion<S>) -> Basis3<S> {
Basis3 { Basis3 {
mat: quaternion.clone().into(), mat: (*quaternion).into(),
} }
} }
} }

View file

@ -580,10 +580,10 @@ where
fn is_symmetric(&self) -> bool; 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 /// 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. /// radians, or adding a number to an angle.
/// ///
pub trait Angle pub trait Angle
@ -609,7 +609,7 @@ where
{ {
type Unitless: BaseFloat; type Unitless: BaseFloat;
/// Return the angle, normalized to the range `[0, full_turn)`. /// Return the angle, normalized to the range `[0, full_turn]`.
#[inline] #[inline]
fn normalize(self) -> Self { fn normalize(self) -> Self {
let rem = self % Self::full_turn(); 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] #[inline]
fn normalize_signed(self) -> Self { fn normalize_signed(self) -> Self {
let rem = self.normalize(); let rem = self.normalize();

View file

@ -123,8 +123,8 @@ where
} }
#[inline] #[inline]
fn look_at_lh(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> { fn look_at_rh(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
let rot = R::look_at(center - eye, up); let rot = R::look_at(eye - center, up);
let disp = rot.rotate_vector(P::origin() - eye); let disp = rot.rotate_vector(P::origin() - eye);
Decomposed { Decomposed {
scale: P::Scalar::one(), scale: P::Scalar::one(),
@ -134,8 +134,8 @@ where
} }
#[inline] #[inline]
fn look_at_rh(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> { fn look_at_lh(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
let rot = R::look_at(eye - center, up); let rot = R::look_at(center - eye, up);
let disp = rot.rotate_vector(P::origin() - eye); let disp = rot.rotate_vector(P::origin() - eye);
Decomposed { Decomposed {
scale: P::Scalar::one(), scale: P::Scalar::one(),
@ -366,7 +366,7 @@ mod serde_de {
where where
D: serde::de::Deserializer<'a>, 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)) deserializer.deserialize_struct("Decomposed", FIELDS, DecomposedVisitor(PhantomData))
} }
} }
@ -422,11 +422,7 @@ mod serde_de {
None => return Err(serde::de::Error::missing_field("disp")), None => return Err(serde::de::Error::missing_field("disp")),
}; };
Ok(Decomposed { Ok(Decomposed { scale, rot, disp })
scale: scale,
rot: rot,
disp: disp,
})
} }
} }
} }

View file

@ -96,7 +96,7 @@ macro_rules! impl_vector {
/// Construct a new vector, using the provided values. /// Construct a new vector, using the provided values.
#[inline] #[inline]
pub const fn new($($field: S),+) -> $VectorN<S> { pub const fn new($($field: S),+) -> $VectorN<S> {
$VectorN { $($field: $field),+ } $VectorN { $($field),+ }
} }
/// Perform the given operation on each field in the vector, returning a new point /// Perform the given operation on each field in the vector, returning a new point
@ -620,7 +620,7 @@ mod tests {
#[test] #[test]
fn test_index_mut() { fn test_index_mut() {
let mut v = VECTOR2; let mut v = VECTOR2;
*&mut v[0] = 0; v[0] = 0;
assert_eq!(v, [0, 2].into()); assert_eq!(v, [0, 2].into());
} }
@ -741,7 +741,7 @@ mod tests {
#[test] #[test]
fn test_index_mut() { fn test_index_mut() {
let mut v = VECTOR3; let mut v = VECTOR3;
*&mut v[1] = 0; v[1] = 0;
assert_eq!(v, [1, 0, 3].into()); assert_eq!(v, [1, 0, 3].into());
} }
@ -868,7 +868,7 @@ mod tests {
#[test] #[test]
fn test_index_mut() { fn test_index_mut() {
let mut v = VECTOR4; let mut v = VECTOR4;
*&mut v[2] = 0; v[2] = 0;
assert_eq!(v, [1, 2, 0, 4].into()); assert_eq!(v, [1, 2, 0, 4].into());
} }

View file

@ -28,7 +28,7 @@ impl From<Simdf32x4> for Vector4<f32> {
#[inline] #[inline]
fn from(f: Simdf32x4) -> Self { fn from(f: Simdf32x4) -> Self {
unsafe { unsafe {
let mut ret: Self = mem::uninitialized(); let mut ret: Self = mem::MaybeUninit();
{ {
let ret_mut: &mut [f32; 4] = ret.as_mut(); let ret_mut: &mut [f32; 4] = ret.as_mut();
f.store(ret_mut.as_mut(), 0 as usize); f.store(ret_mut.as_mut(), 0 as usize);
@ -244,7 +244,7 @@ impl From<Simdi32x4> for Vector4<i32> {
#[inline] #[inline]
fn from(f: Simdi32x4) -> Self { fn from(f: Simdi32x4) -> Self {
unsafe { unsafe {
let mut ret: Self = mem::uninitialized(); let mut ret: Self = mem::MaybeUninit();
{ {
let ret_mut: &mut [i32; 4] = ret.as_mut(); let ret_mut: &mut [i32; 4] = ret.as_mut();
f.store(ret_mut.as_mut(), 0 as usize); f.store(ret_mut.as_mut(), 0 as usize);
@ -324,7 +324,7 @@ impl From<Simdu32x4> for Vector4<u32> {
#[inline] #[inline]
fn from(f: Simdu32x4) -> Self { fn from(f: Simdu32x4) -> Self {
unsafe { unsafe {
let mut ret: Self = mem::uninitialized(); let mut ret: Self = mem::MaybeUninit();
{ {
let ret_mut: &mut [u32; 4] = ret.as_mut(); let ret_mut: &mut [u32; 4] = ret.as_mut();
f.store(ret_mut.as_mut(), 0 as usize); f.store(ret_mut.as_mut(), 0 as usize);

View file

@ -220,7 +220,7 @@ mod from {
use cgmath::*; use cgmath::*;
fn check_with_euler(x: Rad<f32>, y: Rad<f32>, z: Rad<f32>) { fn check_with_euler(x: Rad<f32>, y: Rad<f32>, z: Rad<f32>) {
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 = Quaternion::from(matrix3);
let quaternion_matrix3 = Matrix3::from(quaternion); let quaternion_matrix3 = Matrix3::from(quaternion);
assert_ulps_eq!(matrix3, quaternion_matrix3); assert_ulps_eq!(matrix3, quaternion_matrix3);
@ -265,7 +265,7 @@ mod arc {
#[test] #[test]
fn test_same() { fn test_same() {
let v = Vector3::unit_x(); 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)); assert_eq!(q, Quaternion::new(1.0, 0.0, 0.0, 0.0));
} }

View file

@ -122,7 +122,7 @@ fn test_look_at_lh() {
assert_ulps_eq!(t, Matrix4::<f64>::look_at_lh(eye, center, up)); assert_ulps_eq!(t, Matrix4::<f64>::look_at_lh(eye, center, up));
assert_ulps_eq!(&t.transform_point(point), &view_point); 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. // remains the same until removed.
#[allow(deprecated)] #[allow(deprecated)]
let t: Decomposed<Vector3<f64>, Quaternion<f64>> = Transform::look_at(eye, center, up); let t: Decomposed<Vector3<f64>, Quaternion<f64>> = Transform::look_at(eye, center, up);