diff --git a/src/__private__/__to2d.scad b/src/__private__/__to2d.scad new file mode 100644 index 00000000..865cfcda --- /dev/null +++ b/src/__private__/__to2d.scad @@ -0,0 +1 @@ +function __to2d(p) = [p[0], p[1]]; \ No newline at end of file diff --git a/src/__private__/__to3d.scad b/src/__private__/__to3d.scad new file mode 100644 index 00000000..af3d63aa --- /dev/null +++ b/src/__private__/__to3d.scad @@ -0,0 +1 @@ +function __to3d(p) = [p[0], p[1], 0]; \ No newline at end of file diff --git a/src/cross_sections.scad b/src/cross_sections.scad index 964ba6e3..e6d5edbc 100644 --- a/src/cross_sections.scad +++ b/src/cross_sections.scad @@ -11,13 +11,14 @@ * **/ +include <__private__/__to3d.scad>; include <__private__/__is_vector.scad>; function cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0) = let( len_path_pts_minus_one = len(path_pts) - 1, - sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) [p[0], p[1], 0]], - pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) [p[0], p[1], 0]], + sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) __to3d(p)], + pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)], scale_step_vt = __is_vector(scale) ? [(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one] : [(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one], diff --git a/src/golden_spiral.scad b/src/golden_spiral.scad index 11a1553d..0bb87957 100644 --- a/src/golden_spiral.scad +++ b/src/golden_spiral.scad @@ -44,12 +44,10 @@ function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) = a_step = 360 / $fn * rt_dir, arc_points_angles = (rt_dir == 1 ? [ for(i = [0:len_pts - 1]) - // to 3D points because of rotate_p - [[circle_pts[i][0], circle_pts[i][1], 0], a_step * i] + [circle_pts[i], a_step * i] ] : [ for(i = [0:len_pts - 1]) let(idx = len_pts - i - 1) - // to 3D points because of rotate_p - [[circle_pts[idx][0], circle_pts[idx][1], 0], a_step * i] + [circle_pts[idx], a_step * i] ]), offset = f2 - f1 ) _remove_same_pts( @@ -69,7 +67,4 @@ function _golden_spiral(from, to, point_distance, rt_dir) = _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) : []; function golden_spiral(from, to, point_distance, rt_dir = "CT_CLK") = - [ - for(pt_a = _golden_spiral(from, to, point_distance, (rt_dir == "CT_CLK" ? 1 : -1))) - [[pt_a[0][0], pt_a[0][1]], pt_a[1]] // to 2D points - ]; \ No newline at end of file + _golden_spiral(from, to, point_distance, (rt_dir == "CT_CLK" ? 1 : -1)); \ No newline at end of file diff --git a/src/path_extrude.scad b/src/path_extrude.scad index 8370885c..a5634c83 100644 --- a/src/path_extrude.scad +++ b/src/path_extrude.scad @@ -16,11 +16,8 @@ include <__private__/__is_vector.scad>; module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale = 1.0, closed = false) { - - s_pts = to3d(shape_pts); - pth_pts = to3d(path_pts); - - len_path_pts = len(pth_pts); + + len_path_pts = len(path_pts); len_path_pts_minus_one = len_path_pts - 1; scale_step_vt = __is_vector(scale) ? @@ -31,13 +28,10 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale scale_step_y = scale_step_vt[1]; twist_step = twist / len_path_pts_minus_one; - function to3d(pts) = - len(pts[0]) == 3 ? pts : [for(p = pts) [p[0], p[1], 0]]; - function first_section() = let( - p1 = pth_pts[0], - p2 = pth_pts[1], + p1 = path_pts[0], + p2 = path_pts[1], dx = p2[0] - p1[0], dy = p2[1] - p1[1], dz = p2[2] - p1[2], @@ -45,7 +39,7 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale az = atan2(dy, dx) ) [ - for(p = s_pts) + for(p = shape_pts) rotate_p(p, [0, ay, az]) + p1 ]; @@ -59,7 +53,7 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale az = atan2(dy, dx) ) [ - for(p = s_pts) + for(p = shape_pts) let(scaled_p = [p[0] * (1 + scale_step_x * i), p[1] * (1 + scale_step_y * i), p[2]]) rotate_p( rotate_p(scaled_p, twist_step * i) + [0, 0, length], @@ -70,11 +64,11 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale function path_extrude_inner(index) = index == len_path_pts ? [] : concat( - [section(pth_pts[index - 1], pth_pts[index], index)], + [section(path_pts[index - 1], path_pts[index], index)], path_extrude_inner(index + 1) ); - if(closed && pth_pts[0] == pth_pts[len_path_pts_minus_one]) { + if(closed && path_pts[0] == path_pts[len_path_pts_minus_one]) { // round-robin sections = path_extrude_inner(1); polysections( diff --git a/src/rotate_p.scad b/src/rotate_p.scad index b7f30903..fb91f02d 100644 --- a/src/rotate_p.scad +++ b/src/rotate_p.scad @@ -11,6 +11,9 @@ * **/ +include <__private__/__to2d.scad>; +include <__private__/__to3d.scad>; + function _rotx(pt, a) = let(cosa = cos(a), sina = sin(a)) [ @@ -38,8 +41,6 @@ function _rotz(pt, a) = function _rotate_p_3d(point, a) = _rotz(_roty(_rotx(point, a[0]), a[1]), a[2]); -function _to2d(p) = [p[0], p[1]]; - function to_avect(a) = len(a) == 3 ? a : ( len(a) == 2 ? [a[0], a[1], 0] : ( @@ -51,6 +52,6 @@ function rotate_p(point, a) = let(angle = to_avect(a)) len(point) == 3 ? _rotate_p_3d(point, angle) : - _to2d( - _rotate_p_3d([point[0], point[1], 0], angle) + __to2d( + _rotate_p_3d(__to3d(point), angle) ); diff --git a/src/shape_square.scad b/src/shape_square.scad index 62903068..e40a183c 100644 --- a/src/shape_square.scad +++ b/src/shape_square.scad @@ -12,6 +12,7 @@ * **/ +include <__private__/__is_vector.scad>; include <__private__/__frags.scad>; function shape_square(size, corner_r = 0) = @@ -20,8 +21,8 @@ function shape_square(size, corner_r = 0) = remain = frags % 4, corner_frags = (remain / 4) > 0.5 ? frags - remain + 4 : frags - remain, step_a = 360 / corner_frags, - x = len(size) == undef ? size : size[0], - y = len(size) == undef ? size : size[1], + x = __is_vector(size) ? size[0] : size, + y = __is_vector(size) ? size[1] : size, half_x = x / 2, half_y = y / 2, half_w = half_x - corner_r, diff --git a/src/turtle2d.scad b/src/turtle2d.scad index e0918632..0ac58609 100644 --- a/src/turtle2d.scad +++ b/src/turtle2d.scad @@ -11,8 +11,6 @@ * **/ -include ; - function _turtle2d_turtle(x, y, angle) = [[x, y], angle]; function _turtle2d_set_point(turtle, point) = [point, _turtle2d_get_angle(turtle)];