Skip to content

Commit 126a072

Browse files
-- polygon() doesn't supply paths argument by default; OpenSCAD takes care of this manually
-- polygon() allows points to be passed in as an IncludedSCADObject
1 parent 2e2cde2 commit 126a072

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

solid/objects.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from types import SimpleNamespace
66
from typing import Dict, Optional, Sequence, Tuple, Union, List
77

8-
from .solidpython import OpenSCADObject
8+
from .solidpython import IncludedOpenSCADObject, OpenSCADObject
99

1010
PathStr = Union[Path, str]
1111

@@ -22,10 +22,6 @@
2222
ScadSize = Union[int, Sequence[float]]
2323
OpenSCADObjectPlus = Union[OpenSCADObject, Sequence[OpenSCADObject]]
2424

25-
def _to_point2s(points:Points) -> List[P2]:
26-
return list([(p[0], p[1]) for p in points])
27-
28-
2925
class polygon(OpenSCADObject):
3026
"""
3127
Create a polygon with the specified points and paths.
@@ -44,11 +40,18 @@ class polygon(OpenSCADObject):
4440
to 2D before compiling
4541
"""
4642

47-
def __init__(self, points: Points, paths: Indexes = None) -> None:
48-
if not paths:
49-
paths = [list(range(len(points)))]
50-
super().__init__('polygon',
51-
{'points': _to_point2s(points), 'paths': paths})
43+
def __init__(self, points: Union[Points, IncludedOpenSCADObject], paths: Indexes = None) -> None:
44+
# Force points to 2D if they're defined in Python, pass through if they're
45+
# included OpenSCAD code
46+
pts = points # type: ignore
47+
if not isinstance(points, IncludedOpenSCADObject):
48+
pts = list([(p[0], p[1]) for p in points]) # type: ignore
49+
50+
args = {'points':pts}
51+
# If not supplied, OpenSCAD assumes all points in order for paths
52+
if paths:
53+
args['paths'] = paths # type: ignore
54+
super().__init__('polygon', args)
5255

5356

5457
class circle(OpenSCADObject):

0 commit comments

Comments
 (0)