5
5
from types import SimpleNamespace
6
6
from typing import Dict , Optional , Sequence , Tuple , Union , List
7
7
8
- from .solidpython import OpenSCADObject
8
+ from .solidpython import IncludedOpenSCADObject , OpenSCADObject
9
9
10
10
PathStr = Union [Path , str ]
11
11
22
22
ScadSize = Union [int , Sequence [float ]]
23
23
OpenSCADObjectPlus = Union [OpenSCADObject , Sequence [OpenSCADObject ]]
24
24
25
- def _to_point2s (points :Points ) -> List [P2 ]:
26
- return list ([(p [0 ], p [1 ]) for p in points ])
27
-
28
-
29
25
class polygon (OpenSCADObject ):
30
26
"""
31
27
Create a polygon with the specified points and paths.
@@ -44,11 +40,18 @@ class polygon(OpenSCADObject):
44
40
to 2D before compiling
45
41
"""
46
42
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 )
52
55
53
56
54
57
class circle (OpenSCADObject ):
0 commit comments