1- from __future__ import absolute_import
2- from __future__ import division
3- from __future__ import print_function
1+ from typing import Annotated
2+ from typing import Optional
43
5- from triangle import triangulate
6- from compas .utilities import pairwise
7- from compas .utilities import geometric_key_xy as geo
84from compas .geometry import centroid_points_xy
9-
5+ from compas . itertools import pairwise
106from compas .plugins import plugin
7+ from compas .tolerance import TOL
8+ from triangle import triangulate
9+
10+ geo = TOL .geometric_key_xy
11+
1112
13+ Point = Annotated [list [float ], 3 ]
14+ Polyline = list [Point ]
15+ Polygon = list [Point ]
16+ Segment = tuple [int , int ]
17+ Triangle = tuple [int , int , int ]
1218
13- def _to_vertices_segments_holes (boundary , polylines , polygons ):
19+
20+ def _to_vertices_segments_holes (
21+ boundary : list [Point ],
22+ polylines : list [Polyline ],
23+ polygons : list [Polygon ],
24+ ) -> tuple [list [Point ], list [Segment ], list [Point ]]:
1425 if geo (boundary [0 ]) != geo (boundary [- 1 ]):
1526 boundary .append (boundary [0 ])
1627
@@ -47,8 +58,8 @@ def _to_vertices_segments_holes(boundary, polylines, polygons):
4758 return vertices , segments , holes
4859
4960
50- @plugin (category = ' triangulation' )
51- def delaunay_triangulation (points ) :
61+ @plugin (category = " triangulation" )
62+ def delaunay_triangulation (points : list [ Point ]) -> tuple [ list [ Point ], list [ Triangle ]] :
5263 """Construct a Delaunay triangulation of set of vertices.
5364
5465 Parameters
@@ -62,24 +73,24 @@ def delaunay_triangulation(points):
6273 * The vertices of the triangulation.
6374 * The faces of the triangulation.
6475
65- Examples
66- --------
67- >>>
68-
6976 References
7077 ----------
7178 https://www.cs.cmu.edu/~quake/triangle.delaunay.html
7279
7380 """
74- data = {' vertices' : [point [0 :2 ] for point in points ]}
75- result = triangulate (data , opts = 'c' )
76- vertices = [[x , y , 0.0 ] for x , y in result [' vertices' ]]
77- faces = result [' triangles' ]
81+ data = {" vertices" : [point [0 :2 ] for point in points ]}
82+ result = triangulate (data , opts = "c" )
83+ vertices = [[x , y , 0.0 ] for x , y in result [" vertices" ]]
84+ faces = result [" triangles" ]
7885 return vertices , faces
7986
8087
81- @plugin (category = 'triangulation' )
82- def constrained_delaunay_triangulation (boundary , polylines = None , polygons = None ):
88+ @plugin (category = "triangulation" )
89+ def constrained_delaunay_triangulation (
90+ boundary : list [Point ],
91+ polylines : Optional [list [Polyline ]] = None ,
92+ polygons : Optional [list [Polygon ]] = None ,
93+ ) -> tuple [list [Point ], list [Triangle ]]:
8394 """Construct a Delaunay triangulation of set of vertices, constrained to the specified segments.
8495
8596 Parameters
@@ -101,31 +112,33 @@ def constrained_delaunay_triangulation(boundary, polylines=None, polygons=None):
101112 -----
102113 No additional points will be inserted in the triangulation.
103114
104- Examples
105- --------
106- >>>
107-
108115 References
109116 ----------
110117 https://www.cs.cmu.edu/~quake/triangle.delaunay.html
111118
112119 """
113120 vertices , segments , holes = _to_vertices_segments_holes (boundary , polylines , polygons )
114121
115- data = {' vertices' : vertices , ' segments' : segments }
122+ data = {" vertices" : vertices , " segments" : segments }
116123
117124 if len (holes ) > 0 :
118- data [' holes' ] = holes
125+ data [" holes" ] = holes
119126
120- result = triangulate (data , opts = 'p' )
127+ result = triangulate (data , opts = "p" )
121128
122- vertices = [[x , y , 0.0 ] for x , y in result [' vertices' ]]
123- faces = result [' triangles' ]
129+ vertices = [[x , y , 0.0 ] for x , y in result [" vertices" ]]
130+ faces = result [" triangles" ]
124131 return vertices , faces
125132
126133
127- @plugin (category = 'triangulation' )
128- def conforming_delaunay_triangulation (boundary , polylines = None , polygons = None , angle = None , area = None ):
134+ @plugin (category = "triangulation" )
135+ def conforming_delaunay_triangulation (
136+ boundary : list [Point ],
137+ polylines : Optional [list [Polyline ]] = None ,
138+ polygons : Optional [list [Polygon ]] = None ,
139+ angle : Optional [float ] = None ,
140+ area : Optional [float ] = None ,
141+ ) -> tuple [list [Point ], list [Triangle ]]:
129142 """Construct a Conforming Delaunay triangulation of set of vertices, constrained to the specified segments.
130143
131144 Parameters
@@ -152,35 +165,31 @@ def conforming_delaunay_triangulation(boundary, polylines=None, polygons=None, a
152165 * The vertices of the triangulation.
153166 * The faces of the triangulation.
154167
155- Examples
156- --------
157- >>>
158-
159168 References
160169 ----------
161170 https://www.cs.cmu.edu/~quake/triangle.delaunay.html
162171
163172 """
164173 vertices , segments , holes = _to_vertices_segments_holes (boundary , polylines , polygons )
165174
166- data = {' vertices' : vertices , ' segments' : segments }
175+ data = {" vertices" : vertices , " segments" : segments }
167176
168177 if len (holes ) > 0 :
169- data [' holes' ] = holes
178+ data [" holes" ] = holes
170179
171- opts = 'pq'
180+ opts = "pq"
172181
173182 if angle :
174- opts = ' {}{}' .format (opts , angle )
183+ opts = " {}{}" .format (opts , angle )
175184
176185 if area :
177- opts = ' {}a{}' .format (opts , area )
186+ opts = " {}a{}" .format (opts , area )
178187
179- if opts == 'pq' :
180- opts = ' pq0D'
188+ if opts == "pq" :
189+ opts = " pq0D"
181190
182191 result = triangulate (data , opts = opts )
183192
184- vertices = [[x , y , 0.0 ] for x , y in result [' vertices' ]]
185- faces = result [' triangles' ]
193+ vertices = [[x , y , 0.0 ] for x , y in result [" vertices" ]]
194+ faces = result [" triangles" ]
186195 return vertices , faces
0 commit comments