[remove_duplicate_vertices] improve handling of degenerate shapes

This commit is contained in:
jan 2026-03-08 10:24:25 -07:00
commit 19dafad157

View file

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