Skip to content

Commit

Permalink
Fix convex hull crash
Browse files Browse the repository at this point in the history
By applying dimforge#168 .
  • Loading branch information
caspark committed Feb 1, 2024
1 parent e57762f commit 7b6fa38
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/shape/convex_polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ impl ConvexPolygon {
/// Convexity of the input polyline is not checked.
/// Returns `None` if all points form an almost flat line.
pub fn from_convex_polyline(mut points: Vec<Point<Real>>) -> Option<Self> {
if points.is_empty() {
return None;
}
let eps = ComplexField::sqrt(crate::math::DEFAULT_EPSILON);
let mut normals = Vec::with_capacity(points.len());

Expand Down Expand Up @@ -64,7 +67,7 @@ impl ConvexPolygon {
points.truncate(new_length);
normals.truncate(new_length);

if points.len() != 0 {
if points.len() > 2 {
Some(ConvexPolygon { points, normals })
} else {
None
Expand Down

0 comments on commit 7b6fa38

Please sign in to comment.