55from types import SimpleNamespace
66from typing import Dict , Optional , Sequence , Tuple , Union , List
77
8- from .solidpython import OpenSCADObject
8+ from .solidpython import IncludedOpenSCADObject , OpenSCADObject
99
1010PathStr = Union [Path , str ]
1111
2222ScadSize = Union [int , Sequence [float ]]
2323OpenSCADObjectPlus = 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-
2925class 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
5457class circle (OpenSCADObject ):
0 commit comments