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]: