From 2a03d5a59e0b84898166bee191ae226b9128e587 Mon Sep 17 00:00:00 2001 From: Justin Bell <66568249+bellwether-softworks@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:10:06 -0600 Subject: [PATCH] Addressing fallibility issues (#282) * Making heap peek fallible * Switching to use of fallible convex hull processing when instantiating ConvexPolyhedron --- src/query/epa/epa3.rs | 2 +- src/shape/convex_polyhedron.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/query/epa/epa3.rs b/src/query/epa/epa3.rs index 9f8bdc90..7c05daa0 100644 --- a/src/query/epa/epa3.rs +++ b/src/query/epa/epa3.rs @@ -314,7 +314,7 @@ impl EPA { let mut niter = 0; let mut max_dist = Real::max_value(); - let mut best_face_id = *self.heap.peek().unwrap(); + let mut best_face_id = *self.heap.peek()?; let mut old_dist = 0.0; /* diff --git a/src/shape/convex_polyhedron.rs b/src/shape/convex_polyhedron.rs index da03d7ec..ed907e19 100644 --- a/src/shape/convex_polyhedron.rs +++ b/src/shape/convex_polyhedron.rs @@ -117,8 +117,9 @@ impl ConvexPolyhedron { /// This explicitly computes the convex hull of the given set of points. Use /// Returns `None` if the convex hull computation failed. pub fn from_convex_hull(points: &[Point]) -> Option { - let (vertices, indices) = crate::transformation::convex_hull(points); - Self::from_convex_mesh(vertices, &indices) + crate::transformation::try_convex_hull(points) + .ok() + .and_then(|(vertices, indices)| Self::from_convex_mesh(vertices, &indices)) } /// Attempts to create a new solid assumed to be convex from the set of points and indices.