-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added function create_offset_polygons_with_holes_2
#35
Changes from 1 commit
418b4c2
8f6dd73
161a127
de8da47
33787d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,63 @@ def create_offset_polygons_2(points, offset) -> list[Polygon]: | |
return [Polygon(points.tolist()) for points in offset_polygons] | ||
|
||
|
||
def create_offset_polygons_with_holes_2(points, holes, offset) -> list[Tuple[Polygon, list[Polygon]]]: | ||
"""Compute the polygon offset with holes. | ||
|
||
Parameters | ||
---------- | ||
points : list of point coordinates or :class:`compas.geometry.Polygon` | ||
The points of the polygon. | ||
holes : list of list of point coordinates or list of :class:`compas.geometry.Polygon` | ||
The holes of the polygon. | ||
offset : float | ||
The offset distance. If negative, the offset is outside the polygon, otherwise inside. | ||
|
||
Returns | ||
------- | ||
tomvanmele marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Returns | ||
------- | ||
list of tuple of (:class:`Polygon`, list[:class:`Polygon`]) | ||
The polygons with holes. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
If the normal of the polygon is not [0, 0, 1]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be a unit normal, or vertical up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be vertical up, i've adjusted the docstrings |
||
If the normal of a hole is not [0, 0, -1]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be a unit normal, or vertical down? |
||
""" | ||
points = list(points) | ||
normal = normal_polygon(points, True) | ||
if not TOL.is_allclose(normal, [0, 0, 1]): | ||
raise ValueError("The normal of the polygon should be [0, 0, 1]. The normal of the provided polygon is {}".format(normal)) | ||
V = np.asarray(points, dtype=np.float64) | ||
|
||
H = [] | ||
for i, hole in enumerate(holes): | ||
points = list(hole) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the conversion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, not needed |
||
normal_hole = normal_polygon(points, True) | ||
if not TOL.is_allclose(normal_hole, [0, 0, -1]): | ||
raise ValueError("The normal of the hole should be [0, 0, -1]. The normal of the provided {}-th hole is {}".format(i, normal_hole)) | ||
hole = np.asarray(points, dtype=np.float64) | ||
H.append(hole) | ||
|
||
offset = float(offset) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the conversion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in any case, would do this at the beginning of the algorithm. process all input params (if necessary) at the start... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right, it is not needed |
||
if offset < 0: # outside | ||
offset_polygons = straight_skeleton_2.create_offset_polygons_2_outer_with_holes(V, H, abs(offset)) | ||
else: # inside | ||
offset_polygons = straight_skeleton_2.create_offset_polygons_2_inner_with_holes(V, H, offset) | ||
tomvanmele marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = [] | ||
for points, holes_np in offset_polygons: | ||
polygon = Polygon(points.tolist()) | ||
holes = [] | ||
for hole in holes_np: | ||
holes.append(Polygon(hole.tolist())) | ||
result.append((polygon, holes)) | ||
return result | ||
|
||
|
||
def create_weighted_offset_polygons_2(points, offset, weights) -> list[Polygon]: | ||
"""Compute the polygon offset with weights. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should have asked this before, but i guess
_2
means "2D"? perhaps this should be mentioned in the docstrings...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, i've added it to the docstrings. I've use "_2" as the cgal functions are named like that as well