11import collections .abc
2+ import numbers
23from collections import Counter
34from itertools import chain , combinations
45from math import factorial , sqrt
56from typing import Any , Iterable , Iterator , List , Optional , Sequence , Set , Tuple , Union
67
8+ import numpy as np
79import scipy .spatial
810from numpy import abs as np_abs
911from numpy import (
2527from numpy .linalg import matrix_rank , norm , slogdet , solve
2628
2729SimplexPoints = Union [List [Tuple [float , ...]], ndarray ] # XXX: check if this is correct
28- Simplex = Tuple [int , ...]
30+ Simplex = Union [ Tuple [numbers . Integral , ...], ndarray ]
2931Point = Union [Tuple [float , ...], ndarray ] # XXX: check if this is correct
3032
3133
@@ -49,7 +51,7 @@ def fast_norm(v: Union[Tuple[float, ...], ndarray]) -> float:
4951
5052def fast_2d_point_in_simplex (
5153 point : Point , simplex : SimplexPoints , eps : float = 1e-8
52- ) -> bool :
54+ ) -> Union [ np . bool_ , bool ] :
5355 (p0x , p0y ), (p1x , p1y ), (p2x , p2y ) = simplex
5456 px , py = point
5557
@@ -63,7 +65,9 @@ def fast_2d_point_in_simplex(
6365 return (t >= - eps ) and (s + t <= 1 + eps )
6466
6567
66- def point_in_simplex (point : Point , simplex : SimplexPoints , eps : float = 1e-8 ) -> bool :
68+ def point_in_simplex (
69+ point : Point , simplex : SimplexPoints , eps : float = 1e-8
70+ ) -> Union [np .bool_ , bool ]:
6771 if len (point ) == 2 :
6872 return fast_2d_point_in_simplex (point , simplex , eps )
6973
@@ -322,7 +326,7 @@ class Triangulation:
322326 or more simplices in the
323327 """
324328
325- def __init__ (self , coords : Sequence [Point ]) -> None :
329+ def __init__ (self , coords : Union [ Sequence [Point ], ndarray ]) -> None :
326330 if not is_iterable_and_sized (coords ):
327331 raise TypeError ("Please provide a 2-dimensional list of points" )
328332 coords = list (coords )
@@ -373,10 +377,12 @@ def add_simplex(self, simplex: Simplex) -> None:
373377 for vertex in simplex :
374378 self .vertex_to_simplices [vertex ].add (simplex )
375379
376- def get_vertices (self , indices : Sequence [int ]) -> List [Optional [Point ]]:
380+ def get_vertices (
381+ self , indices : Sequence [numbers .Integral ]
382+ ) -> List [Optional [Point ]]:
377383 return [self .get_vertex (i ) for i in indices ]
378384
379- def get_vertex (self , index : Optional [int ]) -> Optional [Point ]:
385+ def get_vertex (self , index : Optional [numbers . Integral ]) -> Optional [Point ]:
380386 if index is None :
381387 return None
382388 return self .vertices [index ]
@@ -410,7 +416,7 @@ def get_reduced_simplex(
410416
411417 def point_in_simplex (
412418 self , point : Point , simplex : Simplex , eps : float = 1e-8
413- ) -> bool :
419+ ) -> Union [ np . bool_ , bool ] :
414420 vertices = self .get_vertices (simplex )
415421 return point_in_simplex (point , vertices , eps )
416422
@@ -616,7 +622,7 @@ def add_point(
616622 point : Point ,
617623 simplex : Optional [Simplex ] = None ,
618624 transform : Optional [ndarray ] = None ,
619- ) -> Any :
625+ ) -> Tuple [ Set [ Simplex ], Set [ Simplex ]] :
620626 """Add a new vertex and create simplices as appropriate.
621627
622628 Parameters
0 commit comments