@@ -20,6 +20,7 @@ def __init__(self, points):
2020 non-numeric, or wrong shape.
2121 """
2222 from cgeom .elements .models import DelaunayTriangulationInput
23+
2324 validated = DelaunayTriangulationInput (points = points )
2425 self .points = np .array (validated .points )
2526 self ._triangles = None
@@ -50,11 +51,13 @@ def triangulate(self):
5051 margin = 20.0
5152
5253 # Super-triangle vertices stored at indices n, n+1, n+2
53- super_pts = np .array ([
54- [mid_x - margin * delta , mid_y - delta ],
55- [mid_x + margin * delta , mid_y - delta ],
56- [mid_x , mid_y + margin * delta ],
57- ])
54+ super_pts = np .array (
55+ [
56+ [mid_x - margin * delta , mid_y - delta ],
57+ [mid_x + margin * delta , mid_y - delta ],
58+ [mid_x , mid_y + margin * delta ],
59+ ]
60+ )
5861 all_pts = np .vstack ([pts , super_pts ])
5962
6063 # Each triangle is a frozenset of 3 indices
@@ -65,7 +68,9 @@ def triangulate(self):
6568 bad = set ()
6669 for tri in triangles :
6770 a , b , c = tri
68- if self ._in_circumcircle (all_pts [i ], all_pts [a ], all_pts [b ], all_pts [c ]):
71+ if self ._in_circumcircle (
72+ all_pts [i ], all_pts [a ], all_pts [b ], all_pts [c ]
73+ ):
6974 bad .add (tri )
7075
7176 # Find boundary polygon: edges belonging to exactly one bad triangle
@@ -118,8 +123,9 @@ def get_edges(self):
118123 key = (min (edge ), max (edge ))
119124 if key not in seen :
120125 seen .add (key )
121- edges .append ([self .points [key [0 ]].tolist (),
122- self .points [key [1 ]].tolist ()])
126+ edges .append (
127+ [self .points [key [0 ]].tolist (), self .points [key [1 ]].tolist ()]
128+ )
123129 return edges
124130
125131 def get_circumcircles (self ):
@@ -140,13 +146,15 @@ def get_circumcircles(self):
140146 def plot (self , title = "Delaunay Triangulation" ):
141147 """Deprecated: use cgeom.visualization.plot_delaunay() instead."""
142148 import warnings
149+
143150 warnings .warn (
144151 "DelaunayTriangulation.plot() is deprecated. "
145152 "Use cgeom.visualization.plot_delaunay(dt_obj, title) instead." ,
146153 DeprecationWarning ,
147154 stacklevel = 2 ,
148155 )
149156 from cgeom .visualization import plot_delaunay
157+
150158 plot_delaunay (self , title )
151159
152160 @staticmethod
@@ -161,12 +169,16 @@ def _circumcircle(a, b, c):
161169 cx , cy = float (c [0 ]), float (c [1 ])
162170
163171 D = 2.0 * (ax * (by - cy ) + bx * (cy - ay ) + cx * (ay - by ))
164- ux = ((ax * ax + ay * ay ) * (by - cy )
165- + (bx * bx + by * by ) * (cy - ay )
166- + (cx * cx + cy * cy ) * (ay - by )) / D
167- uy = ((ax * ax + ay * ay ) * (cx - bx )
168- + (bx * bx + by * by ) * (ax - cx )
169- + (cx * cx + cy * cy ) * (bx - ax )) / D
172+ ux = (
173+ (ax * ax + ay * ay ) * (by - cy )
174+ + (bx * bx + by * by ) * (cy - ay )
175+ + (cx * cx + cy * cy ) * (ay - by )
176+ ) / D
177+ uy = (
178+ (ax * ax + ay * ay ) * (cx - bx )
179+ + (bx * bx + by * by ) * (ax - cx )
180+ + (cx * cx + cy * cy ) * (bx - ax )
181+ ) / D
170182 r = np .sqrt ((ax - ux ) ** 2 + (ay - uy ) ** 2 )
171183 return ux , uy , r
172184
@@ -181,14 +193,17 @@ def _in_circumcircle(p, a, b, c):
181193 bx , by = float (b [0 ]) - float (p [0 ]), float (b [1 ]) - float (p [1 ])
182194 cx , cy = float (c [0 ]) - float (p [0 ]), float (c [1 ]) - float (p [1 ])
183195
184- det = (ax * ax + ay * ay ) * (bx * cy - cx * by ) \
185- - (bx * bx + by * by ) * (ax * cy - cx * ay ) \
196+ det = (
197+ (ax * ax + ay * ay ) * (bx * cy - cx * by )
198+ - (bx * bx + by * by ) * (ax * cy - cx * ay )
186199 + (cx * cx + cy * cy ) * (ax * by - bx * ay )
200+ )
187201
188202 # The sign of det depends on triangle orientation (CCW vs CW).
189203 # Compute orientation and flip if clockwise.
190- orient = (float (b [0 ]) - float (a [0 ])) * (float (c [1 ]) - float (a [1 ])) \
191- - (float (b [1 ]) - float (a [1 ])) * (float (c [0 ]) - float (a [0 ]))
204+ orient = (float (b [0 ]) - float (a [0 ])) * (float (c [1 ]) - float (a [1 ])) - (
205+ float (b [1 ]) - float (a [1 ])
206+ ) * (float (c [0 ]) - float (a [0 ]))
192207 if orient < 0 :
193208 det = - det
194209
0 commit comments