Skip to content

Commit 9bb3998

Browse files
committed
More comprehensive solid.utils.extrude_along_path() testing
1 parent 02c5a33 commit 9bb3998

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

solid/test/test_utils.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
('arc', arc, [10, 0, 90, 24], '\n\ndifference() {\n\tcircle($fn = 24, r = 10);\n\trotate(a = 0) {\n\t\ttranslate(v = [0, -10, 0]) {\n\t\t\tsquare(center = true, size = [30, 20]);\n\t\t}\n\t}\n\trotate(a = -90) {\n\t\ttranslate(v = [0, -10, 0]) {\n\t\t\tsquare(center = true, size = [30, 20]);\n\t\t}\n\t}\n}'),
2929
('arc_inverted', arc_inverted, [10, 0, 90, 24], '\n\ndifference() {\n\tintersection() {\n\t\trotate(a = 0) {\n\t\t\ttranslate(v = [-990, 0, 0]) {\n\t\t\t\tsquare(center = false, size = [1000, 1000]);\n\t\t\t}\n\t\t}\n\t\trotate(a = 90) {\n\t\t\ttranslate(v = [-990, -1000, 0]) {\n\t\t\t\tsquare(center = false, size = [1000, 1000]);\n\t\t\t}\n\t\t}\n\t}\n\tcircle($fn = 24, r = 10);\n}'),
3030
('transform_to_point_scad', transform_to_point, [cube(2), [2, 2, 2], [3, 3, 1]], '\n\nmultmatrix(m = [[0.7071067812, -0.1622214211, -0.6882472016, 2], [-0.7071067812, -0.1622214211, -0.6882472016, 2], [0.0000000000, 0.9733285268, -0.2294157339, 2], [0, 0, 0, 1.0000000000]]) {\n\tcube(size = 2);\n}'),
31-
('extrude_along_path', extrude_along_path, [tri, [[0, 0, 0], [0, 20, 0]]], '\n\npolyhedron(faces = [[0, 3, 1], [1, 3, 4], [1, 4, 2], [2, 4, 5], [2, 5, 0], [0, 5, 3], [6, 0, 1], [6, 1, 2], [6, 2, 0], [7, 3, 4], [7, 4, 5], [7, 5, 3]], 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], [10.0000000000, 20.0000000000, 0.0000000000], [0.0000000000, 20.0000000000, 10.0000000000], [3.3333333333, 0.0000000000, 3.3333333333], [3.3333333333, 20.0000000000, 3.3333333333]]);'),
32-
('extrude_along_path_vertical', extrude_along_path, [tri, [[0, 0, 0], [0, 0, 20]]], '\n\npolyhedron(faces = [[0, 3, 1], [1, 3, 4], [1, 4, 2], [2, 4, 5], [2, 5, 0], [0, 5, 3], [6, 0, 1], [6, 1, 2], [6, 2, 0], [7, 3, 4], [7, 4, 5], [7, 5, 3]], points = [[0.0000000000, 0.0000000000, 0.0000000000], [-10.0000000000, 0.0000000000, 0.0000000000], [0.0000000000, 10.0000000000, 0.0000000000], [0.0000000000, 0.0000000000, 20.0000000000], [-10.0000000000, 0.0000000000, 20.0000000000], [0.0000000000, 10.0000000000, 20.0000000000], [-3.3333333333, 3.3333333333, 0.0000000000], [-3.3333333333, 3.3333333333, 20.0000000000]]);'),
33-
('extrude_along_path_xy_scale', extrude_along_path, [tri, [[0, 0, 0], [0, 20, 0]], [Point2(0.5, 1.5), Point2(1.5, 0.5)]], '\n\npolyhedron(faces = [[0, 3, 1], [1, 3, 4], [1, 4, 2], [2, 4, 5], [2, 5, 0], [0, 5, 3], [6, 0, 1], [6, 1, 2], [6, 2, 0], [7, 3, 4], [7, 4, 5], [7, 5, 3]], points = [[0.0000000000, 0.0000000000, 0.0000000000], [5.0000000000, 0.0000000000, 0.0000000000], [0.0000000000, 0.0000000000, 15.0000000000], [0.0000000000, 20.0000000000, 0.0000000000], [15.0000000000, 20.0000000000, 0.0000000000], [0.0000000000, 20.0000000000, 5.0000000000], [1.6666666667, 0.0000000000, 5.0000000000], [5.0000000000, 20.0000000000, 1.6666666667]]);'),
34-
3531
]
3632

3733
other_test_cases = [
@@ -143,15 +139,52 @@ def test_path_2d_polygon(self):
143139
expected = [[0,1,2,3],[4,5,6,7]]
144140
actual = poly.params['paths']
145141
self.assertEqual(expected, actual)
146-
147-
# def test_offset_points_inside(self):
148-
# expected = ''
149-
# actual = scad_render(offset_points(tri2d, offset=2, internal=True))
150-
# self.assertEqualNoWhitespace(expected, actual)
142+
143+
def test_extrude_along_path(self):
144+
path = [[0, 0, 0], [0, 20, 0]]
145+
# basic test
146+
actual = scad_render(extrude_along_path(tri, path))
147+
expected = 'polyhedron(faces = [[0, 3, 1], [1, 3, 4], [1, 4, 2], [2, 4, 5], [2, 5, 0], [0, 5, 3], [6, 0, 1], [6, 1, 2], [6, 2, 0], [7, 3, 4], [7, 4, 5], [7, 5, 3]], 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], [10.0000000000, 20.0000000000, 0.0000000000], [0.0000000000, 20.0000000000, 10.0000000000], [3.3333333333, 0.0000000000, 3.3333333333], [3.3333333333, 20.0000000000, 3.3333333333]]);'
148+
self.assertEqualNoWhitespace(expected, actual)
149+
150+
def test_extrude_along_path_vertical(self):
151+
# make sure we still look good extruding along z axis; gimbal lock can mess us up
152+
vert_path = [[0, 0, 0], [0, 0, 20]]
153+
actual = scad_render(extrude_along_path(tri, vert_path))
154+
expected = 'polyhedron(faces=[[0,3,1],[1,3,4],[1,4,2],[2,4,5],[2,5,0],[0,5,3],[6,0,1],[6,1,2],[6,2,0],[7,3,4],[7,4,5],[7,5,3]],points=[[0.0000000000,0.0000000000,0.0000000000],[-10.0000000000,0.0000000000,0.0000000000],[0.0000000000,10.0000000000,0.0000000000],[0.0000000000,0.0000000000,20.0000000000],[-10.0000000000,0.0000000000,20.0000000000],[0.0000000000,10.0000000000,20.0000000000],[-3.3333333333,3.3333333333,0.0000000000],[-3.3333333333,3.3333333333,20.0000000000]]);'
155+
self.assertEqualNoWhitespace(expected, actual)
156+
157+
def test_extrude_along_path_1d_scale(self):
158+
# verify that we can apply scalar scaling
159+
path = [[0, 0, 0], [0, 20, 0]]
160+
scale_factors_1d = [1.5, 0.5]
161+
actual = scad_render(extrude_along_path(tri, path, scale_factors=scale_factors_1d))
162+
expected = 'polyhedron(faces=[[0,3,1],[1,3,4],[1,4,2],[2,4,5],[2,5,0],[0,5,3],[6,0,1],[6,1,2],[6,2,0],[7,3,4],[7,4,5],[7,5,3]],points=[[0.0000000000,0.0000000000,0.0000000000],[15.0000000000,0.0000000000,0.0000000000],[0.0000000000,0.0000000000,15.0000000000],[0.0000000000,20.0000000000,0.0000000000],[5.0000000000,20.0000000000,0.0000000000],[0.0000000000,20.0000000000,5.0000000000],[5.0000000000,0.0000000000,5.0000000000],[1.6666666667,20.0000000000,1.6666666667]]);'
163+
self.assertEqualNoWhitespace(expected, actual)
164+
165+
def test_extrude_along_path_2d_scale(self):
166+
# verify that we can apply differential x & y scaling
167+
path = [[0, 0, 0], [0, 20, 0], [0, 40, 0]]
168+
scale_factors_2d = [Point2(1,1), Point2(0.5, 1.5), Point2(1.5, 0.5), ]
169+
actual = scad_render(extrude_along_path(tri, path, scale_factors=scale_factors_2d))
170+
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]]);'
171+
self.assertEqualNoWhitespace(expected, actual)
172+
173+
def test_extrude_along_path_end_caps(self):
174+
path = [[0, 0, 0], [0, 20, 0]]
175+
actual = scad_render(extrude_along_path(tri, path, connect_ends=False))
176+
expected = 'polyhedron(faces = [[0, 3, 1], [1, 3, 4], [1, 4, 2], [2, 4, 5], [2, 5, 0], [0, 5, 3], [6, 0, 1], [6, 1, 2], [6, 2, 0], [7, 3, 4], [7, 4, 5], [7, 5, 3]], 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], [10.0000000000, 20.0000000000, 0.0000000000], [0.0000000000, 20.0000000000, 10.0000000000], [3.3333333333, 0.0000000000, 3.3333333333], [3.3333333333, 20.0000000000, 3.3333333333]]);'
177+
self.assertEqualNoWhitespace(expected, actual)
178+
179+
def test_extrude_along_path_connect_ends(self):
180+
path = [[0, 0, 0], [20, 0, 0], [20,20,0], [0,20, 0]]
181+
actual = scad_render(extrude_along_path(tri, path, connect_ends=True))
182+
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],[6,9,7],[7,9,10],[7,10,8],[8,10,11],[8,11,6],[6,11,9],[0,9,1],[1,9,10],[1,10,2],[2,10,11],[2,11,0],[0,11,9]],points=[[0.0000000000,0.0000000000,0.0000000000],[-7.0710678119,-7.0710678119,0.0000000000],[0.0000000000,0.0000000000,10.0000000000],[20.0000000000,0.0000000000,0.0000000000],[27.0710678119,-7.0710678119,0.0000000000],[20.0000000000,0.0000000000,10.0000000000],[20.0000000000,20.0000000000,0.0000000000],[27.0710678119,27.0710678119,0.0000000000],[20.0000000000,20.0000000000,10.0000000000],[0.0000000000,20.0000000000,0.0000000000],[-7.0710678119,27.0710678119,0.0000000000],[0.0000000000,20.0000000000,10.0000000000]]);'
183+
self.assertEqualNoWhitespace(expected, actual)
151184

152185
def test_extrude_along_path_numpy(self):
153186
try:
154-
import numpy as np
187+
import numpy as np # type: ignore
155188
except ImportError:
156189
return
157190

@@ -164,7 +197,6 @@ def test_extrude_along_path_numpy(self):
164197
# in earlier code, this would have thrown an exception
165198
a = extrude_along_path(shape_pts=profile, path_pts=path, scale_factors=scalepts)
166199

167-
168200
def test_label(self):
169201
expected = 'translate(v=[0,5.0000000000,0]){resize(newsize=[15,0,0.5000000000]){union(){translate(v=[0,0.0000000000,0]){linear_extrude(height=1){text($fn=40,font="MgOpenModata:style=Bold",halign="left",spacing=1,text="Hello,",valign="baseline");}}translate(v=[0,-11.5000000000,0]){linear_extrude(height=1){text($fn=40,font="MgOpenModata:style=Bold",halign="left",spacing=1,text="World",valign="baseline");}}}}}'
170202
actual = scad_render(label("Hello,\nWorld"))

0 commit comments

Comments
 (0)