diff --git a/src/__private__/__is_vector.scad b/src/__private__/__is_vector.scad new file mode 100644 index 00000000..a4e9d880 --- /dev/null +++ b/src/__private__/__is_vector.scad @@ -0,0 +1 @@ +function __is_vector(value) = !(value >= "") && len(value) != undef; \ No newline at end of file diff --git a/src/cross_sections.scad b/src/cross_sections.scad index 888ec9ad..964ba6e3 100644 --- a/src/cross_sections.scad +++ b/src/cross_sections.scad @@ -11,12 +11,14 @@ * **/ +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]], - scale_step_vt = len(scale) == 2 ? + 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], scale_step_x = scale_step_vt[0], diff --git a/src/helix.scad b/src/helix.scad index c247a8ae..f6679e19 100644 --- a/src/helix.scad +++ b/src/helix.scad @@ -12,12 +12,14 @@ * **/ +include <__private__/__is_vector.scad>; include <__private__/__frags.scad>; function helix(radius, levels, level_dist, vt_dir = "SPI_DOWN", rt_dir = "CT_CLK") = let( - r1 = len(radius) == undef ? radius : radius[0], - r2 = len(radius) == undef ? radius : radius[1], + is_vt = __is_vector(radius), + r1 = is_vt ? radius[0] : radius, + r2 = is_vt ? radius[1] : radius, init_r = vt_dir == "SPI_DOWN" ? r2 : r1, _frags = __frags(init_r), h = level_dist * levels, diff --git a/src/helix_extrude.scad b/src/helix_extrude.scad index cd7fe200..a4729c3a 100644 --- a/src/helix_extrude.scad +++ b/src/helix_extrude.scad @@ -10,14 +10,16 @@ * **/ +include <__private__/__is_vector.scad>; include <__private__/__frags.scad>; module helix_extrude(shape_pts, radius, levels, level_dist, vt_dir = "SPI_DOWN", rt_dir = "CT_CLK", twist = 0, scale = 1.0, triangles = "RADIAL") { - - r1 = len(radius) == undef ? radius : radius[0]; - r2 = len(radius) == undef ? radius : radius[1]; + + is_vt = __is_vector(radius); + r1 = is_vt ? radius[0] : radius; + r2 = is_vt ? radius[1] : radius; init_r = vt_dir == "SPI_DOWN" ? r2 : r1; diff --git a/src/path_extrude.scad b/src/path_extrude.scad index 6498e5c0..8370885c 100644 --- a/src/path_extrude.scad +++ b/src/path_extrude.scad @@ -13,6 +13,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); @@ -21,7 +23,7 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale len_path_pts = len(pth_pts); len_path_pts_minus_one = len_path_pts - 1; - scale_step_vt = len(scale) == 2 ? + 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/rounded_cube.scad b/src/rounded_cube.scad index 1490d094..f23a3074 100644 --- a/src/rounded_cube.scad +++ b/src/rounded_cube.scad @@ -11,12 +11,14 @@ * **/ +include <__private__/__is_vector.scad>; include <__private__/__frags.scad>; module rounded_cube(size, corner_r, center = false) { - x = len(size) == undef ? size : size[0]; - y = len(size) == undef ? size : size[1]; - z = len(size) == undef ? size : size[2]; + is_vt = __is_vector(size); + x = is_vt ? size[0] : size; + y = is_vt ? size[1] : size; + z = is_vt ? size[2] : size; frags = __frags(corner_r); diff --git a/src/rounded_square.scad b/src/rounded_square.scad index 13aff21a..618ea658 100644 --- a/src/rounded_square.scad +++ b/src/rounded_square.scad @@ -11,6 +11,7 @@ * **/ +include <__private__/__is_vector.scad>; include <__private__/__frags.scad>; module rounded_square(size, corner_r, center = false) { @@ -21,8 +22,9 @@ module rounded_square(size, corner_r, center = false) { step_a = 360 / corner_frags; - x = len(size) == undef ? size : size[0]; - y = len(size) == undef ? size : size[1]; + is_vt = __is_vector(size); + x = is_vt ? size[0] : size; + y = is_vt ? size[1] : size; half_x = x / 2; half_y = y / 2;