From e8dce5254b0448434f33fb59b2915bf4f149bea1 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 28 Aug 2023 00:54:36 +0700 Subject: [PATCH 1/2] clippy: Fix needless return warnings. --- src/query/epa/epa2.rs | 2 +- src/query/epa/epa3.rs | 2 +- src/query/gjk/voronoi_simplex2.rs | 2 +- src/query/gjk/voronoi_simplex3.rs | 2 +- src/query/point/point_cylinder.rs | 4 ++-- src/query/point/point_tetrahedron.rs | 4 ++-- src/query/point/point_triangle.rs | 4 ++-- src/shape/polyline.rs | 2 +- src/shape/triangle.rs | 6 +----- src/utils/point_in_poly2d.rs | 2 +- src/utils/segments_intersection.rs | 2 +- 11 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/query/epa/epa2.rs b/src/query/epa/epa2.rs index 15866aa2..dac3476a 100644 --- a/src/query/epa/epa2.rs +++ b/src/query/epa/epa2.rs @@ -346,7 +346,7 @@ impl EPA { let best_face = &self.faces[best_face_id.id]; let cpts = best_face.closest_points(&self.vertices); - return Some((cpts.0, cpts.1, best_face.normal)); + Some((cpts.0, cpts.1, best_face.normal)) } } diff --git a/src/query/epa/epa3.rs b/src/query/epa/epa3.rs index 1396cf05..bea8597e 100644 --- a/src/query/epa/epa3.rs +++ b/src/query/epa/epa3.rs @@ -418,7 +418,7 @@ impl EPA { let best_face = &self.faces[best_face_id.id]; let points = best_face.closest_points(&self.vertices); - return Some((points.0, points.1, best_face.normal)); + Some((points.0, points.1, best_face.normal)) } fn compute_silhouette(&mut self, point: usize, id: usize, opp_pt_id: usize) { diff --git a/src/query/gjk/voronoi_simplex2.rs b/src/query/gjk/voronoi_simplex2.rs index 6b019d22..891c8c4d 100644 --- a/src/query/gjk/voronoi_simplex2.rs +++ b/src/query/gjk/voronoi_simplex2.rs @@ -55,7 +55,7 @@ impl VoronoiSimplex { self.dim += 1; self.vertices[self.dim] = pt; - return true; + true } /// Retrieves the barycentric coordinate associated to the `i`-th by the last call to `project_origin_and_reduce`. diff --git a/src/query/gjk/voronoi_simplex3.rs b/src/query/gjk/voronoi_simplex3.rs index 4bf11c02..44f07ff9 100644 --- a/src/query/gjk/voronoi_simplex3.rs +++ b/src/query/gjk/voronoi_simplex3.rs @@ -82,7 +82,7 @@ impl VoronoiSimplex { self.dim += 1; self.vertices[self.dim] = pt; - return true; + true } /// Retrieves the barycentric coordinate associated to the `i`-th by the last call to `project_origin_and_reduce`. diff --git a/src/query/point/point_cylinder.rs b/src/query/point/point_cylinder.rs index 554e197e..d0e5b505 100644 --- a/src/query/point/point_cylinder.rs +++ b/src/query/point/point_cylinder.rs @@ -45,11 +45,11 @@ impl PointQuery for Cylinder { if pt.y > self.half_height { if planar_dist_from_basis_center <= self.radius { let projection_on_top = Point::new(pt.coords.x, self.half_height, pt.coords.z); - return PointProjection::new(false, projection_on_top); + PointProjection::new(false, projection_on_top) } else { let projection_on_top_circle = Point::new(proj2d[0], self.half_height, proj2d[1]); - return PointProjection::new(false, projection_on_top_circle); + PointProjection::new(false, projection_on_top_circle) } } else if pt.y < -self.half_height { // Project on the bottom plane or the bottom circle. diff --git a/src/query/point/point_tetrahedron.rs b/src/query/point/point_tetrahedron.rs index 1455b4b6..9964937e 100644 --- a/src/query/point/point_tetrahedron.rs +++ b/src/query/point/point_tetrahedron.rs @@ -294,7 +294,7 @@ impl PointQueryWithLocation for Tetrahedron { return Some((proj, TetrahedronPointLocation::OnFace(i as u32, bcoords))); } } - return None; + None } // Face abc. @@ -343,6 +343,6 @@ impl PointQueryWithLocation for Tetrahedron { } let proj = PointProjection::new(true, *pt); - return (proj, TetrahedronPointLocation::OnSolid); + (proj, TetrahedronPointLocation::OnSolid) } } diff --git a/src/query/point/point_triangle.rs b/src/query/point/point_triangle.rs index 1d70b1bd..ce118645 100644 --- a/src/query/point/point_triangle.rs +++ b/src/query/point/point_triangle.rs @@ -139,7 +139,7 @@ impl PointQueryWithLocation for Triangle { return ProjectionInfo::OnBC; } - return ProjectionInfo::OnFace(0, va, vb, vc); + ProjectionInfo::OnFace(0, va, vb, vc) } #[cfg(feature = "dim3")] { @@ -173,7 +173,7 @@ impl PointQueryWithLocation for Triangle { let clockwise = if n.dot(ap) >= 0.0 { 0 } else { 1 }; - return ProjectionInfo::OnFace(clockwise, va, vb, vc); + ProjectionInfo::OnFace(clockwise, va, vb, vc) } } diff --git a/src/shape/polyline.rs b/src/shape/polyline.rs index 8d47b35d..64be51a7 100644 --- a/src/shape/polyline.rs +++ b/src/shape/polyline.rs @@ -171,7 +171,7 @@ impl Polyline { if indices.len() == 0 { // Polyline is empty, return empty Vec - return Vec::new(); + Vec::new() } else { let mut components = Vec::new(); diff --git a/src/shape/triangle.rs b/src/shape/triangle.rs index 2153b567..e0c9b6c6 100644 --- a/src/shape/triangle.rs +++ b/src/shape/triangle.rs @@ -511,11 +511,7 @@ impl Triangle { let c = vp.dot(&nb) * signed_clim.signum(); let clim = signed_clim.abs(); - return c >= 0.0 - && c <= clim - && b >= 0.0 - && b <= blim - && c * blim + b * clim <= blim * clim; + c >= 0.0 && c <= clim && b >= 0.0 && b <= blim && c * blim + b * clim <= blim * clim } /// The normal of the given feature of this shape. diff --git a/src/utils/point_in_poly2d.rs b/src/utils/point_in_poly2d.rs index 7083ffbb..c92eb305 100644 --- a/src/utils/point_in_poly2d.rs +++ b/src/utils/point_in_poly2d.rs @@ -22,6 +22,6 @@ pub fn point_in_poly2d(pt: &Point2, poly: &[Point2]) -> bool { } } - return true; + true } } diff --git a/src/utils/segments_intersection.rs b/src/utils/segments_intersection.rs index e508c137..09aab083 100644 --- a/src/utils/segments_intersection.rs +++ b/src/utils/segments_intersection.rs @@ -141,7 +141,7 @@ fn parallel_intersection( }); } - return None; + None } // Checks that `c` is in-between `a` and `b`. From 468811b12968289044e54b278d4ac55c4849fd75 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 28 Aug 2023 00:58:58 +0700 Subject: [PATCH 2/2] clippy: Fix mem_replace_with_default. When replacing something with the default value, can juse use `take` instead. --- src/partitioning/qbvh/update.rs | 2 +- src/query/contact_manifolds/contact_manifold.rs | 2 +- .../contact_manifolds_composite_shape_composite_shape.rs | 2 +- .../contact_manifolds_composite_shape_shape.rs | 2 +- .../contact_manifolds/contact_manifolds_halfspace_pfm.rs | 2 +- .../contact_manifolds_heightfield_composite_shape.rs | 2 +- .../contact_manifolds/contact_manifolds_heightfield_shape.rs | 2 +- src/shape/trimesh.rs | 4 ++-- src/transformation/convex_hull3/convex_hull.rs | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/partitioning/qbvh/update.rs b/src/partitioning/qbvh/update.rs index 3e0a4082..7c948432 100644 --- a/src/partitioning/qbvh/update.rs +++ b/src/partitioning/qbvh/update.rs @@ -377,7 +377,7 @@ impl Qbvh { workspace.to_sort.extend(0..workspace.orig_ids.len()); let root_id = NodeIndex::new(0, 0); - let mut indices = std::mem::replace(&mut workspace.to_sort, vec![]); + let mut indices = std::mem::take(&mut workspace.to_sort); let (id, aabb) = self.do_recurse_rebalance(&mut indices, workspace, root_id, margin); workspace.to_sort = indices; diff --git a/src/query/contact_manifolds/contact_manifold.rs b/src/query/contact_manifolds/contact_manifold.rs index 66a3ebd9..e1560fce 100644 --- a/src/query/contact_manifolds/contact_manifold.rs +++ b/src/query/contact_manifolds/contact_manifold.rs @@ -141,7 +141,7 @@ impl ContactManifold( // Traverse qbvh1 first. let ls_aabb2_1 = shape2.compute_aabb(&pos12).loosened(prediction); - let mut old_manifolds = std::mem::replace(manifolds, Vec::new()); + let mut old_manifolds = std::mem::take(manifolds); let mut leaf1_fn = |leaf1: &u32| { composite1.map_part_at(*leaf1, &mut |part_pos1, part_shape1| { diff --git a/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs b/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs index 8d04b0e8..f055e8f3 100644 --- a/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs +++ b/src/query/contact_manifolds/contact_manifolds_halfspace_pfm.rs @@ -58,7 +58,7 @@ pub fn contact_manifold_halfspace_pfm<'a, ManifoldData, ContactData, S2>( // We do this clone to perform contact tracking and transfer impulses. // FIXME: find a more efficient way of doing this. - let old_manifold_points = std::mem::replace(&mut manifold.points, Default::default()); + let old_manifold_points = std::mem::take(&mut manifold.points); for i in 0..feature2.num_vertices { let vtx2 = feature2.vertices[i]; diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs index de3dda33..e1c6afaa 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_composite_shape.rs @@ -91,7 +91,7 @@ pub fn contact_manifolds_heightfield_composite_shape( let qbvh2 = composite2.qbvh(); let mut stack2 = Vec::new(); let ls_aabb2_1 = qbvh2.root_aabb().transform_by(pos12).loosened(prediction); - let mut old_manifolds = std::mem::replace(manifolds, Vec::new()); + let mut old_manifolds = std::mem::take(manifolds); heightfield1.map_elements_in_local_aabb(&ls_aabb2_1, &mut |leaf1, part1| { #[cfg(feature = "dim2")] diff --git a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs index 97244891..1ea8a641 100644 --- a/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs +++ b/src/query/contact_manifolds/contact_manifolds_heightfield_shape.rs @@ -125,7 +125,7 @@ pub fn contact_manifolds_heightfield_shape( */ // TODO: somehow precompute the Aabb and reuse it? let ls_aabb2 = shape2.compute_aabb(pos12).loosened(prediction); - let mut old_manifolds = std::mem::replace(manifolds, Vec::new()); + let mut old_manifolds = std::mem::take(manifolds); heightfield1.map_elements_in_local_aabb(&ls_aabb2, &mut |i, part1| { #[cfg(feature = "dim2")] diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index 8686207c..c282fbfb 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -575,8 +575,8 @@ impl TriMesh { .map(|idx| [idx[0] + base_id, idx[1] + base_id, idx[2] + base_id]), ); - let vertices = std::mem::replace(&mut self.vertices, Vec::new()); - let indices = std::mem::replace(&mut self.indices, Vec::new()); + let vertices = std::mem::take(&mut self.vertices); + let indices = std::mem::take(&mut self.indices); *self = TriMesh::with_flags(vertices, indices, self.flags); } diff --git a/src/transformation/convex_hull3/convex_hull.rs b/src/transformation/convex_hull3/convex_hull.rs index 5cadb5ee..cd59bdfa 100644 --- a/src/transformation/convex_hull3/convex_hull.rs +++ b/src/transformation/convex_hull3/convex_hull.rs @@ -250,7 +250,7 @@ fn fix_silhouette_topology( } let mut removing = None; - let old_facets_and_idx = std::mem::replace(out_facets_and_idx, Vec::new()); + let old_facets_and_idx = std::mem::take(out_facets_and_idx); for i in 0..old_facets_and_idx.len() { let facet_id = (loop_start + i) % old_facets_and_idx.len();