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

If we have less than 3 points return empty convex hull #165

Merged
merged 5 commits into from
Jul 20, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Significantly improved the general stability of mesh/mesh intersection calculation.
- Rename `Shape::clone_box` to `Shape::clone_dyn` (the `clone_box` method still exists but has been
deprecated).
- Make `try_convex_hull` return an error instead of panicking if less than 3 input points are given.

## v0.16.1

Expand Down
2 changes: 1 addition & 1 deletion crates/parry3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ num-derive = "0.4"
indexmap = { version = "2", features = ["serde"], optional = true }
rustc-hash = { version = "2", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
spade = { version = "2.9", optional = true } # Make this optional?
rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
rstar = "0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ num-derive = "0.4"
indexmap = { version = "2", features = ["serde"], optional = true }
rustc-hash = { version = "2", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
spade = { version = "2.9", optional = true } # Make this optional?
rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
log = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions src/transformation/convex_hull3/convex_hull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn convex_hull(points: &[Point3<Real>]) -> (Vec<Point3<Real>>, Vec<[u32; 3]>
pub fn try_convex_hull(
points: &[Point3<Real>],
) -> Result<(Vec<Point3<Real>>, Vec<[u32; 3]>), ConvexHullError> {
if points.is_empty() {
return Ok((Vec::new(), Vec::new()));
if points.len() < 3 {
return Err(ConvexHullError::IncompleteInput);
}

// print_buildable_vec("input", points);
Expand Down
20 changes: 7 additions & 13 deletions src/transformation/convex_hull3/error.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
#[derive(Debug, PartialEq)]
#[derive(thiserror::Error, Debug, PartialEq)]
/// Errors generated by the convex-hull calculation.
pub enum ConvexHullError {
/// Reached an impossible configuration in the convex-hull calculation,
/// likely because of a bug.
#[error("Internal error: {0}")]
InternalError(&'static str),
/// The convex hull calculation was unable to find a support point.
/// This generally happens if the input point set contains invalid points (with NaN coordinates)
/// or if they are almost coplanar.
#[error("Input points are either invalid (NaN) or are almost coplanar.")]
MissingSupportPoint,
/// The convex-hull calculation failed because less than 3 points were provided.
#[error("Less than 3 points were given to the convex-hull algorithm.")]
IncompleteInput,
/// Reached a piece of code we shouldn’t (internal error).
#[error("Internal error: unreachable code path")]
Unreachable,
}

impl std::fmt::Display for ConvexHullError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ConvexHullError::InternalError(reason) => write!(f, "InternalError({})", reason),
ConvexHullError::MissingSupportPoint => write!(f, "MissingSupportPoint"),
ConvexHullError::Unreachable => write!(f, "Unreachable"),
}
}
}

impl std::error::Error for ConvexHullError {}