Skip to content

Commit

Permalink
Fix bug where Triangle segfault with duplicate points
Browse files Browse the repository at this point in the history
A bit slower but it's now fixed, doesn't crash but doesn't necessarily
returns a valid triangulation, but then it's faulty input so little we
can do
  • Loading branch information
hugoledoux committed Mar 9, 2022
1 parent e9727ad commit 138a25f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions cjio/geom_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,22 @@ def get_normal_newell(poly):

##-- with Shewchuk Triangle library
def triangulate_face(face, vnp):
#-- if a triangle then do nothing
if ( (len(face) == 1) and (len(face[0]) == 3) ):
return (np.array(face), True)
#-- remove duplicate vertices, which can *easily* make Triangle segfault
for i,each in enumerate(face):
if len(set(each)) < len(each): #-- there are duplicates
re = []
for k in each:
if re.count(k) == 0:
re.append(k)
face[i] = re

if ( (len(face) == 1) and (len(face[0]) <= 3) ):
if len(face[0]) == 3:
#-- if a triangle then do nothing
return (np.array(face), True)
else:
#-- if collapsed then ignore and return false
return (np.array(face), False)
sf = np.array([], dtype=np.int64)
for ring in face:
sf = np.hstack( (sf, np.array(ring)) )
Expand Down

0 comments on commit 138a25f

Please sign in to comment.