|
52 | 52 | class TestSPUtils( unittest.TestCase): |
53 | 53 | # Test cases will be dynamically added to this instance |
54 | 54 | # using the test case arrays above |
55 | | - def test_split_body_horizontal( self): |
56 | | - body = sphere( 20) |
57 | | - actual_tuple = split_body_horizontal( body, plane_z=10, dowel_holes=True) |
58 | | - actual = [scad_render( b) for b in actual_tuple] |
59 | | - expected = ['\n\ndifference() {\n\tintersection() {\n\t\tsphere(r = 20);\n\t\ttranslate(v = [0, 0, -49990]) {\n\t\t\tcube(center = true, size = 100000);\n\t\t}\n\t}\n\tunion() {\n\t\ttranslate(v = [9.0000000000, 0, 10]) {\n\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t}\n\t\ttranslate(v = [-9.0000000000, 0, 10]) {\n\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t}\n\t}\n}', |
60 | | - '\n\ndifference() {\n\tintersection() {\n\t\tsphere(r = 20);\n\t\ttranslate(v = [0, 0, 50010]) {\n\t\t\tcube(center = true, size = 100000);\n\t\t}\n\t}\n\tunion() {\n\t\ttranslate(v = [9.0000000000, 0, 10]) {\n\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t}\n\t\ttranslate(v = [-9.0000000000, 0, 10]) {\n\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t}\n\t}\n}'] |
| 55 | + |
| 56 | + def test_split_body_planar(self): |
| 57 | + offset = [10, 10, 10] |
| 58 | + body = translate( offset)( sphere( 20)) |
| 59 | + body_bb = BoundingBox( [40, 40, 40], offset) |
| 60 | + actual = [] |
| 61 | + for split_dir in [ RIGHT_VEC, FORWARD_VEC, UP_VEC]: |
| 62 | + actual_tuple = split_body_planar( body, body_bb, cutting_plane_normal=split_dir, cut_proportion=0.25) |
| 63 | + actual.append( actual_tuple) |
| 64 | + |
| 65 | + # Ignore the bounding box object that come back, taking only the SCAD objects |
| 66 | + actual = [scad_render( a) for splits in actual for a in splits[::2] ] |
| 67 | + |
| 68 | + expected = ['\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [-5.0000000000, 10, 10]) {\n\t\tcube(center = true, size = [10.0000000000, 40, 40]);\n\t}\n}', |
| 69 | + '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [15.0000000000, 10, 10]) {\n\t\tcube(center = true, size = [30.0000000000, 40, 40]);\n\t}\n}', |
| 70 | + '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, -5.0000000000, 10]) {\n\t\tcube(center = true, size = [40, 10.0000000000, 40]);\n\t}\n}', |
| 71 | + '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, 15.0000000000, 10]) {\n\t\tcube(center = true, size = [40, 30.0000000000, 40]);\n\t}\n}', |
| 72 | + '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, 10, -5.0000000000]) {\n\t\tcube(center = true, size = [40, 40, 10.0000000000]);\n\t}\n}', |
| 73 | + '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, 10, 15.0000000000]) {\n\t\tcube(center = true, size = [40, 40, 30.0000000000]);\n\t}\n}' |
| 74 | + ] |
61 | 75 | self.assertEqual( actual, expected) |
62 | | - |
63 | | - def test_split_body_vertical( self): |
64 | | - body = sphere( 20) |
65 | | - actual_tuple = split_body_vertical( body, plane_x=10, dowel_holes=True) |
66 | | - actual = [scad_render( b) for b in actual_tuple] |
67 | | - expected = ['\n\ndifference() {\n\tintersection() {\n\t\tsphere(r = 20);\n\t\ttranslate(v = [-49990, 0, 0]) {\n\t\t\tcube(center = true, size = 100000);\n\t\t}\n\t}\n\tunion() {\n\t\ttranslate(v = [10, 9.0000000000, 0]) {\n\t\t\trotate(a = 90, v = [0, 1, 0]) {\n\t\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t\t}\n\t\t}\n\t\ttranslate(v = [10, -9.0000000000, 0]) {\n\t\t\trotate(a = 90, v = [0, 1, 0]) {\n\t\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t\t}\n\t\t}\n\t}\n}', |
68 | | - '\n\ndifference() {\n\tintersection() {\n\t\tsphere(r = 20);\n\t\ttranslate(v = [50010, 0, 0]) {\n\t\t\tcube(center = true, size = 100000);\n\t\t}\n\t}\n\tunion() {\n\t\ttranslate(v = [10, 9.0000000000, 0]) {\n\t\t\trotate(a = 90, v = [0, 1, 0]) {\n\t\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t\t}\n\t\t}\n\t\ttranslate(v = [10, -9.0000000000, 0]) {\n\t\t\trotate(a = 90, v = [0, 1, 0]) {\n\t\t\t\tcylinder(h = 30, r = 4.5000000000, center = true);\n\t\t\t}\n\t\t}\n\t}\n}'] |
69 | | - self.assertEqual( actual, expected) |
70 | | - |
| 76 | + |
71 | 77 | def test_fillet_2d_add( self): |
72 | 78 | pts = [ [0,5], [5,5], [5,0], [10,0], [10,10], [0,10],] |
73 | 79 | p = polygon( pts) |
|
0 commit comments