[remove_duplicate_vertices] improve handling of degenerate shapes
This commit is contained in:
parent
5cb608734d
commit
19dafad157
1 changed files with 7 additions and 1 deletions
|
|
@ -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` with no consecutive duplicates. This may be a view into the original array.
|
||||||
"""
|
"""
|
||||||
vertices = numpy.asarray(vertices)
|
vertices = numpy.asarray(vertices)
|
||||||
|
if vertices.shape[0] <= 1:
|
||||||
|
return vertices
|
||||||
duplicates = (vertices == numpy.roll(vertices, -1, axis=0)).all(axis=1)
|
duplicates = (vertices == numpy.roll(vertices, -1, axis=0)).all(axis=1)
|
||||||
if not closed_path:
|
if not closed_path:
|
||||||
duplicates[-1] = False
|
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]:
|
def remove_colinear_vertices(vertices: ArrayLike, closed_path: bool = True) -> NDArray[numpy.float64]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue