@@ -48,8 +48,8 @@ def graph_from_skeleton_data(points: VerticesNumpy, indices: IntNx1, edges: IntN
48
48
return graph
49
49
50
50
51
- def create_interior_straight_skeleton (points , as_graph = True ) -> Union [Graph , Tuple [VerticesNumpy , IntNx1 , IntNx2 , IntNx1 ]]:
52
- """Compute the skeleton of a polygon.
51
+ def interior_straight_skeleton (points , as_graph = True ) -> Union [Graph , Tuple [VerticesNumpy , IntNx1 , IntNx2 , IntNx1 ]]:
52
+ """Compute the skeleton of a 2D polygon.
53
53
54
54
Parameters
55
55
----------
@@ -66,7 +66,7 @@ def create_interior_straight_skeleton(points, as_graph=True) -> Union[Graph, Tup
66
66
Raises
67
67
------
68
68
ValueError
69
- If the normal of the polygon is not [0, 0, 1].
69
+ If the normal of the polygon is not directed vertically upwards like [0, 0, 1].
70
70
"""
71
71
points = list (points )
72
72
normal = normal_polygon (points , True )
@@ -79,13 +79,13 @@ def create_interior_straight_skeleton(points, as_graph=True) -> Union[Graph, Tup
79
79
return points , indices , edges , edge_types
80
80
81
81
82
- def create_interior_straight_skeleton_with_holes (points , holes , as_graph = True ) -> Union [Graph , Tuple [VerticesNumpy , IntNx1 , IntNx2 , IntNx1 ]]:
83
- """Compute the skeleton of a polygon with holes.
82
+ def interior_straight_skeleton_with_holes (points , holes , as_graph = True ) -> Union [Graph , Tuple [VerticesNumpy , IntNx1 , IntNx2 , IntNx1 ]]:
83
+ """Compute the skeleton of a 2D polygon with holes.
84
84
85
85
Parameters
86
86
----------
87
87
points : list of point coordinates or :class:`compas.geometry.Polygon`
88
- The points of the polygon.
88
+ The points of the 2D polygon.
89
89
holes : list of list of point coordinates or list of :class:`compas.geometry.Polygon`
90
90
The holes of the polygon.
91
91
as_graph : bool, optional
@@ -99,8 +99,8 @@ def create_interior_straight_skeleton_with_holes(points, holes, as_graph=True) -
99
99
Raises
100
100
------
101
101
ValueError
102
- If the normal of the polygon is not [0, 0, 1].
103
- If the normal of a hole is not [0, 0, -1].
102
+ If the normal of the polygon is not directed vertically upwards like [0, 0, 1].
103
+ If the normal of a hole is not directed vertically downwards like [0, 0, -1].
104
104
"""
105
105
points = list (points )
106
106
normal = normal_polygon (points , True )
@@ -122,13 +122,13 @@ def create_interior_straight_skeleton_with_holes(points, holes, as_graph=True) -
122
122
return points , indices , edges , edge_types
123
123
124
124
125
- def create_offset_polygons_2 (points , offset ) -> list [Polygon ]:
126
- """Compute the polygon offset.
125
+ def offset_polygon (points , offset ) -> list [Polygon ]:
126
+ """Compute the offset from a 2D polygon .
127
127
128
128
Parameters
129
129
----------
130
130
points : list of point coordinates or :class:`compas.geometry.Polygon`
131
- The points of the polygon.
131
+ The points of the 2D polygon.
132
132
offset : float
133
133
The offset distance. If negative, the offset is outside the polygon, otherwise inside.
134
134
@@ -140,7 +140,7 @@ def create_offset_polygons_2(points, offset) -> list[Polygon]:
140
140
Raises
141
141
------
142
142
ValueError
143
- If the normal of the polygon is not [0, 0, 1].
143
+ If the normal of the polygon is not directed vertically upwards like [0, 0, 1].
144
144
"""
145
145
points = list (points )
146
146
normal = normal_polygon (points , True )
@@ -155,13 +155,66 @@ def create_offset_polygons_2(points, offset) -> list[Polygon]:
155
155
return [Polygon (points .tolist ()) for points in offset_polygons ]
156
156
157
157
158
- def create_weighted_offset_polygons_2 (points , offset , weights ) -> list [Polygon ]:
159
- """Compute the polygon offset with weights .
158
+ def offset_polygon_with_holes (points , holes , offset ) -> list [Tuple [ Polygon , list [ Polygon ]] ]:
159
+ """Compute the offset from a 2D polygon with holes .
160
160
161
161
Parameters
162
162
----------
163
163
points : list of point coordinates or :class:`compas.geometry.Polygon`
164
- The points of the polygon.
164
+ The points of the 2D polygon.
165
+ holes : list of list of point coordinates or list of :class:`compas.geometry.Polygon`
166
+ The holes of the polygon.
167
+ offset : float
168
+ The offset distance. If negative, the offset is outside the polygon, otherwise inside.
169
+
170
+ Returns
171
+ -------
172
+ list of tuple of (:class:`Polygon`, list[:class:`Polygon`])
173
+ The polygons with holes.
174
+
175
+ Raises
176
+ ------
177
+ ValueError
178
+ If the normal of the polygon is not directed vertically upwards like [0, 0, 1].
179
+ If the normal of a hole is not directed vertically downwards like [0, 0, -1].
180
+ """
181
+ points = list (points )
182
+ normal = normal_polygon (points , True )
183
+ if not TOL .is_allclose (normal , [0 , 0 , 1 ]):
184
+ raise ValueError ("The normal of the polygon should be [0, 0, 1]. The normal of the provided polygon is {}" .format (normal ))
185
+ V = np .asarray (points , dtype = np .float64 )
186
+
187
+ H = []
188
+ for i , hole in enumerate (holes ):
189
+ points = hole
190
+ normal_hole = normal_polygon (points , True )
191
+ if not TOL .is_allclose (normal_hole , [0 , 0 , - 1 ]):
192
+ raise ValueError ("The normal of the hole should be [0, 0, -1]. The normal of the provided {}-th hole is {}" .format (i , normal_hole ))
193
+ hole = np .asarray (points , dtype = np .float64 )
194
+ H .append (hole )
195
+
196
+ if offset < 0 : # outside
197
+ offset_polygons = straight_skeleton_2 .create_offset_polygons_2_outer_with_holes (V , H , abs (offset ))
198
+ else : # inside
199
+ offset_polygons = straight_skeleton_2 .create_offset_polygons_2_inner_with_holes (V , H , offset )
200
+
201
+ result = []
202
+ for points , holes_np in offset_polygons :
203
+ polygon = Polygon (points .tolist ())
204
+ holes = []
205
+ for hole in holes_np :
206
+ holes .append (Polygon (hole .tolist ()))
207
+ result .append ((polygon , holes ))
208
+ return result
209
+
210
+
211
+ def weighted_offset_polygon (points , offset , weights ) -> list [Polygon ]:
212
+ """Compute the offset from a 2D polygon with weights.
213
+
214
+ Parameters
215
+ ----------
216
+ points : list of point coordinates or :class:`compas.geometry.Polygon`
217
+ The points of the 2D polygon.
165
218
offset : float
166
219
The offset distance. If negative, the offset is outside the polygon, otherwise inside.
167
220
weights : list of float
@@ -175,7 +228,7 @@ def create_weighted_offset_polygons_2(points, offset, weights) -> list[Polygon]:
175
228
Raises
176
229
------
177
230
ValueError
178
- If the normal of the polygon is not [0, 0, 1].
231
+ If the normal of the polygon is not directed vertically upwards like [0, 0, 1].
179
232
ValueError
180
233
If the number of weights does not match the number of points.
181
234
"""
0 commit comments