26
26
from numpy .linalg import det as ndet
27
27
from numpy .linalg import matrix_rank , norm , slogdet , solve
28
28
29
- SimplexPoints = Union [List [Tuple [float , ...]], ndarray ] # XXX: check if this is correct
30
- Simplex = Union [Tuple [numbers .Integral , ...], ndarray ]
31
- Point = Union [Tuple [float , ...], ndarray ] # XXX: check if this is correct
29
+ SimplexPoints = Union [List [Tuple [float , ...]], ndarray ]
30
+ Simplex = Union [Iterable [numbers .Integral ], ndarray ]
31
+ Point = Union [Tuple [float , ...], ndarray ]
32
+ Points = Union [Sequence [Point ], ndarray ]
32
33
33
34
34
35
def fast_norm (v : Union [Tuple [float , ...], ndarray ]) -> float :
@@ -78,7 +79,7 @@ def point_in_simplex(
78
79
return all (alpha > - eps ) and sum (alpha ) < 1 + eps
79
80
80
81
81
- def fast_2d_circumcircle (points : Sequence [ Point ] ) -> Tuple [Tuple [float , float ], float ]:
82
+ def fast_2d_circumcircle (points : Points ) -> Tuple [Tuple [float , float ], float ]:
82
83
"""Compute the center and radius of the circumscribed circle of a triangle
83
84
84
85
Parameters
@@ -115,7 +116,7 @@ def fast_2d_circumcircle(points: Sequence[Point]) -> Tuple[Tuple[float, float],
115
116
116
117
117
118
def fast_3d_circumcircle (
118
- points : Sequence [ Point ] ,
119
+ points : Points ,
119
120
) -> Tuple [Tuple [float , float , float ], float ]:
120
121
"""Compute the center and radius of the circumscribed sphere of a simplex.
121
122
@@ -215,7 +216,7 @@ def circumsphere(pts: ndarray) -> Tuple[Tuple[float, ...], float]:
215
216
return tuple (center ), radius
216
217
217
218
218
- def orientation (face : ndarray , origin : ndarray ) -> int :
219
+ def orientation (face : Union [ tuple , ndarray ] , origin : Union [ tuple , ndarray ] ) -> int :
219
220
"""Compute the orientation of the face with respect to a point, origin.
220
221
221
222
Parameters
@@ -238,7 +239,7 @@ def orientation(face: ndarray, origin: ndarray) -> int:
238
239
sign , logdet = slogdet (vectors - origin )
239
240
if logdet < - 50 : # assume it to be zero when it's close to zero
240
241
return 0
241
- return sign
242
+ return int ( sign )
242
243
243
244
244
245
def is_iterable_and_sized (obj : Any ) -> bool :
@@ -326,7 +327,7 @@ class Triangulation:
326
327
or more simplices in the
327
328
"""
328
329
329
- def __init__ (self , coords : Union [ Sequence [ Point ], ndarray ] ) -> None :
330
+ def __init__ (self , coords : Points ) -> None :
330
331
if not is_iterable_and_sized (coords ):
331
332
raise TypeError ("Please provide a 2-dimensional list of points" )
332
333
coords = list (coords )
@@ -378,7 +379,7 @@ def add_simplex(self, simplex: Simplex) -> None:
378
379
self .vertex_to_simplices [vertex ].add (simplex )
379
380
380
381
def get_vertices (
381
- self , indices : Sequence [numbers .Integral ]
382
+ self , indices : Iterable [numbers .Integral ]
382
383
) -> List [Optional [Point ]]:
383
384
return [self .get_vertex (i ) for i in indices ]
384
385
@@ -389,7 +390,7 @@ def get_vertex(self, index: Optional[numbers.Integral]) -> Optional[Point]:
389
390
390
391
def get_reduced_simplex (
391
392
self , point : Point , simplex : Simplex , eps : float = 1e-8
392
- ) -> list :
393
+ ) -> List [ numbers . Integral ] :
393
394
"""Check whether vertex lies within a simplex.
394
395
395
396
Returns
@@ -440,7 +441,7 @@ def faces(
440
441
dim : Optional [int ] = None ,
441
442
simplices : Optional [Iterable [Simplex ]] = None ,
442
443
vertices : Optional [Iterable [int ]] = None ,
443
- ) -> Iterator [Tuple [int , ...]]:
444
+ ) -> Iterator [Tuple [numbers . Integral , ...]]:
444
445
"""Iterator over faces of a simplex or vertex sequence."""
445
446
if dim is None :
446
447
dim = self .dim
@@ -525,7 +526,7 @@ def circumscribed_circle(
525
526
526
527
def point_in_cicumcircle (
527
528
self , pt_index : int , simplex : Simplex , transform : ndarray
528
- ) -> bool :
529
+ ) -> Union [ bool , np . bool_ ] :
529
530
# return self.fast_point_in_circumcircle(pt_index, simplex, transform)
530
531
eps = 1e-8
531
532
@@ -603,7 +604,7 @@ def bowyer_watson(
603
604
new_triangles = self .vertex_to_simplices [pt_index ]
604
605
return bad_triangles - new_triangles , new_triangles - bad_triangles
605
606
606
- def _simplex_is_almost_flat (self , simplex : Simplex ) -> bool :
607
+ def _simplex_is_almost_flat (self , simplex : Simplex ) -> Union [ bool , np . bool_ ] :
607
608
return self ._relative_volume (simplex ) < 1e-8
608
609
609
610
def _relative_volume (self , simplex : Simplex ) -> float :
@@ -728,7 +729,7 @@ def find_opposing_vertex(vertex: int):
728
729
return result
729
730
730
731
@property
731
- def hull (self ) -> Set [int ]:
732
+ def hull (self ) -> Set [numbers . Integral ]:
732
733
"""Compute hull from triangulation.
733
734
734
735
Parameters
0 commit comments