test_rails2sections.scad
1 use <unittest.scad> 2 use <bezier_curve.scad> 3 use <rails2sections.scad> 4 5 module test_rails2sections() { 6 module test_simple_path() { 7 8 echo("==== test_rails2sections_simple_path ===="); 9 10 paths = [ 11 [[5, 0, 5], [15, 10, 10], [25, 20, 5]], 12 [[-5, 0, 5], [-15, 10, 10], [-25, 20, 5]], 13 [[-5, 0, -5], [-15, 10, -10], [-25, 20, -5]], 14 [[5, 0, -5], [15, 10, -10], [25, 20, -5]] 15 ]; 16 17 expected = [ 18 [[5, 0, 5], [-5, 0, 5], [-5, 0, -5], [5, 0, -5]], 19 [[15, 10, 10], [-15, 10, 10], [-15, 10, -10], [15, 10, -10]], 20 [[25, 20, 5], [-25, 20, 5], [-25, 20, -5], [25, 20, -5]] 21 ]; 22 23 actual = rails2sections(paths); 24 25 for(i = [0:len(paths[0]) - 1]) { 26 assertEqualPoints(expected[i], actual[i]); 27 } 28 } 29 30 module test_bezier_path() { 31 32 echo("==== test_rails2sections_bezier_path ===="); 33 34 t_step = 0.05; 35 36 paths = [ 37 bezier_curve(t_step, 38 [[1.25, 0, 5], [5, 20, 5], [16, 20, -2], [18, 20, 10], [30, 15, 8]] 39 ), 40 bezier_curve(t_step, 41 [[-1.25, 0, 5], [0, 20, 5], [16, 22, -2], [18, 20, 10], [30, 25, 8]] 42 ), 43 bezier_curve(t_step, 44 [[-1.25, 0, -5], [0, 20, -5], [16, 20, 1], [18, 27, -3], [20, 27, -5]] 45 ), 46 bezier_curve(t_step, 47 [[1.25, 0, -5], [5, 20, -5], [16, 20, 1], [18, 17.5, -3], [20, 17.5, -5]] 48 ) 49 ]; 50 51 sections = rails2sections(paths); 52 53 for(i = [0:len(sections) - 1]) { 54 for(j = [0:len(sections[i]) - 1]) { 55 assertEqualPoint(paths[j][i], sections[i][j]); 56 } 57 } 58 } 59 60 test_simple_path(); 61 test_bezier_path(); 62 } 63 64 test_rails2sections();