Skip to content

Commit

Permalink
fix(face): Add a method to remove duplicate vertices
Browse files Browse the repository at this point in the history
I have found there were several cases where I really only want to remove duplicate vertices and not colinear ones. This will assist in this case.
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jun 5, 2023
1 parent fdb4bb3 commit 9b032b9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ladybug_geometry/geometry3d/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,29 @@ def check_planar(self, tolerance, raise_exception=True):
return False
return True

def remove_duplicate_vertices(self, tolerance):
"""Get a version of this face without duplicate vertices.
Args:
tolerance: The minimum distance between a two vertices at which
they are considered co-located or duplicated.
"""
if not self.has_holes: # we only need to evaluate one list of vertices
new_vertices = tuple(
pt for i, pt in enumerate(self._vertices)
if not pt.is_equivalent(self._vertices[i - 1], tolerance))
_new_face = Face3D(new_vertices, self.plane, enforce_right_hand=False)
return _new_face
# the face has holes
_boundary = tuple(
pt for i, pt in enumerate(self._boundary)
if not pt.is_equivalent(self._boundary[i - 1], tolerance))
_holes = tuple(
tuple(p for i, p in enumerate(h) if not p.is_equivalent(h[i - 1], tolerance))
for j, h in enumerate(self._holes))
_new_face = Face3D(_boundary, self.plane, _holes, enforce_right_hand=False)
return _new_face

def remove_colinear_vertices(self, tolerance):
"""Get a version of this face without colinear or duplicate vertices.
Expand Down

0 comments on commit 9b032b9

Please sign in to comment.