Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some clippy warnings #130

Merged
merged 1 commit into from Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/polyhedron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ fn sphere(n: usize, with_faces: bool) -> ConvexPolyhedron<f32> {
.map(|f| (f.x, f.y, f.z))
.collect::<Vec<_>>();

ConvexPolyhedron::new_with_faces(vertices, faces)
ConvexPolyhedron::new_with_faces(&vertices, &faces)
} else {
ConvexPolyhedron::new(vertices)
ConvexPolyhedron::new(&vertices)
}
}
12 changes: 6 additions & 6 deletions src/algorithm/minkowski/epa/epa2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ mod tests {

#[test]
fn test_closest_edge_0() {
assert_eq!(None, closest_edge::<f32>(&[]))
assert_eq!(None, closest_edge::<f32>(&[]));
}

#[test]
fn test_closest_edge_1() {
assert_eq!(None, closest_edge(&[sup(10., 10.)]))
assert_eq!(None, closest_edge(&[sup(10., 10.)]));
}

#[test]
fn test_closest_edge_2() {
assert_eq!(None, closest_edge(&[sup(10., 10.), sup(-10., 5.)]))
assert_eq!(None, closest_edge(&[sup(10., 10.), sup(-10., 5.)]));
}

#[test]
Expand All @@ -185,9 +185,9 @@ mod tests {
assert!(edge.is_some());
let edge = edge.unwrap();
assert_eq!(2, edge.index);
assert_ulps_eq!(2.5607374, edge.distance);
assert_ulps_eq!(-0.6401844, edge.normal.x);
assert_ulps_eq!(-0.7682213, edge.normal.y);
assert_ulps_eq!(2.560_737_4, edge.distance);
assert_ulps_eq!(-0.640_184_4, edge.normal.x);
assert_ulps_eq!(-0.768_221_3, edge.normal.y);
}

#[test]
Expand Down
29 changes: 26 additions & 3 deletions src/algorithm/minkowski/epa/epa3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,34 @@ mod tests {
let faces = Face::new(&simplex);
assert_eq!(4, faces.len());
assert_face(
&faces[0], 3, 2, 1, -0.8728715, 0.43643576, 0.21821788, 1.0910894,
&faces[0],
3,
2,
1,
-0.872_871_5,
0.436_435_76,
0.218_217_88,
1.091_089_4,
);
assert_face(&faces[1], 3, 1, 0, 0., -0.89442724, 0.44721362, 2.236068);
assert_face(
&faces[2], 3, 0, 2, 0.8728715, 0.43643576, 0.21821788, 1.0910894,
&faces[1],
3,
1,
0,
0.,
-0.894_427_24,
0.447_213_62,
2.236_068,
);
assert_face(
&faces[2],
3,
0,
2,
0.872_871_5,
0.436_435_76,
0.218_217_88,
1.091_089_4,
);
assert_face(&faces[3], 2, 0, 1, 0., 0., -1., 1.0);
}
Expand Down
40 changes: 20 additions & 20 deletions src/algorithm/minkowski/gjk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use cgmath::ulps_eq;
mod simplex;

const MAX_ITERATIONS: u32 = 100;
const GJK_DISTANCE_TOLERANCE: f32 = 0.000001;
const GJK_CONTINUOUS_TOLERANCE: f32 = 0.000001;
const GJK_DISTANCE_TOLERANCE: f32 = 0.000_001;
const GJK_CONTINUOUS_TOLERANCE: f32 = 0.000_001;

/// GJK algorithm for 2D, see [GJK](struct.GJK.html) for more information.
pub type GJK2<S> = GJK<SimplexProcessor2<S>, EPA2<S>, S>;
Expand Down Expand Up @@ -163,9 +163,9 @@ where
pub fn intersection_time_of_impact<P, PL, PR, TL, TR>(
&self,
left: &PL,
left_transform: Range<&TL>,
left_transform: &Range<&TL>,
right: &PR,
right_transform: Range<&TR>,
right_transform: &Range<&TR>,
) -> Option<Contact<P>>
where
P: EuclideanSpace<Scalar = S>,
Expand Down Expand Up @@ -506,7 +506,7 @@ where
min_distance = Some(
min_distance
.map_or(distance, |min_distance| distance.min(min_distance)),
)
);
}
}
}
Expand Down Expand Up @@ -539,9 +539,9 @@ where
&self,
strategy: &CollisionStrategy,
left: &[(PL, TL)],
left_transform: Range<&TL>,
left_transform: &Range<&TL>,
right: &[(PR, TR)],
right_transform: Range<&TR>,
right_transform: &Range<&TR>,
) -> Option<Contact<P>>
where
P: EuclideanSpace<Scalar = S>,
Expand All @@ -562,9 +562,9 @@ where
let right_end_transform = right_transform.end.concat(right_local_transform);
if let Some(mut contact) = self.intersection_time_of_impact(
left_primitive,
&left_start_transform..&left_end_transform,
&(&left_start_transform..&left_end_transform),
right_primitive,
&right_start_transform..&right_end_transform,
&(&right_start_transform..&right_end_transform),
) {
match *strategy {
CollisionOnly => {
Expand Down Expand Up @@ -670,7 +670,7 @@ mod tests {
&right,
&right_transform
)
.is_none())
.is_none());
}

#[test]
Expand Down Expand Up @@ -770,23 +770,23 @@ mod tests {
let contact = gjk
.intersection_time_of_impact(
&left,
&left_start_transform..&left_end_transform,
&(&left_start_transform..&left_end_transform),
&right,
&right_transform..&right_transform,
&(&right_transform..&right_transform),
)
.unwrap();

assert_ulps_eq!(0.1666667, contact.time_of_impact);
assert_ulps_eq!(0.166_666_7, contact.time_of_impact);
assert_eq!(Vector2::new(-1., 0.), contact.normal);
assert!(0. - contact.penetration_depth <= f32::EPSILON);
assert_eq!(Point2::new(10., 0.), contact.contact_point);

assert!(gjk
.intersection_time_of_impact(
&left,
&left_start_transform..&left_start_transform,
&(&left_start_transform..&left_start_transform),
&right,
&right_transform..&right_transform
&(&right_transform..&right_transform)
)
.is_none());
}
Expand All @@ -803,23 +803,23 @@ mod tests {
let contact = gjk
.intersection_time_of_impact(
&left,
&left_start_transform..&left_end_transform,
&(&left_start_transform..&left_end_transform),
&right,
&right_transform..&right_transform,
&(&right_transform..&right_transform),
)
.unwrap();

assert_ulps_eq!(0.1666667, contact.time_of_impact);
assert_ulps_eq!(0.166_666_7, contact.time_of_impact);
assert_eq!(Vector3::new(-1., 0., 0.), contact.normal);
assert!(0. - contact.penetration_depth <= f32::EPSILON);
assert_eq!(Point3::new(10., 0., 0.), contact.contact_point);

assert!(gjk
.intersection_time_of_impact(
&left,
&left_start_transform..&left_start_transform,
&(&left_start_transform..&left_start_transform),
&right,
&right_transform..&right_transform
&(&right_transform..&right_transform)
)
.is_none());
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
rust_2018_idioms,
nonstandard_style,
unused,
future_incompatible
future_incompatible,
clippy::semicolon_if_nothing_returned,
clippy::unreadable_literal,
clippy::unseparated_literal_suffix,
clippy::needless_pass_by_value
)]
#![allow(clippy::excessive_precision)]

Expand Down
8 changes: 4 additions & 4 deletions src/primitive/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ mod tests {
let direction = Vector3::new(0.5, -1., 0.).normalize();
let transform = transform(0., 0., 0., 0.);
let point = capsule.support_point(&direction, &transform);
assert_ulps_eq!(Point3::new(0.44721365, -2.8944273, 0.), point);
assert_ulps_eq!(Point3::new(0.447_213_65, -2.894_427_3, 0.), point);
}

#[test]
Expand Down Expand Up @@ -327,9 +327,9 @@ mod tests {
);
assert_eq!(
Some(Point3::new(
0.10102588514869944,
2.989741148513006,
0.10102588514869944
0.101_025_885_148_699_44,
2.989_741_148_513_006,
0.101_025_885_148_699_44
)),
capsule.intersection(&ray)
);
Expand Down
4 changes: 2 additions & 2 deletions src/primitive/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {

#[test]
fn test_circle_far_2() {
test_circle(1., 1., 7.0710677, 7.0710677, 0.);
test_circle(1., 1., 7.071_067_7, 7.071_067_7, 0.);
}

#[test]
Expand All @@ -126,7 +126,7 @@ mod tests {
#[test]
fn test_circle_bound() {
let circle = Circle::new(10.);
assert_eq!(bound(-10., -10., 10., 10.), circle.compute_bound())
assert_eq!(bound(-10., -10., 10., 10.), circle.compute_bound());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/primitive/cuboid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod tests {
#[test]
fn test_rectangle_bound() {
let r = Cuboid::new(10., 10., 10.);
assert_eq!(bound(-5., -5., -5., 5., 5., 5.), r.compute_bound())
assert_eq!(bound(-5., -5., -5., 5., 5., 5.), r.compute_bound());
}

#[test]
Expand Down Expand Up @@ -271,7 +271,7 @@ mod tests {
let ray = Ray3::new(Point3::new(10., 0., 0.), Vector3::new(-1., 0., 0.));
let t = transform(0., 0., 0., 0.3);
let p = cuboid.intersection_transformed(&ray, &t).unwrap();
assert_ulps_eq!(5.233758, p.x);
assert_ulps_eq!(5.233_758, p.x);
assert_ulps_eq!(0., p.y);
assert_ulps_eq!(0., p.z);
}
Expand Down
4 changes: 2 additions & 2 deletions src/primitive/particle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
fn test_continuous() {
let circle = Circle::new(4.);
assert_ulps_eq!(
Point2::new(-2.8284271247461903, -2.8284271247461903),
Point2::new(-2.828_427_124_746_190_3, -2.828_427_124_746_190_3),
circle
.intersection(&(Particle::new(), Point2::new(-5., -5.)..Point2::new(5., 5.)))
.unwrap()
Expand All @@ -223,7 +223,7 @@ mod tests {
let circle = Circle::new(4.);
let t = transform(0., 0., 0.);
assert_ulps_eq!(
Point2::new(-2.8284271247461903, -2.8284271247461903),
Point2::new(-2.828_427_124_746_190_3, -2.828_427_124_746_190_3),
circle
.intersection_transformed(
&(Particle::new(), Point2::new(-5., -5.)..Point2::new(5., 5.)),
Expand Down
2 changes: 1 addition & 1 deletion src/primitive/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ mod tests {
assert_eq!(None, polygon.intersection_transformed(&ray, &t));
let t = transform(0., 0., 0.3);
let p = polygon.intersection_transformed(&ray, &t).unwrap();
assert_ulps_eq!(0.38913357, p.x);
assert_ulps_eq!(0.389_133_57, p.x);
assert_ulps_eq!(6.8, p.y);
}

Expand Down
Loading