Skip to content

Commit e994edd

Browse files
committed
-- Allow list of 2-tuples as scale_factors arguments to solid.utils.extrude_along_path(), as well as Point2s
-- Tests for same
1 parent 1a8ea15 commit e994edd

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

solid/test/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def test_extrude_along_path_2d_scale(self):
170170
expected = 'polyhedron(faces=[[0,3,1],[1,3,4],[1,4,2],[2,4,5],[2,5,0],[0,5,3],[3,6,4],[4,6,7],[4,7,5],[5,7,8],[5,8,3],[3,8,6],[9,0,1],[9,1,2],[9,2,0],[10,6,7],[10,7,8],[10,8,6]],points=[[0.0000000000,0.0000000000,0.0000000000],[10.0000000000,0.0000000000,0.0000000000],[0.0000000000,0.0000000000,10.0000000000],[0.0000000000,20.0000000000,0.0000000000],[5.0000000000,20.0000000000,0.0000000000],[0.0000000000,20.0000000000,15.0000000000],[0.0000000000,40.0000000000,0.0000000000],[15.0000000000,40.0000000000,0.0000000000],[0.0000000000,40.0000000000,5.0000000000],[3.3333333333,0.0000000000,3.3333333333],[5.0000000000,40.0000000000,1.6666666667]]);'
171171
self.assertEqualNoWhitespace(expected, actual)
172172

173+
def test_extrude_along_path_2d_scale_list_input(self):
174+
# verify that we can apply differential x & y scaling
175+
path = [[0, 0, 0], [0, 20, 0], [0, 40, 0]]
176+
scale_factors_2d = [(1,1), (0.5, 1.5), (1.5, 0.5), ]
177+
actual = scad_render(extrude_along_path(tri, path, scale_factors=scale_factors_2d))
178+
expected = 'polyhedron(faces=[[0,3,1],[1,3,4],[1,4,2],[2,4,5],[2,5,0],[0,5,3],[3,6,4],[4,6,7],[4,7,5],[5,7,8],[5,8,3],[3,8,6],[9,0,1],[9,1,2],[9,2,0],[10,6,7],[10,7,8],[10,8,6]],points=[[0.0000000000,0.0000000000,0.0000000000],[10.0000000000,0.0000000000,0.0000000000],[0.0000000000,0.0000000000,10.0000000000],[0.0000000000,20.0000000000,0.0000000000],[5.0000000000,20.0000000000,0.0000000000],[0.0000000000,20.0000000000,15.0000000000],[0.0000000000,40.0000000000,0.0000000000],[15.0000000000,40.0000000000,0.0000000000],[0.0000000000,40.0000000000,5.0000000000],[3.3333333333,0.0000000000,3.3333333333],[5.0000000000,40.0000000000,1.6666666667]]);'
179+
self.assertEqualNoWhitespace(expected, actual)
180+
173181
def test_extrude_along_path_end_caps(self):
174182
path = [[0, 0, 0], [0, 20, 0]]
175183
actual = scad_render(extrude_along_path(tri, path, connect_ends=False))

solid/utils.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def path_2d_polygon(points:Sequence[Point23], width:float=1, closed:bool=False)
11431143
# ==========================
11441144
def extrude_along_path( shape_pts:Points,
11451145
path_pts:Points,
1146-
scale_factors:Sequence[Union[Vector2, float]]=None,
1146+
scale_factors:Sequence[Union[Vector2, float, Tuple2]]=None,
11471147
connect_ends = False) -> OpenSCADObject:
11481148
# Extrude the convex curve defined by shape_pts along path_pts.
11491149
# -- For predictable results, shape_pts must be planar, convex, and lie
@@ -1234,16 +1234,11 @@ def _loop_facet_indices(loop_start_index:int, loop_pt_count:int, next_loop_start
12341234
facet_indices.append((b,c,d))
12351235
return facet_indices
12361236

1237-
def _scale_loop(points:Sequence[Point3], scale_factor:Union[float, Point2]=None) -> List[Point3]:
1238-
scale_x, scale_y = [1, 1]
1239-
if scale_factor:
1240-
if isinstance(scale_factor, (int, float)):
1241-
scale_x, scale_y = scale_factor, scale_factor
1242-
elif isinstance(scale_factor, Vector2):
1243-
scale_x, scale_y = scale_factor.x, scale_factor.y
1244-
else:
1245-
raise ValueError(f'Unable to scale shape_pts with scale_factor: {scale_factor}')
1246-
this_loop = [Point3(v.x * scale_x, v.y * scale_y, v.z) for v in points]
1237+
def _scale_loop(points:Sequence[Point3], scale:Union[float, Point2, Tuple2]=None) -> List[Point3]:
1238+
scale = scale or [1, 1]
1239+
if isinstance(scale, (float, int)):
1240+
scale = [scale] * 2
1241+
this_loop = [Point3(v.x * scale[0], v.y * scale[1], v.z) for v in points]
12471242
return this_loop
12481243

12491244
def _end_cap(new_point_index:int, points:Sequence[Point3], vertex_indices: Sequence[int]) -> Tuple[Point3, List[FacetIndices]]:

0 commit comments

Comments
 (0)