Skip to content

Commit ea9a9e8

Browse files
author
Rémi Lauzier
committed
Fix some clippy warnings
1 parent d1d7422 commit ea9a9e8

19 files changed

+54
-52
lines changed

examples/mvp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
extern crate nalgebra as na;
44

55
use na::{Isometry3, Perspective3, Point3, Vector3};
6+
use std::f32::consts;
67

78
fn main() {
89
// Our object is translated along the x axis.
@@ -15,7 +16,7 @@ fn main() {
1516
let view = Isometry3::look_at_rh(&eye, &target, &Vector3::y());
1617

1718
// A perspective projection.
18-
let projection = Perspective3::new(16.0 / 9.0, 3.14 / 2.0, 1.0, 1000.0);
19+
let projection = Perspective3::new(16.0 / 9.0, consts::PI / 2.0, 1.0, 1000.0);
1920

2021
// The combination of the model with the view is still an isometry.
2122
let model_view = view * model;

examples/raw_pointer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() {
1919

2020
/* Then pass the raw pointers to some graphics API. */
2121

22+
#[allow(clippy::float_cmp)]
2223
unsafe {
2324
assert_eq!(*v_pointer, 1.0);
2425
assert_eq!(*v_pointer.offset(1), 0.0);

examples/screen_to_view_coords.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
extern crate nalgebra as na;
44

55
use na::{Perspective3, Point2, Point3, Unit};
6+
use std::f32::consts;
67

78
fn main() {
8-
let projection = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
9+
let projection = Perspective3::new(800.0 / 600.0, consts::PI / 2.0, 1.0, 1000.0);
910
let screen_point = Point2::new(10.0f32, 20.0);
1011

1112
// Compute two points in clip-space.

examples/transform_conversion.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
extern crate nalgebra as na;
22

33
use na::{Isometry2, Similarity2, Vector2};
4+
use std::f32::consts;
45

56
fn main() {
67
// Isometry -> Similarity conversion always succeeds.
78
let iso = Isometry2::new(Vector2::new(1.0f32, 2.0), na::zero());
89
let _: Similarity2<f32> = na::convert(iso);
910

1011
// Similarity -> Isometry conversion fails if the scaling factor is not 1.0.
11-
let sim_without_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), 3.14, 1.0);
12-
let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), 3.14, 2.0);
12+
let sim_without_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 1.0);
13+
let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 2.0);
1314

1415
let iso_success: Option<Isometry2<f32>> = na::try_convert(sim_without_scaling);
1516
let iso_fail: Option<Isometry2<f32>> = na::try_convert(sim_with_scaling);

examples/transform_matrix4.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extern crate approx;
33
extern crate nalgebra as na;
44

55
use na::{Matrix4, Point3, Vector3};
6+
use std::f32::consts;
67

78
fn main() {
89
// Create a uniform scaling matrix with scaling factor 2.
@@ -28,7 +29,7 @@ fn main() {
2829
);
2930

3031
// Create rotation.
31-
let rot = Matrix4::from_scaled_axis(&Vector3::x() * 3.14);
32+
let rot = Matrix4::from_scaled_axis(Vector3::x() * consts::PI);
3233
let rot_then_m = m * rot; // Right-multiplication is equivalent to prepending `rot` to `m`.
3334
let m_then_rot = rot * m; // Left-multiplication is equivalent to appending `rot` to `m`.
3435

examples/transformation_pointer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn main() {
1212

1313
/* Then pass the raw pointer to some graphics API. */
1414

15+
#[allow(clippy::float_cmp)]
1516
unsafe {
1617
assert_eq!(*iso_pointer, 1.0);
1718
assert_eq!(*iso_pointer.offset(5), 1.0);

examples/unit_wrapper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::float_cmp)]
12
extern crate nalgebra as na;
23

34
use na::{Unit, Vector3};

src/base/edition.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ impl<T: Scalar + Zero, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {
9595
for (destination, source) in icols.enumerate() {
9696
// NOTE: this is basically a copy_frow but wrapping the values insnide of MaybeUninit.
9797
res.column_mut(destination)
98-
.zip_apply(&self.column(*source), |out, e| {
99-
*out = MaybeUninit::new(e.clone())
100-
});
98+
.zip_apply(&self.column(*source), |out, e| *out = MaybeUninit::new(e));
10199
}
102100

103101
// Safety: res is now fully initialized.
@@ -1094,7 +1092,7 @@ unsafe fn compress_rows<T: Scalar>(
10941092

10951093
if new_nrows == 0 || ncols == 0 {
10961094
// The output matrix is empty, drop everything.
1097-
ptr::drop_in_place(data.as_mut());
1095+
ptr::drop_in_place(data);
10981096
return;
10991097
}
11001098

src/base/indexing.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Indexing
2+
#![allow(clippy::reversed_empty_ranges)]
23

34
use crate::base::storage::{RawStorage, RawStorageMut};
45
use crate::base::{
@@ -43,7 +44,7 @@ impl<D: Dim> DimRange<D> for usize {
4344

4445
#[test]
4546
fn dimrange_usize() {
46-
assert_eq!(DimRange::contained_by(&0, Const::<0>), false);
47+
assert!(!DimRange::contained_by(&0, Const::<0>));
4748
assert!(DimRange::contained_by(&0, Const::<1>));
4849
}
4950

@@ -68,8 +69,8 @@ impl<D: Dim> DimRange<D> for ops::Range<usize> {
6869

6970
#[test]
7071
fn dimrange_range_usize() {
71-
assert_eq!(DimRange::contained_by(&(0..0), Const::<0>), false);
72-
assert_eq!(DimRange::contained_by(&(0..1), Const::<0>), false);
72+
assert!(!DimRange::contained_by(&(0..0), Const::<0>));
73+
assert!(!DimRange::contained_by(&(0..1), Const::<0>));
7374
assert!(DimRange::contained_by(&(0..1), Const::<1>));
7475
assert!(DimRange::contained_by(
7576
&((usize::MAX - 1)..usize::MAX),
@@ -110,8 +111,8 @@ impl<D: Dim> DimRange<D> for ops::RangeFrom<usize> {
110111

111112
#[test]
112113
fn dimrange_rangefrom_usize() {
113-
assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false);
114-
assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false);
114+
assert!(!DimRange::contained_by(&(0..), Const::<0>));
115+
assert!(!DimRange::contained_by(&(0..), Const::<0>));
115116
assert!(DimRange::contained_by(&(0..), Const::<1>));
116117
assert!(DimRange::contained_by(
117118
&((usize::MAX - 1)..),
@@ -204,16 +205,16 @@ impl<D: Dim> DimRange<D> for ops::RangeInclusive<usize> {
204205

205206
#[test]
206207
fn dimrange_rangeinclusive_usize() {
207-
assert_eq!(DimRange::contained_by(&(0..=0), Const::<0>), false);
208+
assert!(!DimRange::contained_by(&(0..=0), Const::<0>));
208209
assert!(DimRange::contained_by(&(0..=0), Const::<1>));
209-
assert_eq!(
210-
DimRange::contained_by(&(usize::MAX..=usize::MAX), Dynamic::new(usize::MAX)),
211-
false
212-
);
213-
assert_eq!(
214-
DimRange::contained_by(&((usize::MAX - 1)..=usize::MAX), Dynamic::new(usize::MAX)),
215-
false
216-
);
210+
assert!(!DimRange::contained_by(
211+
&(usize::MAX..=usize::MAX),
212+
Dynamic::new(usize::MAX)
213+
));
214+
assert!(!DimRange::contained_by(
215+
&((usize::MAX - 1)..=usize::MAX),
216+
Dynamic::new(usize::MAX)
217+
));
217218
assert!(DimRange::contained_by(
218219
&((usize::MAX - 1)..=(usize::MAX - 1)),
219220
Dynamic::new(usize::MAX)
@@ -255,7 +256,7 @@ impl<D: Dim> DimRange<D> for ops::RangeTo<usize> {
255256
#[test]
256257
fn dimrange_rangeto_usize() {
257258
assert!(DimRange::contained_by(&(..0), Const::<0>));
258-
assert_eq!(DimRange::contained_by(&(..1), Const::<0>), false);
259+
assert!(!DimRange::contained_by(&(..1), Const::<0>));
259260
assert!(DimRange::contained_by(&(..0), Const::<1>));
260261
assert!(DimRange::contained_by(
261262
&(..(usize::MAX - 1)),
@@ -292,13 +293,13 @@ impl<D: Dim> DimRange<D> for ops::RangeToInclusive<usize> {
292293

293294
#[test]
294295
fn dimrange_rangetoinclusive_usize() {
295-
assert_eq!(DimRange::contained_by(&(..=0), Const::<0>), false);
296-
assert_eq!(DimRange::contained_by(&(..=1), Const::<0>), false);
296+
assert!(!DimRange::contained_by(&(..=0), Const::<0>));
297+
assert!(!DimRange::contained_by(&(..=1), Const::<0>));
297298
assert!(DimRange::contained_by(&(..=0), Const::<1>));
298-
assert_eq!(
299-
DimRange::contained_by(&(..=(usize::MAX)), Dynamic::new(usize::MAX)),
300-
false
301-
);
299+
assert!(!DimRange::contained_by(
300+
&(..=(usize::MAX)),
301+
Dynamic::new(usize::MAX)
302+
));
302303
assert!(DimRange::contained_by(
303304
&(..=(usize::MAX - 1)),
304305
Dynamic::new(usize::MAX)

src/base/matrix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ where
17771777
assert!(self.shape() == other.shape());
17781778
self.iter()
17791779
.zip(other.iter())
1780-
.all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps.clone()))
1780+
.all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps))
17811781
}
17821782
}
17831783

src/base/min_max.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
6060
T: SimdPartialOrd + Zero,
6161
{
6262
self.fold_with(
63-
|e| e.map(|e| e.clone()).unwrap_or_else(T::zero),
63+
|e| e.cloned().unwrap_or_else(T::zero),
6464
|a, b| a.simd_max(b.clone()),
6565
)
6666
}
@@ -123,7 +123,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
123123
T: SimdPartialOrd + Zero,
124124
{
125125
self.fold_with(
126-
|e| e.map(|e| e.clone()).unwrap_or_else(T::zero),
126+
|e| e.cloned().unwrap_or_else(T::zero),
127127
|a, b| a.simd_min(b.clone()),
128128
)
129129
}

src/base/norm.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: StorageMut<T, R, C>> Matrix<T, R, C, S> {
434434
{
435435
let n = self.norm();
436436
let le = n.clone().simd_le(min_norm);
437-
self.apply(|e| {
438-
*e = e
439-
.clone()
440-
.simd_unscale(n.clone())
441-
.select(le.clone(), e.clone())
442-
});
437+
self.apply(|e| *e = e.clone().simd_unscale(n.clone()).select(le, e.clone()));
443438
SimdOption::new(n, le)
444439
}
445440

src/base/uninit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ unsafe impl<T> InitStatus<T> for Uninit {
6666

6767
#[inline(always)]
6868
unsafe fn assume_init_ref(t: &MaybeUninit<T>) -> &T {
69-
std::mem::transmute(t.as_ptr()) // TODO: use t.assume_init_ref()
69+
&*t.as_ptr() // TODO: use t.assume_init_ref()
7070
}
7171

7272
#[inline(always)]
7373
unsafe fn assume_init_mut(t: &mut MaybeUninit<T>) -> &mut T {
74-
std::mem::transmute(t.as_mut_ptr()) // TODO: use t.assume_init_mut()
74+
&mut *t.as_mut_ptr() // TODO: use t.assume_init_mut()
7575
}
7676
}

src/geometry/dual_quaternion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<T: RealField + UlpsEq<Epsilon = T>> UlpsEq for DualQuaternion<T> {
353353
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
354354
self.clone().to_vector().ulps_eq(&other.clone().to_vector(), epsilon.clone(), max_ulps.clone()) ||
355355
// Account for the double-covering of S², i.e. q = -q.
356-
self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone()))
356+
self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps))
357357
}
358358
}
359359

src/geometry/orthographic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<T: RealField> Orthographic3<T> {
175175
);
176176

177177
let half: T = crate::convert(0.5);
178-
let width = zfar.clone() * (vfov.clone() * half.clone()).tan();
178+
let width = zfar.clone() * (vfov * half.clone()).tan();
179179
let height = width.clone() / aspect;
180180

181181
Self::new(

src/geometry/quaternion.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,9 @@ impl<T: RealField + UlpsEq<Epsilon = T>> UlpsEq for Quaternion<T> {
10391039

10401040
#[inline]
10411041
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
1042-
self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps.clone()) ||
1042+
self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps) ||
10431043
// Account for the double-covering of S², i.e. q = -q.
1044-
self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone()))
1044+
self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps))
10451045
}
10461046
}
10471047

@@ -1492,18 +1492,18 @@ where
14921492
let wk = w.clone() * k.clone() * crate::convert(2.0f64);
14931493
let wj = w.clone() * j.clone() * crate::convert(2.0f64);
14941494
let ik = i.clone() * k.clone() * crate::convert(2.0f64);
1495-
let jk = j.clone() * k.clone() * crate::convert(2.0f64);
1496-
let wi = w.clone() * i.clone() * crate::convert(2.0f64);
1495+
let jk = j * k * crate::convert(2.0f64);
1496+
let wi = w * i * crate::convert(2.0f64);
14971497

14981498
Rotation::from_matrix_unchecked(Matrix3::new(
14991499
ww.clone() + ii.clone() - jj.clone() - kk.clone(),
15001500
ij.clone() - wk.clone(),
15011501
wj.clone() + ik.clone(),
1502-
wk.clone() + ij.clone(),
1502+
wk + ij,
15031503
ww.clone() - ii.clone() + jj.clone() - kk.clone(),
15041504
jk.clone() - wi.clone(),
1505-
ik.clone() - wj.clone(),
1506-
wi.clone() + jk.clone(),
1505+
ik - wj,
1506+
wi + jk,
15071507
ww - ii - jj + kk,
15081508
))
15091509
}

src/linalg/determinant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<T: ComplexField, D: DimMin<D, Output = D>, S: Storage<T, D, D>> SquareMatri
4949
let m33 = self.get_unchecked((2, 2)).clone();
5050

5151
let minor_m12_m23 = m22.clone() * m33.clone() - m32.clone() * m23.clone();
52-
let minor_m11_m23 = m21.clone() * m33.clone() - m31.clone() * m23.clone();
52+
let minor_m11_m23 = m21.clone() * m33 - m31.clone() * m23;
5353
let minor_m11_m22 = m21 * m32 - m31 * m22;
5454

5555
m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22

src/linalg/exp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ where
510510
#[cfg(test)]
511511
mod tests {
512512
#[test]
513+
#[allow(clippy::float_cmp)]
513514
fn one_norm() {
514515
use crate::Matrix3;
515516
let m = Matrix3::new(-3.0, 5.0, 7.0, 2.0, 6.0, 4.0, 0.0, 2.0, 8.0);

src/linalg/givens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T: ComplexField> GivensRotation<T> {
4747
if denom > eps {
4848
let norm = sign0.scale(denom.clone());
4949
let c = mod0 / denom;
50-
let s = s.clone() / norm.clone();
50+
let s = s / norm.clone();
5151
Some((Self { c, s }, norm))
5252
} else {
5353
None

0 commit comments

Comments
 (0)