From 19dafad15779c85fd6c96f0a4ae0aa00b07b73cc Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 8 Mar 2026 10:24:25 -0700 Subject: [PATCH] [remove_duplicate_vertices] improve handling of degenerate shapes --- masque/utils/vertices.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/masque/utils/vertices.py b/masque/utils/vertices.py index c4a7cb6..176f0f5 100644 --- a/masque/utils/vertices.py +++ b/masque/utils/vertices.py @@ -18,10 +18,16 @@ def remove_duplicate_vertices(vertices: ArrayLike, closed_path: bool = True) -> `vertices` with no consecutive duplicates. This may be a view into the original array. """ vertices = numpy.asarray(vertices) + if vertices.shape[0] <= 1: + return vertices duplicates = (vertices == numpy.roll(vertices, -1, axis=0)).all(axis=1) if not closed_path: duplicates[-1] = False - return vertices[~duplicates] + + result = vertices[~duplicates] + if result.shape[0] == 0 and vertices.shape[0] > 0: + return vertices[:1] + return result def remove_colinear_vertices(vertices: ArrayLike, closed_path: bool = True) -> NDArray[numpy.float64]: