Merge pull request #969 from remilauzier/dev

Fix some clippy warnings
This commit is contained in:
Sébastien Crozet 2021-08-30 10:11:51 +02:00 committed by GitHub
commit 90e531337a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 54 additions and 52 deletions

View File

@ -3,6 +3,7 @@
extern crate nalgebra as na; extern crate nalgebra as na;
use na::{Isometry3, Perspective3, Point3, Vector3}; use na::{Isometry3, Perspective3, Point3, Vector3};
use std::f32::consts;
fn main() { fn main() {
// Our object is translated along the x axis. // Our object is translated along the x axis.
@ -15,7 +16,7 @@ fn main() {
let view = Isometry3::look_at_rh(&eye, &target, &Vector3::y()); let view = Isometry3::look_at_rh(&eye, &target, &Vector3::y());
// A perspective projection. // 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. // The combination of the model with the view is still an isometry.
let model_view = view * model; let model_view = view * model;

View File

@ -19,6 +19,7 @@ fn main() {
/* Then pass the raw pointers to some graphics API. */ /* Then pass the raw pointers to some graphics API. */
#[allow(clippy::float_cmp)]
unsafe { unsafe {
assert_eq!(*v_pointer, 1.0); assert_eq!(*v_pointer, 1.0);
assert_eq!(*v_pointer.offset(1), 0.0); assert_eq!(*v_pointer.offset(1), 0.0);

View File

@ -3,9 +3,10 @@
extern crate nalgebra as na; extern crate nalgebra as na;
use na::{Perspective3, Point2, Point3, Unit}; use na::{Perspective3, Point2, Point3, Unit};
use std::f32::consts;
fn main() { 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); let screen_point = Point2::new(10.0f32, 20.0);
// Compute two points in clip-space. // Compute two points in clip-space.

View File

@ -1,6 +1,7 @@
extern crate nalgebra as na; extern crate nalgebra as na;
use na::{Isometry2, Similarity2, Vector2}; use na::{Isometry2, Similarity2, Vector2};
use std::f32::consts;
fn main() { fn main() {
// Isometry -> Similarity conversion always succeeds. // Isometry -> Similarity conversion always succeeds.
@ -8,8 +9,8 @@ fn main() {
let _: Similarity2<f32> = na::convert(iso); let _: Similarity2<f32> = na::convert(iso);
// Similarity -> Isometry conversion fails if the scaling factor is not 1.0. // 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_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), 3.14, 2.0); let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 2.0);
let iso_success: Option<Isometry2<f32>> = na::try_convert(sim_without_scaling); let iso_success: Option<Isometry2<f32>> = na::try_convert(sim_without_scaling);
let iso_fail: Option<Isometry2<f32>> = na::try_convert(sim_with_scaling); let iso_fail: Option<Isometry2<f32>> = na::try_convert(sim_with_scaling);

View File

@ -3,6 +3,7 @@ extern crate approx;
extern crate nalgebra as na; extern crate nalgebra as na;
use na::{Matrix4, Point3, Vector3}; use na::{Matrix4, Point3, Vector3};
use std::f32::consts;
fn main() { fn main() {
// Create a uniform scaling matrix with scaling factor 2. // Create a uniform scaling matrix with scaling factor 2.
@ -28,7 +29,7 @@ fn main() {
); );
// Create rotation. // 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 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`. let m_then_rot = rot * m; // Left-multiplication is equivalent to appending `rot` to `m`.

View File

@ -12,6 +12,7 @@ fn main() {
/* Then pass the raw pointer to some graphics API. */ /* Then pass the raw pointer to some graphics API. */
#[allow(clippy::float_cmp)]
unsafe { unsafe {
assert_eq!(*iso_pointer, 1.0); assert_eq!(*iso_pointer, 1.0);
assert_eq!(*iso_pointer.offset(5), 1.0); assert_eq!(*iso_pointer.offset(5), 1.0);

View File

@ -1,3 +1,4 @@
#![allow(clippy::float_cmp)]
extern crate nalgebra as na; extern crate nalgebra as na;
use na::{Unit, Vector3}; use na::{Unit, Vector3};

View File

@ -95,9 +95,7 @@ impl<T: Scalar + Zero, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {
for (destination, source) in icols.enumerate() { for (destination, source) in icols.enumerate() {
// NOTE: this is basically a copy_frow but wrapping the values insnide of MaybeUninit. // NOTE: this is basically a copy_frow but wrapping the values insnide of MaybeUninit.
res.column_mut(destination) res.column_mut(destination)
.zip_apply(&self.column(*source), |out, e| { .zip_apply(&self.column(*source), |out, e| *out = MaybeUninit::new(e));
*out = MaybeUninit::new(e.clone())
});
} }
// Safety: res is now fully initialized. // Safety: res is now fully initialized.
@ -1094,7 +1092,7 @@ unsafe fn compress_rows<T: Scalar>(
if new_nrows == 0 || ncols == 0 { if new_nrows == 0 || ncols == 0 {
// The output matrix is empty, drop everything. // The output matrix is empty, drop everything.
ptr::drop_in_place(data.as_mut()); ptr::drop_in_place(data);
return; return;
} }

View File

@ -1,4 +1,5 @@
//! Indexing //! Indexing
#![allow(clippy::reversed_empty_ranges)]
use crate::base::storage::{RawStorage, RawStorageMut}; use crate::base::storage::{RawStorage, RawStorageMut};
use crate::base::{ use crate::base::{
@ -43,7 +44,7 @@ impl<D: Dim> DimRange<D> for usize {
#[test] #[test]
fn dimrange_usize() { 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>)); assert!(DimRange::contained_by(&0, Const::<1>));
} }
@ -68,8 +69,8 @@ impl<D: Dim> DimRange<D> for ops::Range<usize> {
#[test] #[test]
fn dimrange_range_usize() { fn dimrange_range_usize() {
assert_eq!(DimRange::contained_by(&(0..0), Const::<0>), false); assert!(!DimRange::contained_by(&(0..0), Const::<0>));
assert_eq!(DimRange::contained_by(&(0..1), Const::<0>), false); assert!(!DimRange::contained_by(&(0..1), Const::<0>));
assert!(DimRange::contained_by(&(0..1), Const::<1>)); assert!(DimRange::contained_by(&(0..1), Const::<1>));
assert!(DimRange::contained_by( assert!(DimRange::contained_by(
&((usize::MAX - 1)..usize::MAX), &((usize::MAX - 1)..usize::MAX),
@ -110,8 +111,8 @@ impl<D: Dim> DimRange<D> for ops::RangeFrom<usize> {
#[test] #[test]
fn dimrange_rangefrom_usize() { fn dimrange_rangefrom_usize() {
assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false); assert!(!DimRange::contained_by(&(0..), Const::<0>));
assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false); assert!(!DimRange::contained_by(&(0..), Const::<0>));
assert!(DimRange::contained_by(&(0..), Const::<1>)); assert!(DimRange::contained_by(&(0..), Const::<1>));
assert!(DimRange::contained_by( assert!(DimRange::contained_by(
&((usize::MAX - 1)..), &((usize::MAX - 1)..),
@ -204,16 +205,16 @@ impl<D: Dim> DimRange<D> for ops::RangeInclusive<usize> {
#[test] #[test]
fn dimrange_rangeinclusive_usize() { 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!(DimRange::contained_by(&(0..=0), Const::<1>));
assert_eq!( assert!(!DimRange::contained_by(
DimRange::contained_by(&(usize::MAX..=usize::MAX), Dynamic::new(usize::MAX)), &(usize::MAX..=usize::MAX),
false Dynamic::new(usize::MAX)
); ));
assert_eq!( assert!(!DimRange::contained_by(
DimRange::contained_by(&((usize::MAX - 1)..=usize::MAX), Dynamic::new(usize::MAX)), &((usize::MAX - 1)..=usize::MAX),
false Dynamic::new(usize::MAX)
); ));
assert!(DimRange::contained_by( assert!(DimRange::contained_by(
&((usize::MAX - 1)..=(usize::MAX - 1)), &((usize::MAX - 1)..=(usize::MAX - 1)),
Dynamic::new(usize::MAX) Dynamic::new(usize::MAX)
@ -255,7 +256,7 @@ impl<D: Dim> DimRange<D> for ops::RangeTo<usize> {
#[test] #[test]
fn dimrange_rangeto_usize() { fn dimrange_rangeto_usize() {
assert!(DimRange::contained_by(&(..0), Const::<0>)); 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(&(..0), Const::<1>));
assert!(DimRange::contained_by( assert!(DimRange::contained_by(
&(..(usize::MAX - 1)), &(..(usize::MAX - 1)),
@ -292,13 +293,13 @@ impl<D: Dim> DimRange<D> for ops::RangeToInclusive<usize> {
#[test] #[test]
fn dimrange_rangetoinclusive_usize() { fn dimrange_rangetoinclusive_usize() {
assert_eq!(DimRange::contained_by(&(..=0), Const::<0>), false); 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(&(..=0), Const::<1>));
assert_eq!( assert!(!DimRange::contained_by(
DimRange::contained_by(&(..=(usize::MAX)), Dynamic::new(usize::MAX)), &(..=(usize::MAX)),
false Dynamic::new(usize::MAX)
); ));
assert!(DimRange::contained_by( assert!(DimRange::contained_by(
&(..=(usize::MAX - 1)), &(..=(usize::MAX - 1)),
Dynamic::new(usize::MAX) Dynamic::new(usize::MAX)

View File

@ -1792,7 +1792,7 @@ where
assert!(self.shape() == other.shape()); assert!(self.shape() == other.shape());
self.iter() self.iter()
.zip(other.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))
} }
} }

View File

@ -60,7 +60,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
T: SimdPartialOrd + Zero, T: SimdPartialOrd + Zero,
{ {
self.fold_with( 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()), |a, b| a.simd_max(b.clone()),
) )
} }
@ -123,7 +123,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
T: SimdPartialOrd + Zero, T: SimdPartialOrd + Zero,
{ {
self.fold_with( 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()), |a, b| a.simd_min(b.clone()),
) )
} }

View File

@ -434,12 +434,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: StorageMut<T, R, C>> Matrix<T, R, C, S> {
{ {
let n = self.norm(); let n = self.norm();
let le = n.clone().simd_le(min_norm); let le = n.clone().simd_le(min_norm);
self.apply(|e| { self.apply(|e| *e = e.clone().simd_unscale(n.clone()).select(le, e.clone()));
*e = e
.clone()
.simd_unscale(n.clone())
.select(le.clone(), e.clone())
});
SimdOption::new(n, le) SimdOption::new(n, le)
} }

View File

@ -66,11 +66,11 @@ unsafe impl<T> InitStatus<T> for Uninit {
#[inline(always)] #[inline(always)]
unsafe fn assume_init_ref(t: &MaybeUninit<T>) -> &T { unsafe fn assume_init_ref(t: &MaybeUninit<T>) -> &T {
std::mem::transmute(t.as_ptr()) // TODO: use t.assume_init_ref() &*t.as_ptr() // TODO: use t.assume_init_ref()
} }
#[inline(always)] #[inline(always)]
unsafe fn assume_init_mut(t: &mut MaybeUninit<T>) -> &mut T { unsafe fn assume_init_mut(t: &mut MaybeUninit<T>) -> &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()
} }
} }

View File

@ -353,7 +353,7 @@ impl<T: RealField + UlpsEq<Epsilon = T>> UlpsEq for DualQuaternion<T> {
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { 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()) || 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. // 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))
} }
} }

View File

@ -175,7 +175,7 @@ impl<T: RealField> Orthographic3<T> {
); );
let half: T = crate::convert(0.5); 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; let height = width.clone() / aspect;
Self::new( Self::new(

View File

@ -1039,9 +1039,9 @@ impl<T: RealField + UlpsEq<Epsilon = T>> UlpsEq for Quaternion<T> {
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { 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. // 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 wk = w.clone() * k.clone() * crate::convert(2.0f64);
let wj = w.clone() * j.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 ik = i.clone() * k.clone() * crate::convert(2.0f64);
let jk = j.clone() * k.clone() * crate::convert(2.0f64); let jk = j * k * crate::convert(2.0f64);
let wi = w.clone() * i.clone() * crate::convert(2.0f64); let wi = w * i * crate::convert(2.0f64);
Rotation::from_matrix_unchecked(Matrix3::new( Rotation::from_matrix_unchecked(Matrix3::new(
ww.clone() + ii.clone() - jj.clone() - kk.clone(), ww.clone() + ii.clone() - jj.clone() - kk.clone(),
ij.clone() - wk.clone(), ij.clone() - wk.clone(),
wj.clone() + ik.clone(), wj.clone() + ik.clone(),
wk.clone() + ij.clone(), wk + ij,
ww.clone() - ii.clone() + jj.clone() - kk.clone(), ww.clone() - ii.clone() + jj.clone() - kk.clone(),
jk.clone() - wi.clone(), jk.clone() - wi.clone(),
ik.clone() - wj.clone(), ik - wj,
wi.clone() + jk.clone(), wi + jk,
ww - ii - jj + kk, ww - ii - jj + kk,
)) ))
} }

View File

@ -49,7 +49,7 @@ impl<T: ComplexField, D: DimMin<D, Output = D>, S: Storage<T, D, D>> SquareMatri
let m33 = self.get_unchecked((2, 2)).clone(); let m33 = self.get_unchecked((2, 2)).clone();
let minor_m12_m23 = m22.clone() * m33.clone() - m32.clone() * m23.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; let minor_m11_m22 = m21 * m32 - m31 * m22;
m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22 m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22

View File

@ -510,6 +510,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]
#[allow(clippy::float_cmp)]
fn one_norm() { fn one_norm() {
use crate::Matrix3; 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); let m = Matrix3::new(-3.0, 5.0, 7.0, 2.0, 6.0, 4.0, 0.0, 2.0, 8.0);

View File

@ -47,7 +47,7 @@ impl<T: ComplexField> GivensRotation<T> {
if denom > eps { if denom > eps {
let norm = sign0.scale(denom.clone()); let norm = sign0.scale(denom.clone());
let c = mod0 / denom; let c = mod0 / denom;
let s = s.clone() / norm.clone(); let s = s / norm.clone();
Some((Self { c, s }, norm)) Some((Self { c, s }, norm))
} else { } else {
None None