From 61c8ee7cb8e68d77a6e57e8cd01d43e51c099977 Mon Sep 17 00:00:00 2001 From: Okko Hakola Date: Fri, 13 Oct 2023 10:52:41 +0300 Subject: [PATCH] Ensure points passed to convex polygon aren't empty --- src/shape/convex_polygon.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shape/convex_polygon.rs b/src/shape/convex_polygon.rs index 9ab6a61b..5d9012d7 100644 --- a/src/shape/convex_polygon.rs +++ b/src/shape/convex_polygon.rs @@ -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>) -> Option { + if points.is_empty() { + return None; + } let eps = ComplexField::sqrt(crate::math::DEFAULT_EPSILON); let mut normals = Vec::with_capacity(points.len()); // First, compute all normals.