@@ -409,8 +409,10 @@ def _extend_hull(self, new_vertex, eps=1e-8):
409409 if orientation_inside == - orientation_new_point :
410410 # if the orientation of the new vertex is zero or directed
411411 # towards the center, do not add the simplex
412- self .add_simplex ((* face , pt_index ))
413- new_simplices .add ((* face , pt_index ))
412+ simplex = (* face , pt_index )
413+ if not self ._simplex_is_almost_flat (simplex ):
414+ self .add_simplex (simplex )
415+ new_simplices .add (simplex )
414416
415417 if len (new_simplices ) == 0 :
416418 # We tried to add an internal point, revert and raise.
@@ -510,13 +512,27 @@ def bowyer_watson(self, pt_index, containing_simplex=None, transform=None):
510512
511513 for face in hole_faces :
512514 if pt_index not in face :
513- if self . volume (( * face , pt_index )) < 1e-8 :
514- continue
515- self .add_simplex (( * face , pt_index ) )
515+ simplex = ( * face , pt_index )
516+ if not self . _simplex_is_almost_flat ( simplex ):
517+ self .add_simplex (simplex )
516518
517519 new_triangles = self .vertex_to_simplices [pt_index ]
518520 return bad_triangles - new_triangles , new_triangles - bad_triangles
519521
522+ def _simplex_is_almost_flat (self , simplex ):
523+ return self ._relative_volume (simplex ) < 1e-8
524+
525+ def _relative_volume (self , simplex ):
526+ """Compute the volume of a simplex divided by the average (Manhattan)
527+ distance of its vertices. The advantage of this is that the relative
528+ volume is only dependent on the shape of the simplex and not on the
529+ absolute size. Due to the weird scaling, the only use of this method
530+ is to check that a simplex is almost flat."""
531+ vertices = np .array (self .get_vertices (simplex ))
532+ vectors = vertices [1 :] - vertices [0 ]
533+ average_edge_length = np .mean (np .abs (vectors ))
534+ return self .volume (simplex ) / (average_edge_length ** self .dim )
535+
520536 def add_point (self , point , simplex = None , transform = None ):
521537 """Add a new vertex and create simplices as appropriate.
522538
0 commit comments