Skip to content

Commit 03fdecd

Browse files
committed
OpenSCAD's polygon() takes a convexity argument. Add that argument and a test for it to SP
1 parent cb5fbff commit 03fdecd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

solid/objects.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,20 @@ class polygon(OpenSCADObject):
3636
assumed in order. (The 'pN' components of the *paths* vector are 0-indexed
3737
references to the elements of the *points* vector.)
3838
39+
:param convexity: OpenSCAD's convexity... yadda yadda
40+
3941
NOTE: OpenSCAD accepts only 2D points for `polygon()`. Convert any 3D points
4042
to 2D before compiling
4143
"""
4244

43-
def __init__(self, points: Union[Points, IncludedOpenSCADObject], paths: Indexes = None) -> None:
45+
def __init__(self, points: Union[Points, IncludedOpenSCADObject], paths: Indexes = None, convexity: int = None) -> None:
4446
# Force points to 2D if they're defined in Python, pass through if they're
4547
# included OpenSCAD code
4648
pts = points # type: ignore
4749
if not isinstance(points, IncludedOpenSCADObject):
4850
pts = list([(p[0], p[1]) for p in points]) # type: ignore
4951

50-
args = {'points':pts}
52+
args = {'points':pts, 'convexity':convexity}
5153
# If not supplied, OpenSCAD assumes all points in order for paths
5254
if paths:
5355
args['paths'] = paths # type: ignore

solid/test/test_solidpython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
scad_test_case_templates = [
1919
{'name': 'polygon', 'class': 'polygon' , 'kwargs': {'paths': [[0, 1, 2]]}, 'expected': '\n\npolygon(paths = [[0, 1, 2]], points = [[0, 0], [1, 0], [0, 1]]);', 'args': {'points': [[0, 0, 0], [1, 0, 0], [0, 1, 0]]}, },
2020
{'name': 'polygon', 'class': 'polygon' , 'kwargs': {}, 'expected': '\n\npolygon(points = [[0, 0], [1, 0], [0, 1]]);', 'args': {'points': [[0, 0, 0], [1, 0, 0], [0, 1, 0]]}, },
21+
{'name': 'polygon', 'class': 'polygon' , 'kwargs': {}, 'expected': '\n\npolygon(convexity = 3, points = [[0, 0], [1, 0], [0, 1]]);', 'args': {'points': [[0, 0, 0], [1, 0, 0], [0, 1, 0]], 'convexity': 3}, },
2122
{'name': 'circle', 'class': 'circle' , 'kwargs': {'segments': 12, 'r': 1}, 'expected': '\n\ncircle($fn = 12, r = 1);', 'args': {}, },
2223
{'name': 'circle_diam', 'class': 'circle' , 'kwargs': {'segments': 12, 'd': 1}, 'expected': '\n\ncircle($fn = 12, d = 1);', 'args': {}, },
2324
{'name': 'square', 'class': 'square' , 'kwargs': {'center': False, 'size': 1}, 'expected': '\n\nsquare(center = false, size = 1);', 'args': {}, },

0 commit comments

Comments
 (0)