@@ -48,8 +48,8 @@ def graph_from_skeleton_data(points: VerticesNumpy, indices: IntNx1, edges: IntN
4848 return graph
4949
5050
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.
5353
5454 Parameters
5555 ----------
@@ -66,7 +66,7 @@ def create_interior_straight_skeleton(points, as_graph=True) -> Union[Graph, Tup
6666 Raises
6767 ------
6868 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].
7070 """
7171 points = list (points )
7272 normal = normal_polygon (points , True )
@@ -79,13 +79,13 @@ def create_interior_straight_skeleton(points, as_graph=True) -> Union[Graph, Tup
7979 return points , indices , edges , edge_types
8080
8181
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.
8484
8585 Parameters
8686 ----------
8787 points : list of point coordinates or :class:`compas.geometry.Polygon`
88- The points of the polygon.
88+ The points of the 2D polygon.
8989 holes : list of list of point coordinates or list of :class:`compas.geometry.Polygon`
9090 The holes of the polygon.
9191 as_graph : bool, optional
@@ -99,8 +99,8 @@ def create_interior_straight_skeleton_with_holes(points, holes, as_graph=True) -
9999 Raises
100100 ------
101101 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].
104104 """
105105 points = list (points )
106106 normal = normal_polygon (points , True )
@@ -122,13 +122,13 @@ def create_interior_straight_skeleton_with_holes(points, holes, as_graph=True) -
122122 return points , indices , edges , edge_types
123123
124124
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 .
127127
128128 Parameters
129129 ----------
130130 points : list of point coordinates or :class:`compas.geometry.Polygon`
131- The points of the polygon.
131+ The points of the 2D polygon.
132132 offset : float
133133 The offset distance. If negative, the offset is outside the polygon, otherwise inside.
134134
@@ -140,7 +140,7 @@ def create_offset_polygons_2(points, offset) -> list[Polygon]:
140140 Raises
141141 ------
142142 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].
144144 """
145145 points = list (points )
146146 normal = normal_polygon (points , True )
@@ -155,13 +155,66 @@ def create_offset_polygons_2(points, offset) -> list[Polygon]:
155155 return [Polygon (points .tolist ()) for points in offset_polygons ]
156156
157157
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 .
160160
161161 Parameters
162162 ----------
163163 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.
165218 offset : float
166219 The offset distance. If negative, the offset is outside the polygon, otherwise inside.
167220 weights : list of float
@@ -175,7 +228,7 @@ def create_weighted_offset_polygons_2(points, offset, weights) -> list[Polygon]:
175228 Raises
176229 ------
177230 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].
179232 ValueError
180233 If the number of weights does not match the number of points.
181234 """
0 commit comments