From a4c0d0be65b866b7563d227cf8f190c05e0689ae Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 8 May 2022 20:51:37 +0800 Subject: [PATCH] rename --- src/_impl/_bezier_curve_impl.scad | 10 +- src/_impl/_bezier_smooth_impl.scad | 12 +- src/_impl/_bijection_offset_impl.scad | 10 +- src/_impl/_bspline_curve_impl.scad | 38 +++--- src/_impl/_golden_spiral_impl.scad | 4 +- src/_impl/_in_shape_impl.scad | 8 +- src/_impl/_midpt_smooth_impl.scad | 4 +- src/_impl/_shape_liquid_splitting_impl.scad | 16 +-- src/_impl/_shape_path_extend_impl.scad | 22 ++-- src/_impl/_trim_shape_impl.scad | 22 ++-- src/in_shape.scad | 4 +- src/noise/_impl/_pnoise1_impl.scad | 6 +- src/noise/_impl/_pnoise2_impl.scad | 10 +- src/noise/_impl/_pnoise3_impl.scad | 18 +-- .../_impl/_tri_ear_clipping_impl.scad | 38 +++--- src/turtle/_impl/_t2d_impl.scad | 74 +++++------ src/turtle/_impl/_t3d_impl.scad | 124 +++++++++--------- src/voxel/_impl/_vx_bezier_impl.scad | 10 +- src/voxel/_impl/_vx_circle_impl.scad | 12 +- src/voxel/_impl/_vx_contour_impl.scad | 20 +-- src/voxel/_impl/_vx_curve_impl.scad | 11 +- src/voxel/_impl/_vx_cylinder_impl.scad | 16 +-- src/voxel/_impl/_vx_from_impl.scad | 4 +- src/voxel/_impl/_vx_gray_impl.scad | 4 +- src/voxel/_impl/_vx_line_impl.scad | 102 +++++++------- 25 files changed, 294 insertions(+), 305 deletions(-) diff --git a/src/_impl/_bezier_curve_impl.scad b/src/_impl/_bezier_curve_impl.scad index c395a187..93ed974b 100644 --- a/src/_impl/_bezier_curve_impl.scad +++ b/src/_impl/_bezier_curve_impl.scad @@ -12,12 +12,12 @@ function _combi(n, k) = n < 4 ? bi_coef[n][k] : k == 0 ? 1 : (_combi(n, k - 1) * (n - k + 1) / k); -function bezier_curve_component(t, points, n, i) = +function _component(t, points, n, i) = let(one_t = 1 - t) sum([for(j = [0:n]) _combi(n, j) * points[j][i] * one_t ^ (n - j) * t ^ j]); -function _bezier_curve_coordinate(range, t, points, n) = - [for(i = range) bezier_curve_component(t, points, n, i)]; +function _coordinate(range, t, points, n) = + [for(i = range) _component(t, points, n, i)]; function _bezier_curve_impl(t_step, points) = let( @@ -26,6 +26,6 @@ function _bezier_curve_impl(t_step, points) = range = [0:len(points[0]) - 1] ) [ - each [for(t = 0; t < t_end; t = t + 1) _bezier_curve_coordinate(range, t * t_step, points, n)], - _bezier_curve_coordinate(range, 1, points, n) + each [for(t = 0; t < t_end; t = t + 1) _coordinate(range, t * t_step, points, n)], + _coordinate(range, 1, points, n) ]; diff --git a/src/_impl/_bezier_smooth_impl.scad b/src/_impl/_bezier_smooth_impl.scad index 6f9ce7da..35ad5c38 100644 --- a/src/_impl/_bezier_smooth_impl.scad +++ b/src/_impl/_bezier_smooth_impl.scad @@ -25,16 +25,16 @@ function _corner_ctrl_pts(round_d, p1, p2, p3) = p2 - [dx2, dy2, dz2] ]; -function _bezier_corner(round_d, t_step, p1, p2, p3) = +function _corner(round_d, t_step, p1, p2, p3) = bezier_curve(t_step, _corner_ctrl_pts(round_d, p1, p2, p3)); -function _bezier_smooth_corners(pts, round_d, t_step, leng, angle_threshold) = +function _corners(pts, round_d, t_step, leng, angle_threshold) = let(end_i = leng - 2) [ for(i = 0; i < end_i; i = i + 1) let(pi = pts[i], pi1 = pts[i + 1], pi2 = pts[i + 2]) each angle_between(pi - pi1, pi1 - pi2) > angle_threshold ? - _bezier_corner(round_d, t_step, pi, pi1, pi2) : [pi1] + _corner(round_d, t_step, pi, pi1, pi2) : [pi1] ]; function _bezier_smooth_impl(path_pts, round_d, t_step, closed, angle_threshold) = @@ -42,16 +42,16 @@ function _bezier_smooth_impl(path_pts, round_d, t_step, closed, angle_threshold) pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)], leng = len(pts), first = pts[0], - middle_pts = _bezier_smooth_corners(pts, round_d, t_step, leng, angle_threshold), + middle_pts = _corners(pts, round_d, t_step, leng, angle_threshold), last = pts[leng - 1], pth_pts = closed ? concat( - _bezier_smooth_corners( + _corners( [last, first, pts[1]], round_d, t_step, 3, angle_threshold ), middle_pts, - _bezier_smooth_corners( + _corners( [pts[leng - 2], last, first], round_d, t_step, 3, angle_threshold ) diff --git a/src/_impl/_bijection_offset_impl.scad b/src/_impl/_bijection_offset_impl.scad index 816347d6..de1c18ad 100644 --- a/src/_impl/_bijection_offset_impl.scad +++ b/src/_impl/_bijection_offset_impl.scad @@ -1,25 +1,25 @@ use <../__comm__/__lines_from.scad>; use <../__comm__/__line_intersection.scad>; -function _bijection_outward_edge_normal(edge) = +function _outward_edge_normal(edge) = let( v = edge[1] - edge[0], nv = v / norm(v) ) [nv.y, -nv.x]; -function _bijection_offset_edge(edge, dxy) = edge + [dxy, dxy]; +function _edge(edge, dxy) = edge + [dxy, dxy]; -function _bijection__bijection_offset_edges(edges, d) = +function _offset_edges(edges, d) = [ for(edge = edges) - _bijection_offset_edge(edge, _bijection_outward_edge_normal(edge) * d) + _edge(edge, _outward_edge_normal(edge) * d) ]; function _bijection_offset_impl(pts, d, epsilon) = let( es = __lines_from(pts, true), - offset_es = _bijection__bijection_offset_edges(es, d), + offset_es = _offset_edges(es, d), leng_minus_one = len(offset_es) - 1, last_p = __line_intersection2(offset_es[leng_minus_one], offset_es[0], epsilon) ) diff --git a/src/_impl/_bspline_curve_impl.scad b/src/_impl/_bspline_curve_impl.scad index 6efbc87d..56f3c53e 100644 --- a/src/_impl/_bspline_curve_impl.scad +++ b/src/_impl/_bspline_curve_impl.scad @@ -1,29 +1,28 @@ -function _bspline_curve_knots(n, degree) = [each [0:n + degree]]; +function _knots(n, degree) = [each [0:n + degree]]; -function _bspline_curve_weights(n) = [for(i = 0; i < n; i = i + 1) 1]; +function _weights(n) = [for(i = 0; i < n; i = i + 1) 1]; -function _bspline_curve_ts(ot, degree, knots) = +function _ts(ot, degree, knots) = let( domain = [degree, len(knots) - 1 - degree], low = knots[domain[0]], high = knots[domain[1]], t = ot * (high - low) + low, - s = _bspline_curve_s(domain[0], domain[1], t, knots) + s = _s(domain[0], domain[1], t, knots) ) [t, s]; -function _bspline_curve_s(s, end, t, knots) = - t >= knots[s] && t <= knots[s+1] ? - s : _bspline_curve_s(s + 1, end, t, knots); +function _s(s, end, t, knots) = + t >= knots[s] && t <= knots[s+1] ? s : _s(s + 1, end, t, knots); -function _bspline_curve_alpha(i, l, t, degree, knots) = +function _alpha(i, l, t, degree, knots) = (t - knots[i]) / (knots[i + degree + 1 - l] - knots[i]); function _bspline_curve_nvi(v, i, l, t, degree, knots, d) = - let(alpha = _bspline_curve_alpha(i, l, t, degree, knots)) + let(alpha = _alpha(i, l, t, degree, knots)) [for(j = 0; j < d + 1; j = j + 1) ((1 - alpha) * v[i - 1][j] + alpha * v[i][j])]; -function _bspline_curve_nvl(v, l, s, t, degree, knots, d, i) = +function _nvl(v, l, s, t, degree, knots, d, i) = i == (s - degree - 1 + l) ? v : let( leng_v = len(v), @@ -33,27 +32,26 @@ function _bspline_curve_nvl(v, l, s, t, degree, knots, d, i) = each [for(j = i + 1; j < leng_v; j = j + 1) v[j]] ] ) - _bspline_curve_nvl(nv, l, s, t, degree, knots, d, i - 1); + _nvl(nv, l, s, t, degree, knots, d, i - 1); -function _bspline_curve_v(v, s, t, degree, knots, d, l = 1) = +function _v(v, s, t, degree, knots, d, l = 1) = l > degree + 1 ? v : - let(nv = _bspline_curve_nvl(v, l, s, t, degree, knots, d, s)) - _bspline_curve_v(nv, s, t, degree, knots, d, l + 1); + _v(_nvl(v, l, s, t, degree, knots, d, s), s, t, degree, knots, d, l + 1); -function _bspline_curve_interpolate(t, degree, points, knots, weights) = +function _interpolate(t, degree, points, knots, weights) = let( d = len(points[0]), n = len(points), - kts = is_undef(knots) ? _bspline_curve_knots(n, degree) : knots, - wts = is_undef(weights) ? _bspline_curve_weights(n) : weights, + kts = is_undef(knots) ? _knots(n, degree) : knots, + wts = is_undef(weights) ? _weights(n) : weights, v = [ for(i = 0; i < n; i = i + 1) let(wt = wts[i]) [each points[i] * wt, wt] ], - ts = _bspline_curve_ts(t, degree, kts), + ts = _ts(t, degree, kts), s = ts[1], - nvs = _bspline_curve_v(v, s, ts[0], degree, kts, d)[s] + nvs = _v(v, s, ts[0], degree, kts, d)[s] ) [for(i = 0; i < d; i = i + 1) nvs[i]] / nvs[d]; @@ -64,5 +62,5 @@ function _bspline_curve_impl(t_step, degree, points, knots, weights) = assert(is_undef(knots) || (len(knots) == n + degree + 1), "len(knots) must be equals to len(points) + degree + 1") [ for(t = 0; t < 1; t = t + t_step) - _bspline_curve_interpolate(t, degree, points, knots, weights) + _interpolate(t, degree, points, knots, weights) ]; \ No newline at end of file diff --git a/src/_impl/_golden_spiral_impl.scad b/src/_impl/_golden_spiral_impl.scad index 453d0487..5ce5a2f0 100644 --- a/src/_impl/_golden_spiral_impl.scad +++ b/src/_impl/_golden_spiral_impl.scad @@ -8,7 +8,7 @@ function _remove_same_pts(pts1, pts2) = pts1[len(pts1) - 1] == pts2[0] ? [for(i = [1:len(pts2) - 1]) pts2[i]] : pts2 ); -function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) = +function _from_ls_or_eql_to(from, to, point_distance, rt_dir) = let( f1 = __fast_fibonacci(from), fn = floor(f1 * PI * 2 / point_distance), @@ -36,7 +36,7 @@ function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) = ); function _golden_spiral(from, to, point_distance, rt_dir) = - from > to ? [] : _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir); + from > to ? [] : _from_ls_or_eql_to(from, to, point_distance, rt_dir); function _golden_spiral_impl(from, to, point_distance, rt_dir) = _golden_spiral(from, to, point_distance, (rt_dir == "CT_CLK" ? 1 : -1)); \ No newline at end of file diff --git a/src/_impl/_in_shape_impl.scad b/src/_impl/_in_shape_impl.scad index bd397c42..221ba415 100644 --- a/src/_impl/_in_shape_impl.scad +++ b/src/_impl/_in_shape_impl.scad @@ -1,16 +1,16 @@ use <__comm__/__in_line.scad>; -function _in_shape_in_any_edges(edges, pt, epsilon) = - let( +function _in_any_edges(edges, pt, epsilon) = + let( leng = len(edges), maybe_last = [for(i = 0; i < leng && !__in_line(edges[i], pt, epsilon); i = i + 1) i][leng - 1] ) is_undef(maybe_last); -function _in_shape_does_pt_cross(pi, pj, pt) = +function _does_pt_cross(pi, pj, pt) = ((pi.y - pt.y) * (pj.y - pt.y) < 0) && (pt.x < lookup(pt.y, [[pi.y, pi.x], [pj.y, pj.x]])); function _in_shape_sub(shapt_pts, leng, pt, cond, i = 0) = let(j = i + 1) - j == leng ? cond : _in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts[i], shapt_pts[j], pt) ? !cond : cond, j); + j == leng ? cond : _in_shape_sub(shapt_pts, leng, pt, _does_pt_cross(shapt_pts[i], shapt_pts[j], pt) ? !cond : cond, j); \ No newline at end of file diff --git a/src/_impl/_midpt_smooth_impl.scad b/src/_impl/_midpt_smooth_impl.scad index 593904b0..347cb74c 100644 --- a/src/_impl/_midpt_smooth_impl.scad +++ b/src/_impl/_midpt_smooth_impl.scad @@ -8,7 +8,5 @@ function _midpt_smooth_sub(points, iend, closed) = ]; function _midpt_smooth_impl(points, n, closed) = - let( - smoothed = _midpt_smooth_sub(points, len(points) - 1, closed) - ) + let(smoothed = _midpt_smooth_sub(points, len(points) - 1, closed)) n == 1 ? smoothed : _midpt_smooth_impl(smoothed, n - 1, closed); \ No newline at end of file diff --git a/src/_impl/_shape_liquid_splitting_impl.scad b/src/_impl/_shape_liquid_splitting_impl.scad index d29cf25f..5109102d 100644 --- a/src/_impl/_shape_liquid_splitting_impl.scad +++ b/src/_impl/_shape_liquid_splitting_impl.scad @@ -2,7 +2,7 @@ use <../ptf/ptf_rotate.scad>; use <../shape_pie.scad>; use <../bezier_curve.scad>; -function _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle) = +function _pie_curve(radius, centre_dist, tangent_angle) = let( begin_ang = 90 + tangent_angle, shape_pts = shape_pie(radius, [-begin_ang, begin_ang]), @@ -11,7 +11,7 @@ function _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle) = ) [for(i = 1; i < leng; i = i + 1) shape_pts[i] + offset_p]; -function _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) = +function _bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) = let( ctrl_p = ptf_rotate([radius * tan(tangent_angle), -radius], tangent_angle), ctrl_p2 = [-ctrl_p.x, ctrl_p.y] + [centre_dist / 2, 0], @@ -28,18 +28,18 @@ function _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, ct ] ); -function _liquid_splitting_lower_half_curve(curve_pts, leng) = +function _lower_half_curve(curve_pts, leng) = [ for(i = 0; i < leng; i = i + 1) let(p = curve_pts[leng - 1 - i]) if(p.x >= 0) p ]; -function _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_angle, t_step) = +function _half_liquid_splitting(radius, centre_dist, tangent_angle, t_step) = let( - pie_curve_pts = _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle), - curve_pts = _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, pie_curve_pts[0]), - lower_curve_pts = _liquid_splitting_lower_half_curve(curve_pts, len(curve_pts)), + pie_curve_pts = _pie_curve(radius, centre_dist, tangent_angle), + curve_pts = _bezier(radius, centre_dist, tangent_angle, t_step, pie_curve_pts[0]), + lower_curve_pts = _lower_half_curve(curve_pts, len(curve_pts)), upper_curve_pts = [ for(i = len(lower_curve_pts) - 1; i > -1; i = i - 1) let(p = lower_curve_pts[i]) [p.x, -p.y] @@ -52,7 +52,7 @@ function _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_an function _shape_liquid_splitting_impl(radius, centre_dist, tangent_angle, t_step) = let( - half_liquid_splittings = _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_angle, t_step), + half_liquid_splittings = _half_liquid_splitting(radius, centre_dist, tangent_angle, t_step), left_half_liquid_splittings = [ for(i = len(half_liquid_splittings) - 1; i > -1; i = i - 1) let(p = half_liquid_splittings[i]) [-p.x, p.y] diff --git a/src/_impl/_shape_path_extend_impl.scad b/src/_impl/_shape_path_extend_impl.scad index 38a025dd..954e83dd 100644 --- a/src/_impl/_shape_path_extend_impl.scad +++ b/src/_impl/_shape_path_extend_impl.scad @@ -15,29 +15,29 @@ function __polytransversals(transversals) = lefts ); -function _shape_path_extend_az(p1, p2) = let(v = p2 - p1) -90 + atan2(v.y, v.x); +function _az(p1, p2) = let(v = p2 - p1) -90 + atan2(v.y, v.x); -function _shape_path_first_stroke(stroke_pts, path_pts) = +function _first_stroke(stroke_pts, path_pts) = let( p1 = path_pts[0], p2 = path_pts[1], - a = _shape_path_extend_az(p1, p2) + a = _az(p1, p2) ) [for(p = stroke_pts) ptf_rotate(p, a) + p1]; -function _shape_path_extend_stroke(stroke_pts, p1, p2, scale_step, i) = +function _stroke(stroke_pts, p1, p2, scale_step, i) = let( leng = norm(__to3d(p2) - __to3d(p1)), - a = _shape_path_extend_az(p1, p2), + a = _az(p1, p2), s = 1 + scale_step * i, off_p = [0, leng] ) [for(p = stroke_pts) ptf_rotate(p * s + off_p, a) + p1]; -function _shape_path_extend_inner(stroke_pts, path_pts, leng_path_pts, scale_step) = +function _inner(stroke_pts, path_pts, leng_path_pts, scale_step) = [ for(i = 1; i < leng_path_pts; i = i + 1) - _shape_path_extend_stroke( + _stroke( stroke_pts, path_pts[i - 1], path_pts[i ], @@ -50,11 +50,9 @@ function _shape_path_extend_impl(stroke_pts, path_pts, scale, closed) = let( leng_path_pts = len(path_pts), scale_step = (scale - 1) / (leng_path_pts - 1), - strokes = _shape_path_extend_inner(stroke_pts, path_pts, leng_path_pts, scale_step) + strokes = _inner(stroke_pts, path_pts, leng_path_pts, scale_step) ) closed && path_pts[0] == path_pts[leng_path_pts - 1] ? - __polytransversals(concat(strokes, [strokes[0]])) : - __polytransversals( - [_shape_path_first_stroke(stroke_pts, path_pts), each strokes] - ); + __polytransversals([each strokes, strokes[0]]) : + __polytransversals([_first_stroke(stroke_pts, path_pts), each strokes]); diff --git a/src/_impl/_trim_shape_impl.scad b/src/_impl/_trim_shape_impl.scad index 34383ee4..d6ad6aac 100644 --- a/src/_impl/_trim_shape_impl.scad +++ b/src/_impl/_trim_shape_impl.scad @@ -2,13 +2,13 @@ use <../__comm__/__line_intersection.scad>; use <../__comm__/__in_line.scad>; use <../__comm__/__lines_from.scad>; -function _trim_shape_any_intersection_sub(lines, line, lines_leng, i, epsilon) = +function _any_intersection_sub(lines, line, lines_leng, i, epsilon) = let(p = __line_intersection2(lines[i], line, epsilon)) - (p != [] && __in_line(line, p, epsilon) && __in_line(lines[i], p, epsilon)) ? [i, p] : _trim_shape_any_intersection(lines, line, lines_leng, i + 1, epsilon); + (p != [] && __in_line(line, p, epsilon) && __in_line(lines[i], p, epsilon)) ? [i, p] : _any_intersection(lines, line, lines_leng, i + 1, epsilon); // return [idx, [x, y]] or [] -function _trim_shape_any_intersection(lines, line, lines_leng, i, epsilon) = - i == lines_leng ? [] : _trim_shape_any_intersection_sub(lines, line, lines_leng, i, epsilon); +function _any_intersection(lines, line, lines_leng, i, epsilon) = + i == lines_leng ? [] : _any_intersection_sub(lines, line, lines_leng, i, epsilon); function _trim_sub(lines, leng, epsilon) = let( @@ -18,25 +18,25 @@ function _trim_sub(lines, leng, epsilon) = lines_from_next2 = [for(j = 2; j < leng; j = j + 1) lines[j]], current_p = current_line[0], leng_lines_from_next2 = len(lines_from_next2), - inter_p = _trim_shape_any_intersection(lines_from_next2, current_line, leng_lines_from_next2, 0, epsilon) + inter_p = _any_intersection(lines_from_next2, current_line, leng_lines_from_next2, 0, epsilon) ) // no intersecting pt, collect current_p and trim remain lines - inter_p == [] ? [current_p, each _trim_shape_trim_lines(lines_from_next, epsilon)] : + inter_p == [] ? [current_p, each _trim_lines(lines_from_next, epsilon)] : // collect current_p, intersecting pt and the last pt leng == 3 || (inter_p.x == (leng_lines_from_next2 - 1)) ? [current_p, inter_p.y, lines[leng - 1]] : // collect current_p, intersecting pt and trim remain lines - [current_p, inter_p.y, each _trim_shape_trim_lines([for(i = inter_p.x + 1; i < leng_lines_from_next2; i = i + 1) lines_from_next2[i]], epsilon)]; + [current_p, inter_p.y, each _trim_lines([for(i = inter_p.x + 1; i < leng_lines_from_next2; i = i + 1) lines_from_next2[i]], epsilon)]; -function _trim_shape_trim_lines(lines, epsilon) = +function _trim_lines(lines, epsilon) = let(leng = len(lines)) - leng > 2 ? _trim_sub(lines, leng, epsilon) : _trim_shape_collect_pts_from(lines, leng); + leng > 2 ? _trim_sub(lines, leng, epsilon) : _collect_pts_from(lines, leng); -function _trim_shape_collect_pts_from(lines, leng) = +function _collect_pts_from(lines, leng) = [each [for(line = lines) line[0]], lines[leng - 1][1]]; function _trim_shape_impl(shape_pts, from, to, epsilon) = let( pts = [for(i = from; i <= to; i = i + 1) shape_pts[i]], - trimmed = _trim_shape_trim_lines(__lines_from(pts), epsilon) + trimmed = _trim_lines(__lines_from(pts), epsilon) ) len(shape_pts) == len(trimmed) ? trimmed : _trim_shape_impl(trimmed, 0, len(trimmed) - 1, epsilon); diff --git a/src/in_shape.scad b/src/in_shape.scad index fa119310..43c97703 100644 --- a/src/in_shape.scad +++ b/src/in_shape.scad @@ -16,5 +16,5 @@ function in_shape(shapt_pts, pt, include_edge = false, epsilon = 0.0001) = leng = len(shapt_pts), edges = __lines_from(shapt_pts, true) ) - _in_shape_in_any_edges(edges, pt, epsilon) ? include_edge : - _in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts[leng - 1], shapt_pts[0], pt)); \ No newline at end of file + _in_any_edges(edges, pt, epsilon) ? include_edge : + _in_shape_sub(shapt_pts, leng, pt, _does_pt_cross(shapt_pts[leng - 1], shapt_pts[0], pt)); \ No newline at end of file diff --git a/src/noise/_impl/_pnoise1_impl.scad b/src/noise/_impl/_pnoise1_impl.scad index 021f0f4f..9998336a 100644 --- a/src/noise/_impl/_pnoise1_impl.scad +++ b/src/noise/_impl/_pnoise1_impl.scad @@ -2,7 +2,7 @@ use <_pnoise_comm.scad>; use <../../util/lerp.scad>; _signs = [1, -1]; -function _pnoise1_grad1(hashvalue, x) = _signs[hashvalue % 2] * x; +function _grad1(hashvalue, x) = _signs[hashvalue % 2] * x; function _pnoise1_impl(x, seed) = let( @@ -10,7 +10,7 @@ function _pnoise1_impl(x, seed) = xf = x - xi ) lerp( - _pnoise1_grad1(rands(0, 256, 1, seed + xi)[0], xf), - _pnoise1_grad1(rands(0, 256, 1, seed + xi + 1)[0], xf - 1), + _grad1(rands(0, 256, 1, seed + xi)[0], xf), + _grad1(rands(0, 256, 1, seed + xi + 1)[0], xf - 1), _pnoise_fade(xf) ); \ No newline at end of file diff --git a/src/noise/_impl/_pnoise2_impl.scad b/src/noise/_impl/_pnoise2_impl.scad index 1670896d..0ddecaaa 100644 --- a/src/noise/_impl/_pnoise2_impl.scad +++ b/src/noise/_impl/_pnoise2_impl.scad @@ -2,7 +2,7 @@ use <_pnoise_comm.scad>; use <../../util/lerp.scad>; _signs = [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]]; -function _pnoise2_grad2(hashvalue, x, y) = _signs[hashvalue % 8] * [x, y]; +function _grad2(hashvalue, x, y) = _signs[hashvalue % 8] * [x, y]; function _pnoise2(x, y, seed) = let( @@ -19,13 +19,13 @@ function _pnoise2(x, y, seed) = ab = rands(0, 256, 1, rnd1 + 1)[0], bb = rands(0, 256, 1, rnd2 + 1)[0], y1 = lerp( - _pnoise2_grad2(aa, xf, yf), - _pnoise2_grad2(ba, xf - 1, yf), + _grad2(aa, xf, yf), + _grad2(ba, xf - 1, yf), u ), y2 = lerp( - _pnoise2_grad2(ab, xf, yf - 1), - _pnoise2_grad2(bb, xf - 1, yf - 1), + _grad2(ab, xf, yf - 1), + _grad2(bb, xf - 1, yf - 1), u ) ) diff --git a/src/noise/_impl/_pnoise3_impl.scad b/src/noise/_impl/_pnoise3_impl.scad index 5ea7212c..44a943a7 100644 --- a/src/noise/_impl/_pnoise3_impl.scad +++ b/src/noise/_impl/_pnoise3_impl.scad @@ -2,7 +2,7 @@ use <_pnoise_comm.scad>; use <../../util/lerp.scad>; _signs = [[1, 1, 0], [-1, 1, 0], [1, -1, 0], [-1, -1, 0], [1, 0, 1], [-1, 0, 1], [1, 0, -1], [-1, 0, -1], [0, 1, 1], [0, -1, 1], [0, 1, -1], [0, -1, -1], [1, 1, 0], [0, -1, 1], [-1, 1, 0], [0, -1, -1]]; -function _pnoise3_grad3(hashvalue, x, y, z) = _signs[hashvalue % 16] * [x, y, z]; +function _grad3(hashvalue, x, y, z) = _signs[hashvalue % 16] * [x, y, z]; function _pnoise3(x, y, z, seed) = let( @@ -34,24 +34,24 @@ function _pnoise3(x, y, z, seed) = bbb = rands(0, 256, 1, rnd6 + 1)[0], x1 = lerp( - _pnoise3_grad3(aaa, xf, yf, zf), - _pnoise3_grad3(baa, xf - 1, yf, zf), + _grad3(aaa, xf, yf, zf), + _grad3(baa, xf - 1, yf, zf), u ), x2 = lerp( - _pnoise3_grad3(aba, xf, yf - 1, zf), - _pnoise3_grad3(bba, xf - 1, yf - 1, zf), + _grad3(aba, xf, yf - 1, zf), + _grad3(bba, xf - 1, yf - 1, zf), u ), y1 = lerp(x1, x2, v), x3 = lerp( - _pnoise3_grad3(aab, xf, yf, zf - 1), - _pnoise3_grad3(bab, xf - 1, yf, zf - 1), + _grad3(aab, xf, yf, zf - 1), + _grad3(bab, xf - 1, yf, zf - 1), u ), x4 = lerp( - _pnoise3_grad3(abb, xf, yf - 1, zf - 1), - _pnoise3_grad3(bbb, xf - 1, yf - 1, zf - 1), + _grad3(abb, xf, yf - 1, zf - 1), + _grad3(bbb, xf - 1, yf - 1, zf - 1), u ), y2 = lerp(x3, x4, v) diff --git a/src/triangle/_impl/_tri_ear_clipping_impl.scad b/src/triangle/_impl/_tri_ear_clipping_impl.scad index 55aabb19..b76cf4c7 100644 --- a/src/triangle/_impl/_tri_ear_clipping_impl.scad +++ b/src/triangle/_impl/_tri_ear_clipping_impl.scad @@ -1,4 +1,4 @@ -function _triangulate_in_triangle(p0, p1, p2, p) = +function _in_triangle(p0, p1, p2, p) = let( v0 = p0 - p, v1 = p1 - p, @@ -9,53 +9,53 @@ function _triangulate_in_triangle(p0, p1, p2, p) = ) (c0 > 0 && c1 > 0 && c2 > 0) || (c0 < 0 && c1 < 0 && c2 < 0); -function _triangulate_snipable(shape_pts, u, v, w, n, indices, epsilon = 0.0001) = +function _snipable(shape_pts, u, v, w, n, indices, epsilon = 0.0001) = let( a = shape_pts[indices[u]], b = shape_pts[indices[v]], c = shape_pts[indices[w]] ) - epsilon <= cross(b - a, c - a) && _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices); + epsilon <= cross(b - a, c - a) && _snipable_sub(shape_pts, n, u, v, w, a, b, c, indices); -function _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p = 0) = +function _snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p = 0) = p == n || ( - (((p == u) || (p == v) || (p == w)) && _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p + 1)) || - (_triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p + 1) && !_triangulate_in_triangle(a, b, c, shape_pts[indices[p]])) + (((p == u) || (p == v) || (p == w)) && _snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p + 1)) || + (_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p + 1) && !_in_triangle(a, b, c, shape_pts[indices[p]])) ); // remove the elem at idx v from indices -function _triangulate_remove_v(indices, v, num_of_vertices) = +function _remove_v(indices, v, num_of_vertices) = let(nv_minuns_one = num_of_vertices - 1) v == 0 ? [for(i = 1; i <= nv_minuns_one; i = i + 1) indices[i]] : let(n_indices = [for(i = 0; i < v; i = i + 1) indices[i]]) v == nv_minuns_one ? n_indices : concat(n_indices, [for(i = v + 1; i <= nv_minuns_one; i = i + 1) indices[i]]); -function _triangulate_zero_or_value(num_of_vertices, value) = num_of_vertices <= value ? 0 : value; +function _zero_or_value(num_of_vertices, value) = num_of_vertices <= value ? 0 : value; function _triangulate_real_triangulate_sub(shape_pts, collector, indices, v, num_of_vertices, count, epsilon) = let( // idxes of three consecutive vertices - u = _triangulate_zero_or_value(num_of_vertices, v), - vi = _triangulate_zero_or_value(num_of_vertices, u + 1), - w = _triangulate_zero_or_value(num_of_vertices, vi + 1) + u = _zero_or_value(num_of_vertices, v), + vi = _zero_or_value(num_of_vertices, u + 1), + w = _zero_or_value(num_of_vertices, vi + 1) ) - _triangulate_snipable(shape_pts, u, vi, w, num_of_vertices, indices, epsilon) ? - _triangulate_snip(shape_pts, collector, indices, u, vi, w, num_of_vertices, count, epsilon) : - _triangulate_real_triangulate(shape_pts, collector, indices, vi, num_of_vertices, count, epsilon); + _snipable(shape_pts, u, vi, w, num_of_vertices, indices, epsilon) ? + _snip(shape_pts, collector, indices, u, vi, w, num_of_vertices, count, epsilon) : + _real_triangulate(shape_pts, collector, indices, vi, num_of_vertices, count, epsilon); -function _triangulate_snip(shape_pts, collector, indices, u, v, w, num_of_vertices, count, epsilon) = +function _snip(shape_pts, collector, indices, u, v, w, num_of_vertices, count, epsilon) = let(new_nv = num_of_vertices - 1) - _triangulate_real_triangulate( + _real_triangulate( shape_pts, [each collector, [indices[u], indices[v], indices[w]]], - _triangulate_remove_v(indices, v, num_of_vertices), + _remove_v(indices, v, num_of_vertices), v, new_nv, 2 * new_nv, epsilon ); -function _triangulate_real_triangulate(shape_pts, collector, indices, v, num_of_vertices, count, epsilon) = +function _real_triangulate(shape_pts, collector, indices, v, num_of_vertices, count, epsilon) = count <= 0 ? [] : num_of_vertices == 2 ? collector : _triangulate_real_triangulate_sub(shape_pts, collector, indices, v, num_of_vertices, count - 1, epsilon); @@ -66,4 +66,4 @@ function _tri_ear_clipping_impl(shape_pts, epsilon) = v = num_of_vertices - 1, count = 2 * num_of_vertices ) - num_of_vertices < 3 ? [] : _triangulate_real_triangulate(shape_pts, [], [each [0:v]], v, num_of_vertices, count, epsilon); \ No newline at end of file + num_of_vertices < 3 ? [] : _real_triangulate(shape_pts, [], [each [0:v]], v, num_of_vertices, count, epsilon); \ No newline at end of file diff --git a/src/turtle/_impl/_t2d_impl.scad b/src/turtle/_impl/_t2d_impl.scad index 2ab39590..7bc28950 100644 --- a/src/turtle/_impl/_t2d_impl.scad +++ b/src/turtle/_impl/_t2d_impl.scad @@ -1,61 +1,61 @@ -function _t2d_turtle(point, angle) = +function _turtle(point, angle) = [is_undef(point) ? [0, 0] : point, is_undef(angle) ? 0 : angle]; -function _t2d_set_point(t, point) = [point, _t2d_get_angle(t)]; +function _set_point(t, point) = [point, _get_angle(t)]; -function _t2d_set_x(t, x) = [[x, _t2d_get_y(t)], _t2d_get_angle(t)]; -function _t2d_set_y(t, y) = [[_t2d_get_x(t), y], _t2d_get_angle(t)]; -function _t2d_set_angle(t, angle) = [_t2d_get_pt(t), angle]; +function _set_x(t, x) = [[x, _get_y(t)], _get_angle(t)]; +function _set_y(t, y) = [[_get_x(t), y], _get_angle(t)]; +function _set_angle(t, angle) = [_get_pt(t), angle]; -function _t2d_forward(t, leng) = - _t2d_turtle( +function _forward(t, leng) = + _turtle( [ - _t2d_get_x(t) + leng * cos(_t2d_get_angle(t)), - _t2d_get_y(t) + leng * sin(_t2d_get_angle(t)) + _get_x(t) + leng * cos(_get_angle(t)), + _get_y(t) + leng * sin(_get_angle(t)) ], - _t2d_get_angle(t) + _get_angle(t) ); -function _t2d_turn(t, angle) = [_t2d_get_pt(t), _t2d_get_angle(t) + angle]; +function _turn(t, angle) = [_get_pt(t), _get_angle(t) + angle]; -function _t2d_get_x(t) = t[0].x; -function _t2d_get_y(t) = t[0].y; -function _t2d_get_pt(t) = t[0]; -function _t2d_get_angle(t) = t[1]; +function _get_x(t) = t[0].x; +function _get_y(t) = t[0].y; +function _get_pt(t) = t[0]; +function _get_angle(t) = t[1]; -function _t2d_get(t, cmd) = - cmd == "angle" ? _t2d_get_angle(t) : - cmd == "point" ? _t2d_get_pt(t) : +function _get(t, cmd) = + cmd == "angle" ? _get_angle(t) : + cmd == "point" ? _get_pt(t) : assert(false, "unknown command"); -function _t2d_set(t, point, angle) = - !is_undef(point) ? _t2d_set_point(t, point) : - !is_undef(angle) ? _t2d_set_angle(t, angle) : +function _set(t, point, angle) = + !is_undef(point) ? _set_point(t, point) : + !is_undef(angle) ? _set_angle(t, angle) : assert(false, "no target to set"); -function _t2d_cmdline(cmd, t, arg) = - is_undef(arg) ? _t2d_get(t, cmd) : - cmd == "forward" ? _t2d_forward(t, arg) : - cmd == "turn" ? _t2d_turn(t, arg) : - cmd == "point" ? _t2d_set_point(t, arg) : - cmd == "angle" ? _t2d_set_angle(t, arg) : +function _cmdline(cmd, t, arg) = + is_undef(arg) ? _get(t, cmd) : + cmd == "forward" ? _forward(t, arg) : + cmd == "turn" ? _turn(t, arg) : + cmd == "point" ? _set_point(t, arg) : + cmd == "angle" ? _set_angle(t, arg) : assert(false, "unknown command"); -function _t2d_cmd(t, cmd, point, angle, leng) = - cmd == "forward" ? _t2d_forward(t, leng) : - cmd == "turn" ? _t2d_turn(t, angle) : - _t2d_get(t, cmd); +function _cmd(t, cmd, point, angle, leng) = + cmd == "forward" ? _forward(t, leng) : + cmd == "turn" ? _turn(t, angle) : + _get(t, cmd); -function _t2d_cmds(t, cmds, i = 0) = +function _cmds(t, cmds, i = 0) = i == len(cmds) ? t : let( cmd = cmds[i][0], arg = cmds[i][1] ) - _t2d_cmds(_t2d_cmdline(cmd, t, arg), cmds, i + 1); + _cmds(_cmdline(cmd, t, arg), cmds, i + 1); function _t2d_impl(t, cmd, point, angle, leng) = - is_undef(t) ? _t2d_turtle(point, angle) : - is_undef(cmd) ? _t2d_set(t, point, angle) : - is_string(cmd) ? _t2d_cmd(t, cmd, point, angle, leng) : - _t2d_cmds(t, cmd); \ No newline at end of file + is_undef(t) ? _turtle(point, angle) : + is_undef(cmd) ? _set(t, point, angle) : + is_string(cmd) ? _cmd(t, cmd, point, angle, leng) : + _cmds(t, cmd); \ No newline at end of file diff --git a/src/turtle/_impl/_t3d_impl.scad b/src/turtle/_impl/_t3d_impl.scad index 6d996217..5483ebb2 100644 --- a/src/turtle/_impl/_t3d_impl.scad +++ b/src/turtle/_impl/_t3d_impl.scad @@ -1,44 +1,44 @@ use <../../matrix/m_rotation.scad>; -function _t3d_create(pt, unit_vts) = +function _create(pt, unit_vts) = [ is_undef(pt) ? [0, 0, 0] : pt, is_undef(unit_vts) ? [[1, 0, 0], [0, 1, 0], [0, 0, 1]] : unit_vts ]; -function _t3d_pt(turtle) = turtle[0]; -function _t3d_unit_vts(turtle) = turtle[1]; +function _pt(turtle) = turtle[0]; +function _unit_vts(turtle) = turtle[1]; // forward the turtle in the x' direction -function _t3d_xu_forward(turtle, leng) = _t3d_create( - _t3d_pt(turtle) + _t3d_unit_vts(turtle).x * leng, - _t3d_unit_vts(turtle) +function _xu_forward(turtle, leng) = _create( + _pt(turtle) + _unit_vts(turtle).x * leng, + _unit_vts(turtle) ); // forward the turtle in the y' direction -function _t3d_yu_forward(turtle, leng) = _t3d_create( - _t3d_pt(turtle) + _t3d_unit_vts(turtle).y * leng, - _t3d_unit_vts(turtle) +function _yu_forward(turtle, leng) = _create( + _pt(turtle) + _unit_vts(turtle).y * leng, + _unit_vts(turtle) ); // forward the turtle in the z' direction -function _t3d_zu_forward(turtle, leng) = _t3d_create( - _t3d_pt(turtle) + _t3d_unit_vts(turtle).z * leng, - _t3d_unit_vts(turtle) +function _zu_forward(turtle, leng) = _create( + _pt(turtle) + _unit_vts(turtle).z * leng, + _unit_vts(turtle) ); // turn the turtle around the x'-axis // return a new unit vector -function _t3d_xu_turn(turtle, a) = +function _xu_turn(turtle, a) = let( - unit_vts = _t3d_unit_vts(turtle), + unit_vts = _unit_vts(turtle), xu = unit_vts.x, m = m_rotation(a, xu), nyu = m * [each unit_vts.y, 1], nzu = m * [each unit_vts.z, 1] ) - _t3d_create( - _t3d_pt(turtle), + _create( + _pt(turtle), [ xu, [nyu.x, nyu.y, nyu.z], @@ -48,16 +48,16 @@ function _t3d_xu_turn(turtle, a) = // turn the turtle around the y'-axis // return a new unit vector -function _t3d_yu_turn(turtle, a) = +function _yu_turn(turtle, a) = let( - unit_vts = _t3d_unit_vts(turtle), + unit_vts = _unit_vts(turtle), yu = unit_vts.y, m = m_rotation(a, yu), nxu = m * [each unit_vts.x, 1], nzu = m * [each unit_vts.z, 1] ) - _t3d_create( - _t3d_pt(turtle), + _create( + _pt(turtle), [ [nxu.x, nxu.y, nxu.z], yu, @@ -67,16 +67,16 @@ function _t3d_yu_turn(turtle, a) = // turn the turtle around the z'-axis // return a new unit vector -function _t3d_zu_turn(turtle, a) = +function _zu_turn(turtle, a) = let( - unit_vts = _t3d_unit_vts(turtle), + unit_vts = _unit_vts(turtle), zu = unit_vts.z, m = m_rotation(a, zu), nxu = m * [each unit_vts.x, 1], nyu = m * [each unit_vts.y, 1] ) - _t3d_create( - _t3d_pt(turtle), + _create( + _pt(turtle), [ [nxu.x, nxu.y, nxu.z], [nyu.x, nyu.y, nyu.z], @@ -84,57 +84,57 @@ function _t3d_zu_turn(turtle, a) = ] ); -function _t3d_set_point(t, point) = - _t3d_create(point, _t3d_unit_vts(t)); +function _set_point(t, point) = + _create(point, _unit_vts(t)); -function _t3d_set_unit_vectors(t, unit_vectors) = - _t3d_create(_t3d_pt(t), unit_vectors); +function _set_unit_vectors(t, unit_vectors) = + _create(_pt(t), unit_vectors); -function _t3d_get(t, cmd) = - cmd == "point" ? _t3d_pt(t) : - cmd == "unit_vectors" ? _t3d_unit_vts(t) : +function _get(t, cmd) = + cmd == "point" ? _pt(t) : + cmd == "unit_vectors" ? _unit_vts(t) : assert(false, "unknown command"); -function _t3d_set(t, point, unit_vectors) = - !is_undef(point) ? _t3d_set_point(t, point) : - !is_undef(unit_vectors) ? _t3d_set_unit_vectors(t, unit_vectors) : +function _set(t, point, unit_vectors) = + !is_undef(point) ? _set_point(t, point) : + !is_undef(unit_vectors) ? _set_unit_vectors(t, unit_vectors) : assert(false, "no target to set"); -function _t3d_cmd(t, cmd, point, unit_vectors, leng, angle) = - cmd == "forward" || cmd == "xforward" ? _t3d_xu_forward(t, leng) : - cmd == "roll" ? _t3d_xu_turn(t, -angle) : - cmd == "pitch" ? _t3d_yu_turn(t, -angle) : - cmd == "turn" || cmd == "zturn" ? _t3d_zu_turn(t, angle) : - cmd == "xturn" ? _t3d_xu_turn(t, angle) : - cmd == "yturn" ? _t3d_yu_turn(t, angle) : - cmd == "yforward" ? _t3d_yu_forward(t, leng) : - cmd == "zforward" ? _t3d_zu_forward(t, leng) : - _t3d_get(t, cmd); +function _cmd(t, cmd, point, unit_vectors, leng, angle) = + cmd == "forward" || cmd == "xforward" ? _xu_forward(t, leng) : + cmd == "roll" ? _xu_turn(t, -angle) : + cmd == "pitch" ? _yu_turn(t, -angle) : + cmd == "turn" || cmd == "zturn" ? _zu_turn(t, angle) : + cmd == "xturn" ? _xu_turn(t, angle) : + cmd == "yturn" ? _yu_turn(t, angle) : + cmd == "yforward" ? _yu_forward(t, leng) : + cmd == "zforward" ? _zu_forward(t, leng) : + _get(t, cmd); -function _t3d_cmdline(cmd, t, arg) = - is_undef(arg) ? _t3d_get(t, cmd) : - cmd == "forward" || cmd == "xforward" ? _t3d_xu_forward(t, arg) : - cmd == "roll" ? _t3d_xu_turn(t, -arg) : - cmd == "pitch" ? _t3d_yu_turn(t, -arg) : - cmd == "turn" || cmd == "zturn" ? _t3d_zu_turn(t, arg) : - cmd == "point" ? _t3d_set_point(t, point) : - cmd == "xturn" ? _t3d_xu_turn(t, arg) : - cmd == "yturn" ? _t3d_yu_turn(t, arg) : - cmd == "yforward" ? _t3d_yu_forward(t, arg) : - cmd == "zforward" ? _t3d_zu_forward(t, arg) : - cmd == "unit_vectors" ? _t3d_set_unit_vectors(t, unit_vectors) : +function _cmdline(cmd, t, arg) = + is_undef(arg) ? _get(t, cmd) : + cmd == "forward" || cmd == "xforward" ? _xu_forward(t, arg) : + cmd == "roll" ? _xu_turn(t, -arg) : + cmd == "pitch" ? _yu_turn(t, -arg) : + cmd == "turn" || cmd == "zturn" ? _zu_turn(t, arg) : + cmd == "point" ? _set_point(t, point) : + cmd == "xturn" ? _xu_turn(t, arg) : + cmd == "yturn" ? _yu_turn(t, arg) : + cmd == "yforward" ? _yu_forward(t, arg) : + cmd == "zforward" ? _zu_forward(t, arg) : + cmd == "unit_vectors" ? _set_unit_vectors(t, unit_vectors) : assert(false, "unknown command"); -function _t3d_cmds(t, cmds, i = 0) = +function _cmds(t, cmds, i = 0) = i == len(cmds) ? t : let( cmd = cmds[i][0], arg = cmds[i][1] ) - _t3d_cmds(_t3d_cmdline(cmd, t, arg), cmds, i + 1); + _cmds(_cmdline(cmd, t, arg), cmds, i + 1); function _t3d_impl(t, cmd, point, unit_vectors, leng, angle) = - is_undef(t) ? _t3d_create(point, unit_vectors) : - is_undef(cmd) ? _t3d_set(t, point, unit_vectors) : - is_string(cmd) ? _t3d_cmd(t, cmd, point, unit_vectors, leng, angle) : - _t3d_cmds(t, cmd); \ No newline at end of file + is_undef(t) ? _create(point, unit_vectors) : + is_undef(cmd) ? _set(t, point, unit_vectors) : + is_string(cmd) ? _cmd(t, cmd, point, unit_vectors, leng, angle) : + _cmds(t, cmd); \ No newline at end of file diff --git a/src/voxel/_impl/_vx_bezier_impl.scad b/src/voxel/_impl/_vx_bezier_impl.scad index 27dc82d3..a9e5a373 100644 --- a/src/voxel/_impl/_vx_bezier_impl.scad +++ b/src/voxel/_impl/_vx_bezier_impl.scad @@ -1,4 +1,4 @@ -function _vx_bezier_pt3(p1, p2, p3, p4, pts) = +function _pt3(p1, p2, p3, p4, pts) = let( a1 = (p1 + p2) * 0.5, a2 = (p2 + p3) * 0.5, @@ -13,10 +13,9 @@ function _vx_bezier_pt3(p1, p2, p3, p4, pts) = function _vx_bezier3(p1, p2, p3, p4, pts) = let(v = p1 - p4) abs(v.x) < 0.5 && abs(v.y) < 0.5 && abs(v.z) < 0.5 ? - pts : - _vx_bezier_pt3(p1, p2, p3, p4, pts); + pts : _pt3(p1, p2, p3, p4, pts); -function _vx_bezier_pt2(p1, p2, p3, p4, pts) = +function _pt2(p1, p2, p3, p4, pts) = let( a1 = (p1 + p2) * 0.5, a2 = (p2 + p3) * 0.5, @@ -31,5 +30,4 @@ function _vx_bezier_pt2(p1, p2, p3, p4, pts) = function _vx_bezier2(p1, p2, p3, p4, pts) = let(v = p1 - p4) abs(v.x) < 0.5 && abs(v.y) < 0.5 ? - pts : - _vx_bezier_pt2(p1, p2, p3, p4, pts); \ No newline at end of file + pts : _pt2(p1, p2, p3, p4, pts); \ No newline at end of file diff --git a/src/voxel/_impl/_vx_circle_impl.scad b/src/voxel/_impl/_vx_circle_impl.scad index a03564dd..c190029b 100644 --- a/src/voxel/_impl/_vx_circle_impl.scad +++ b/src/voxel/_impl/_vx_circle_impl.scad @@ -1,15 +1,15 @@ -function _vx_circle_y(f, y) = f >= 0 ? y - 1 : y; -function _vx_circle_ddf_y(f, ddf_y) = f >= 0 ? ddf_y + 2 : ddf_y; -function _vx_circle_f(f, ddf_y) = f >= 0 ? f + ddf_y : f; +function _y(f, y) = f >= 0 ? y - 1 : y; +function _ddf_y(f, ddf_y) = f >= 0 ? ddf_y + 2 : ddf_y; +function _f(f, ddf_y) = f >= 0 ? f + ddf_y : f; function _vx_circle(f, ddf_x, ddf_y, x, y, filled) = x >= y ? [] : let( - ny = _vx_circle_y(f, y), - nddf_y = _vx_circle_ddf_y(f, ddf_y), + ny = _y(f, y), + nddf_y = _ddf_y(f, ddf_y), nx = x + 1, nddf_x = ddf_x + 2, - nf = _vx_circle_f(f, ddf_y) + nddf_x + nf = _f(f, ddf_y) + nddf_x ) concat( filled ? diff --git a/src/voxel/_impl/_vx_contour_impl.scad b/src/voxel/_impl/_vx_contour_impl.scad index 408c9ad1..1c20d470 100644 --- a/src/voxel/_impl/_vx_contour_impl.scad +++ b/src/voxel/_impl/_vx_contour_impl.scad @@ -5,7 +5,7 @@ include <../../__comm__/_pt2_hash.scad>; hash = function(p) _pt2_hash(p); -function _vx_contour_corner_value(pts, x, y) = +function _corner_value(pts, x, y) = let( c1 = hashset_has(pts, [x, y - 1], hash = _pt2_hash) || hashset_has(pts, [x - 1, y - 1], hash = _pt2_hash) ? 1 : 0, c2 = hashset_has(pts, [x - 1, y], hash = _pt2_hash) || hashset_has(pts, [x - 1, y + 1], hash = _pt2_hash) ? 2 : 0, @@ -14,31 +14,31 @@ function _vx_contour_corner_value(pts, x, y) = ) c1 + c2 + c3 + c4; -_vx_contour_dir_table = [ +_dir_table = [ [4, 0], [6, 0], [7, 0], // RIGHT [8, 1], [12, 1], [14, 1], // DOWN [2, 2], [3, 2], [11, 2], // UP [1, 3], [9, 3], [13, 3] // LEFT ]; -function _vx_contour_dir(cr_value) = - lookup(cr_value, _vx_contour_dir_table); +function _dir(cr_value) = + lookup(cr_value, _dir_table); function _vx_contour(points) = let( // always start from the left-bottom pt fst = min(points) + [-1, -1] ) - _vx_contour_travel(hashset(points, hash = _pt2_hash), fst, fst); + _travel(hashset(points, hash = _pt2_hash), fst, fst); -_vx_contour_nxt_offset = [ +_nxt_offset = [ [1, 0], // RIGHT [0, -1], // DOWN [0, 1], // UP [-1, 0] // LEFT ]; -function _vx_contour_travel(pts, p, fst) = +function _travel(pts, p, fst) = let( - dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p.x, p.y)), - nxt_p = p + _vx_contour_nxt_offset[dir_i] + dir_i = _dir(_corner_value(pts, p.x, p.y)), + nxt_p = p + _nxt_offset[dir_i] ) - nxt_p == fst ? [p] : [p, each _vx_contour_travel(pts, nxt_p, fst)]; + nxt_p == fst ? [p] : [p, each _travel(pts, nxt_p, fst)]; diff --git a/src/voxel/_impl/_vx_curve_impl.scad b/src/voxel/_impl/_vx_curve_impl.scad index 1d738d76..ddac959a 100644 --- a/src/voxel/_impl/_vx_curve_impl.scad +++ b/src/voxel/_impl/_vx_curve_impl.scad @@ -2,11 +2,8 @@ use <../vx_bezier.scad>; function _vx_catmull_rom_spline_4pts(points, tightness) = let( - p1x_0tightness = (points[2] - points[0]) / 4 + points[1], - v_p1x = points[1] - p1x_0tightness, - p1x = p1x_0tightness + v_p1x * tightness, - p2x_0tightness = (points[1] - points[3]) / 4 + points[2], - v_p2x = points[2] - p2x_0tightness, - p2x = p2x_0tightness + v_p2x * tightness + p1 = points[1], + p2 = points[2], + t = (tightness - 1) / 4 ) - vx_bezier(points[1], p1x, p2x, points[2]); \ No newline at end of file + vx_bezier(p1, (points[0] - p2) * t + p1, (points[3] - p1) * t + p2, p2); \ No newline at end of file diff --git a/src/voxel/_impl/_vx_cylinder_impl.scad b/src/voxel/_impl/_vx_cylinder_impl.scad index 22e0993d..93a78d98 100644 --- a/src/voxel/_impl/_vx_cylinder_impl.scad +++ b/src/voxel/_impl/_vx_cylinder_impl.scad @@ -1,4 +1,4 @@ -function _vx_cylinder_vx_circle(radius, filled, thickness) = +function _vx_circle(radius, filled, thickness) = let(range = [-radius: radius - 1], powr = radius ^ 2) filled ? [ for(y = range, x = range) @@ -15,22 +15,22 @@ function _vx_cylinder_vx_circle(radius, filled, thickness) = if(pow_leng < powr && pow_leng > ishell) v ]; -function _vx_cylinder_diff_r(r, h, filled, thickness) = +function _diff_r(r, h, filled, thickness) = let( r1 = r[0], r2 = r[1] ) - r1 == r2 ? _vx_cylinder_same_r(r1, h, filled, thickness) : + r1 == r2 ? _same_r(r1, h, filled, thickness) : let(dr = (r2 - r1) / (h - 1)) [ for(i = 0; i < h; i = i + 1) let(r = round(r1 + dr * i)) - for(pt = _vx_cylinder_vx_circle(r, filled, thickness)) + for(pt = _vx_circle(r, filled, thickness)) [each pt, i] ]; -function _vx_cylinder_same_r(r, h, filled, thickness) = - let(c = _vx_cylinder_vx_circle(r, filled, thickness)) +function _same_r(r, h, filled, thickness) = + let(c = _vx_circle(r, filled, thickness)) [ for(i = 0; i < h; i = i + 1) for(pt = c) [each pt, i] @@ -38,5 +38,5 @@ function _vx_cylinder_same_r(r, h, filled, thickness) = function _vx_cylinder_impl(r, h, filled, thickness) = is_num(r) ? - _vx_cylinder_same_r(r, h, filled, thickness) : - _vx_cylinder_diff_r(r, h, filled, thickness); \ No newline at end of file + _same_r(r, h, filled, thickness) : + _diff_r(r, h, filled, thickness); \ No newline at end of file diff --git a/src/voxel/_impl/_vx_from_impl.scad b/src/voxel/_impl/_vx_from_impl.scad index b57d45c0..57343de9 100644 --- a/src/voxel/_impl/_vx_from_impl.scad +++ b/src/voxel/_impl/_vx_from_impl.scad @@ -1,4 +1,4 @@ -function _vx_from_row(r_count, row_bits, width, height, center, invert) = +function _row(r_count, row_bits, width, height, center, invert) = let( half_w = width / 2, half_h = height / 2, @@ -17,5 +17,5 @@ function _vx_from_impl(binaries, center, invert) = ) [ for(i = height - 1; i > -1; i = i - 1) - each _vx_from_row(height - i - 1, binaries[i], width, height, center, invert) + each _row(height - i - 1, binaries[i], width, height, center, invert) ]; \ No newline at end of file diff --git a/src/voxel/_impl/_vx_gray_impl.scad b/src/voxel/_impl/_vx_gray_impl.scad index 3600083a..aad31b00 100644 --- a/src/voxel/_impl/_vx_gray_impl.scad +++ b/src/voxel/_impl/_vx_gray_impl.scad @@ -1,4 +1,4 @@ -function _vx_gray_row(r_count, row_bits, width, height, center, invert, normalize) = +function _row(r_count, row_bits, width, height, center, invert, normalize) = let( half_w = width / 2, half_h = height / 2, @@ -25,5 +25,5 @@ function _vx_gray_impl(levels, center, invert, normalize) = ) [ for(i = height - 1; i > -1; i = i - 1) - each _vx_gray_row(height - i - 1, levels[i], width, height, center, invert, normalize) + each _row(height - i - 1, levels[i], width, height, center, invert, normalize) ]; \ No newline at end of file diff --git a/src/voxel/_impl/_vx_line_impl.scad b/src/voxel/_impl/_vx_line_impl.scad index 89324078..585087bc 100644 --- a/src/voxel/_impl/_vx_line_impl.scad +++ b/src/voxel/_impl/_vx_line_impl.scad @@ -3,12 +3,12 @@ use <../../__comm__/__to3d.scad>; use <../../__comm__/__to2d.scad>; // x-dominant -function _vx_line_xdominant_y(y, yd, sy) = yd >= 0 ? y + sy : y; -function _vx_line_xdominant_yd(yd, ax, ay) = (yd >= 0 ? yd - ax : yd) + ay; -function _vx_line_xdominant_z(z, zd, sz) = zd >= 0 ? z + sz : z; -function _vx_line_xdominant_zd(zd, ax, az) = (zd >= 0 ? zd - ax : zd) + az; +function _xdominant_y(y, yd, sy) = yd >= 0 ? y + sy : y; +function _xdominant_yd(yd, ax, ay) = (yd >= 0 ? yd - ax : yd) + ay; +function _xdominant_z(z, zd, sz) = zd >= 0 ? z + sz : z; +function _xdominant_zd(zd, ax, az) = (zd >= 0 ? zd - ax : zd) + az; -function _vx_line_xdominant(start, end, a, s) = +function _xdominant(start, end, a, s) = let( shrx = floor(a.x / 2), yd = a.y - shrx, @@ -16,40 +16,40 @@ function _vx_line_xdominant(start, end, a, s) = ) [ start, - each _vx_line_xdominant_sub( + each _xdominant_sub( start.x + s.x, - _vx_line_xdominant_y(start.y, yd, s.y), - _vx_line_xdominant_z(start.z, zd, s.z), + _xdominant_y(start.y, yd, s.y), + _xdominant_z(start.z, zd, s.z), end.x, a, s, - _vx_line_xdominant_yd(yd, a.x, a.y), - _vx_line_xdominant_zd(zd, a.x, a.z) + _xdominant_yd(yd, a.x, a.y), + _xdominant_zd(zd, a.x, a.z) ) ]; -function _vx_line_xdominant_sub(x, y, z, endx, a, s, yd, zd) = +function _xdominant_sub(x, y, z, endx, a, s, yd, zd) = x == endx ? [] : [ [x, y, z], - each _vx_line_xdominant_sub( + each _xdominant_sub( x + s.x, - _vx_line_xdominant_y(y, yd, s.y), - _vx_line_xdominant_z(z, zd, s.z), + _xdominant_y(y, yd, s.y), + _xdominant_z(z, zd, s.z), endx, a, s, - _vx_line_xdominant_yd(yd, a.x, a.y), - _vx_line_xdominant_zd(zd, a.x, a.z) + _xdominant_yd(yd, a.x, a.y), + _xdominant_zd(zd, a.x, a.z) ) ]; // y-dominant -function _vx_line_ydominant_x(x, xd, sx) = xd >= 0 ? x + sx : x; -function _vx_line_ydominant_xd(xd, ax, ay) = (xd >= 0 ? xd - ay : xd) + ax; -function _vx_line_ydominant_z(z, zd, sz) = zd >= 0 ? z + sz : z; -function _vx_line_ydominant_zd(zd, ay, az) = (zd >= 0 ? zd - ay : zd) + az; +function _ydominant_x(x, xd, sx) = xd >= 0 ? x + sx : x; +function _ydominant_xd(xd, ax, ay) = (xd >= 0 ? xd - ay : xd) + ax; +function _ydominant_z(z, zd, sz) = zd >= 0 ? z + sz : z; +function _ydominant_zd(zd, ay, az) = (zd >= 0 ? zd - ay : zd) + az; -function _vx_line_ydominant(start, end, a, s) = +function _ydominant(start, end, a, s) = let( shry = floor(a.y / 2), xd = a.x - shry, @@ -57,41 +57,41 @@ function _vx_line_ydominant(start, end, a, s) = ) [ start, - each _vx_line_ydominant_sub( - _vx_line_ydominant_x(start.x, xd, s.x), + each _ydominant_sub( + _ydominant_x(start.x, xd, s.x), start.y + s.y, - _vx_line_ydominant_z(start.z, zd, s.z), + _ydominant_z(start.z, zd, s.z), end.y, a, s, - _vx_line_ydominant_xd(xd, a.x, a.y), - _vx_line_ydominant_zd(zd, a.y, a.z) + _ydominant_xd(xd, a.x, a.y), + _ydominant_zd(zd, a.y, a.z) ) ]; -function _vx_line_ydominant_sub(x, y, z, endy, a, s, xd, zd) = +function _ydominant_sub(x, y, z, endy, a, s, xd, zd) = y == endy ? [] : [ [x, y, z], - each _vx_line_ydominant_sub( - _vx_line_ydominant_x(x, xd, s.x), + each _ydominant_sub( + _ydominant_x(x, xd, s.x), y + s.y, - _vx_line_ydominant_z(z, zd, s.z), + _ydominant_z(z, zd, s.z), endy, a, s, - _vx_line_ydominant_xd(xd, a.x, a.y), - _vx_line_ydominant_zd(zd, a.y, a.z) + _ydominant_xd(xd, a.x, a.y), + _ydominant_zd(zd, a.y, a.z) ) ]; // z-dominant -function _vx_line_zdominant_x(x, xd, sx) = xd >= 0 ? x + sx : x; -function _vx_line_zdominant_xd(xd, ax, az) = (xd >= 0 ? xd - az : xd) + ax; +function _zdominant_x(x, xd, sx) = xd >= 0 ? x + sx : x; +function _zdominant_xd(xd, ax, az) = (xd >= 0 ? xd - az : xd) + ax; -function _vx_line_zdominant_y(y, yd, sy) = yd >= 0 ? y + sy : y; -function _vx_line_zdominant_yd(yd, ay, az) = (yd >= 0 ? yd - az : yd) + ay; +function _zdominant_y(y, yd, sy) = yd >= 0 ? y + sy : y; +function _zdominant_yd(yd, ay, az) = (yd >= 0 ? yd - az : yd) + ay; -function _vx_line_zdominant(start, end, a, s) = +function _zdominant(start, end, a, s) = let( shrz = floor(a.z / 2), xd = a.x - shrz, @@ -99,30 +99,30 @@ function _vx_line_zdominant(start, end, a, s) = ) [ start, - each _vx_line_zdominant_sub( - _vx_line_zdominant_x(start.x, xd, s.x), - _vx_line_zdominant_y(start.y, yd, s.y), + each _zdominant_sub( + _zdominant_x(start.x, xd, s.x), + _zdominant_y(start.y, yd, s.y), start.z + s.z, end.z, a, s, - _vx_line_zdominant_xd(xd, a.x, a.z), - _vx_line_zdominant_yd(yd, a.y, a.z) + _zdominant_xd(xd, a.x, a.z), + _zdominant_yd(yd, a.y, a.z) ) ]; -function _vx_line_zdominant_sub(x, y, z, endz, a, s, xd, yd) = +function _zdominant_sub(x, y, z, endz, a, s, xd, yd) = z == endz ? [] : [ [x, y, z], - each _vx_line_zdominant_sub( - _vx_line_zdominant_x(x, xd, s.x), - _vx_line_zdominant_y(y, yd, s.y), + each _zdominant_sub( + _zdominant_x(x, xd, s.x), + _zdominant_y(y, yd, s.y), z + s.z, endz, a, s, - _vx_line_zdominant_xd(xd, a.x, a.z), - _vx_line_zdominant_yd(yd, a.y, a.z) + _zdominant_xd(xd, a.x, a.z), + _zdominant_yd(yd, a.y, a.z) ) ]; @@ -134,8 +134,8 @@ function _vx_line_impl(p1, p2) = dt = end_pt - start_pt, a = [for(c = dt) floor(abs(c) * 2)], s = [for(c = dt) sign(c)], - points = a.x >= max(a.y, a.z) ? _vx_line_xdominant(start_pt, end_pt, a, s) : - a.y >= max(a.x, a.z) ? _vx_line_ydominant(start_pt, end_pt, a, s) : - _vx_line_zdominant(start_pt, end_pt, a, s) + points = a.x >= max(a.y, a.z) ? _xdominant(start_pt, end_pt, a, s) : + a.y >= max(a.x, a.z) ? _ydominant(start_pt, end_pt, a, s) : + _zdominant(start_pt, end_pt, a, s) ) is_2d ? [for(pt = points) __to2d(pt)] : points; \ No newline at end of file