1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-09-25 05:51:41 +02:00

use [each lt, v] to replace concat(lt, [v])

This commit is contained in:
Justin Lin
2022-02-27 22:02:51 +08:00
parent 042feb4951
commit 8dc6336f2f
57 changed files with 194 additions and 266 deletions

View File

@@ -34,16 +34,16 @@ function m_assign(m, i, j, v) =
lt = m[i],
leng_lt = len(lt),
nlt = [
each (j == 0 ? [] : [for(idx = [0:j - 1]) lt[idx]]),
if(j != 0) each [for(idx = [0:j - 1]) lt[idx]],
v,
each (j == leng_lt - 1 ? [] : [for(idx = [j + 1:leng_lt - 1]) lt[idx]])
if(j != leng_lt - 1) each [for(idx = [j + 1:leng_lt - 1]) lt[idx]]
],
leng_m = len(m)
)
[
each (i == 0 ? [] : [for(idx = [0:i - 1]) m[idx]]),
if(i != 0) each [for(idx = [0:i - 1]) m[idx]],,
nlt,
each (i == leng_m - 1 ? [] : [for(idx = [i + 1:leng_m - 1]) m[idx]])
if(i != leng_m - 1) each [for(idx = [i + 1:leng_m - 1]) m[idx]]
];
function next_vis(i, pts, cur_faces, cur_faces_leng, next, vis, j = 0) =

View File

@@ -11,10 +11,7 @@ function _find_radians(b, point_distance, radians, n, count = 1) =
_find_radians(
b,
point_distance,
concat(
radians,
[pre_radians + _radian_step(b, pre_radians, point_distance)]
),
[each radians, pre_radians + _radian_step(b, pre_radians, point_distance)],
n,
count + 1)
);

View File

@@ -54,11 +54,5 @@ function _bezier_curve_point3(t, points) =
function _bezier_curve_impl(t_step, points) =
let(t_end = ceil(1 / t_step))
len(points[0]) == 3 ?
concat([
for(t = 0; t < t_end; t = t + 1)
_bezier_curve_point3(t * t_step, points)
], [_bezier_curve_point3(1, points)]) :
concat([
for(t = 0; t < t_end; t = t + 1)
_bezier_curve_point2(t * t_step, points)
], [_bezier_curve_point2(1, points)]);
[each [for(t = 0; t < t_end; t = t + 1) _bezier_curve_point3(t * t_step, points)], _bezier_curve_point3(1, points)] :
[each [for(t = 0; t < t_end; t = t + 1) _bezier_curve_point2(t * t_step, points)], _bezier_curve_point2(1, points)];

View File

@@ -54,11 +54,6 @@ function _bezier_smooth_impl(path_pts, round_d, t_step, closed, angle_threshold)
[pts[leng - 2], pts[leng - 1], pts[0]],
round_d, t_step, 3, angle_threshold
)
) :
concat(
[pts[0]],
middle_pts,
[pts[leng - 1]]
)
) : [pts[0], each middle_pts, pts[leng - 1]]
)
len(path_pts[0]) == 2 ? [for(p = pth_pts) __to2d(p)] : pth_pts;

View File

@@ -40,9 +40,9 @@ function _bijection_offset_impl(pts, d, epsilon) =
leng_minus_one = leng - 1,
last_p = __line_intersection2(offset_es[leng_minus_one], offset_es[0], epsilon)
)
concat(
last_p != [] && last_p == last_p ? [last_p] : [],
[
[
if(last_p != [] && last_p == last_p) last_p,
each [
for(i = 0; i < leng_minus_one; i = i + 1)
let(
this_edge = offset_es[i],
@@ -53,5 +53,5 @@ function _bijection_offset_impl(pts, d, epsilon) =
)
p
]
);
];

View File

@@ -54,7 +54,7 @@ function _bspline_curve_interpolate(t, degree, points, knots, weights) =
v = [
for(i = 0; i < n; i = i + 1)
let(p = points[i] * wts[i])
concat([for(j = 0; j < d; j = j + 1) p[j]], [wts[i]])
[each [for(j = 0; j < d; j = j + 1) p[j]], wts[i]]
],
ts = _bspline_curve_ts(t, degree, kts),
s = ts[1],

View File

@@ -1,11 +1,11 @@
function _midpt_smooth_sub(points, iend, closed) =
concat(
[
[
each [
for(i = 0; i < iend; i = i + 1)
(points[i] + points[i + 1]) / 2
],
closed ? [(points[iend] + points[0]) / 2] : []
);
if(closed) (points[iend] + points[0]) / 2
];
function _midpt_smooth_impl(points, n, closed) =
let(

View File

@@ -73,6 +73,6 @@ function _shape_path_extend_impl(stroke_pts, path_pts, scale, closed) =
closed && path_pts[0] == path_pts[leng_path_pts - 1] ?
__polytransversals(concat(strokes, [strokes[0]])) :
__polytransversals(
concat([_shape_path_first_stroke(stroke_pts, path_pts)], strokes)
[_shape_path_first_stroke(stroke_pts, path_pts), each strokes]
);

View File

@@ -23,13 +23,12 @@ function _trim_sub(lines, leng, epsilon) =
inter_p = _trim_shape_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 == [] ? (concat([current_p], _trim_shape_trim_lines(lines_from_next, epsilon))) : (
inter_p == [] ? [current_p, each _trim_shape_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
concat([current_p, inter_p.y],
_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_shape_trim_lines([for(i = inter_p.x + 1; i < leng_lines_from_next2; i = i + 1) lines_from_next2[i]], epsilon)]
)
);
@@ -38,7 +37,7 @@ function _trim_shape_trim_lines(lines, epsilon) =
leng > 2 ? _trim_sub(lines, leng, epsilon) : _trim_shape_collect_pts_from(lines, leng);
function _trim_shape_collect_pts_from(lines, leng) =
concat([for(line = lines) line[0]], [lines[leng - 1][1]]);
[each [for(line = lines) line[0]], lines[leng - 1][1]];
function _trim_shape_impl(shape_pts, from, to, epsilon) =
let(

View File

@@ -18,10 +18,9 @@ function arc_path(radius, angle) =
angles = is_num(angle) ? [0, angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
points = concat([__ra_to_xy(__edge_r_begin(radius, angles[0], a_step, m), angles[0])],
m > n ? [] : [
for(i = m; i <= n; i = i + 1)
__ra_to_xy(radius, a_step * i)
],
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(radius, angles[1], a_step, n), angles[1])])
points = [
__ra_to_xy(__edge_r_begin(radius, angles[0], a_step, m), angles[0]),
if(m <= n) each [for(i = m; i <= n; i = i + 1) __ra_to_xy(radius, a_step * i)],
if(angles[1] != a_step * n) __ra_to_xy(__edge_r_end(radius, angles[1], a_step, n), angles[1])
]
) points;

View File

@@ -12,13 +12,13 @@ use <_impl/_catmull_rom_spline.scad>;
function curve(t_step, points, tightness = 0) =
let(leng = len(points))
concat(
[
[
each [
for(i = [0:leng - 4])
let(
pts = _catmull_rom_spline_4pts(t_step, [for(j = [i:i + 3]) points[j]], tightness)
)
for(i = [0:len(pts) - 2]) pts[i]
],
[points[leng - 2]]
);
points[leng - 2]
];

View File

@@ -30,14 +30,8 @@ module ellipse_extrude(semi_minor_axis, height, center = false, convexity = 10,
pre_f * f_extrude[i][0]
];
child_fs = concat([1], accm_fs);
pre_zs = concat(
[0],
[
for(i = 0; i < len_f_extrude; i = i + 1)
f_extrude[i][1]
]
);
child_fs = [1, each accm_fs];
pre_zs = [0, each [for(i = 0; i < len_f_extrude; i = i + 1) f_extrude[i][1]]];
module extrude() {
for(i = [0:len_f_extrude - 1]) {

View File

@@ -91,7 +91,7 @@ function gyroid_points(pp, w)=
// pp=number of rows
function gyroid_faces(pp)=
let(zs=(pp+1)*(pp+1)) // starting index of down wall points
concat( // calculate face index vetros for triangles of polyhedron
// calculate face index vetros for triangles of polyhedron
[ for(i=[0:pp-1]) // for every row
let(jm=i*(i+1)) // middle point index for current j vector
let(jfm=(i+1)*(i+2)) // middle point index for succeeding j vector
@@ -103,7 +103,7 @@ function gyroid_faces(pp)=
let(p3=(l==0) ? jfm+(j+1)*k+dm : jm+(j+1)*k+dm)
if (j<i || l==0)
((k==1 && m==0) || (k==-1 && m==1)) ? [p2, p1, p3] : [p1, p2, p3]
]);
];
// Swaps x and y coordinate of all members in matrix m. Applied on a faces matrix for polyhedron creation, it swaps inside out.
function swap_xy(m)=

View File

@@ -3,7 +3,7 @@ use <lines_intersection.scad>;
function _intersection_ps(shape, line_pts, epsilon) =
let(
leng = len(shape),
pts = concat(shape, [shape[0]])
pts = [each shape, shape[0]]
)
[
for(i = [0:leng - 1])

View File

@@ -252,13 +252,12 @@ function tilemap_generate(tm) =
], x, y));
function neighbor_dirs(x, y, width, height) =
concat(
x > 0 ? [[-1, 0]] : [], // left
x < width - 1 ? [[ 1, 0]] : [], // right
y > 0 ? [[ 0, -1]] : [], // top
y < height - 1 ? [[ 0, 1]] : [] // bottom
);
function neighbor_dirs(x, y, width, height) = [
if(x > 0) [-1, 0], // left
if(x < width - 1) [ 1, 0], // right
if(y > 0) [ 0, -1], // top
if(y < height - 1) [ 0, 1] // bottom
];
function neighbor_compatibilities(sample, x, y, width, height) =
let(me = sample[y][x])

View File

@@ -7,7 +7,7 @@ function convex_intersection(shape1, shape2, epsilon = 0.0001) =
(shape1 == [] || shape2 == []) ? [] :
let(
leng = len(shape1),
pts = concat(shape1, [shape1[0]])
pts = [each shape1, shape1[0]]
)
convex_ct_clk_order(
concat(

View File

@@ -29,7 +29,7 @@ module hollow_out_sweep(sections, diameter, closed = false, style = "LINES") {
[[rect[0], rect[1], rect[2]], [rect[0], rect[2], rect[3]]] :
[[rect[1], rect[2], rect[3]], [rect[1], rect[3], rect[0]]];
sects = closed ? concat(sections, [sections[0]]) : sections;
sects = closed ? [each sections, sections[0]] : sections;
lines = [
for(rect = rects(sects))
for(tri = rand_tris(rect))

View File

@@ -67,9 +67,9 @@ function sub_dart(tile) =
n_size = tile_size(tile) / PHI,
r = PHI * size
)
concat(
[tile(KITE, x, y, between_360(angle + 5 * 36), n_size)],
[
[
tile(KITE, x, y, between_360(angle + 5 * 36), n_size),
each [
for(i = 0, sign = 1; i < 2; i = i + 1, sign = -sign)
let(a = between_360(angle - 4 * 36 * sign))
tile(
@@ -80,7 +80,7 @@ function sub_dart(tile) =
n_size
)
]
);
];
function subdivide(tiles) = [
for(tile = tiles)
@@ -114,9 +114,9 @@ function tile_penrose2(n, triangles) =
angle = tile_angle(tile) - 36,
type = tile_type(tile),
size = tile_size(tile),
shape = concat(
[[tile_x(tile), tile_y(tile)]],
[
shape = [
[tile_x(tile), tile_y(tile)],
each [
for(i = [0:2])
let(
r = dist[type][i] * size,
@@ -124,7 +124,7 @@ function tile_penrose2(n, triangles) =
)
[tile_x(tile) + r * cos(a), tile_y(tile) + r * sin(a)]
]
)
]
)
each [
[type, [shape[0], shape[1], shape[2]]],

View File

@@ -25,7 +25,7 @@ function _sub_obtuse(a, b, c) =
PHI = 1.618033988749895,
r = b + (c - b) / PHI
)
concat([["OBTUSE", r, c, a]], _sub_acute(b, a, r));
[["OBTUSE", r, c, a], each _sub_acute(b, a, r)];
function _penrose3(triangles, n, i = 0) =
i == n ? triangles :

View File

@@ -59,13 +59,7 @@ module hexagons(radius, spacing, levels) {
[[hex_datum[0][0], -hex_datum[0][1]], hex_datum[1]]
] : [];
total_hex_data = concat(
[
[[0, 0], beginning_n] // first line
],
upper_hex_data,
lower_hex_data
);
total_hex_data = [[[0, 0], beginning_n], each upper_hex_data, each lower_hex_data];
pts_all_lines = [
for(hex_datum = total_hex_data)

View File

@@ -29,11 +29,7 @@ module loft(sections, slices = 1) {
p1 = sect[i],
p2 = sect[(i + 1) % leng]
)
concat(
[p1],
inter_pts(p1, p2, n),
_interpolate(sect, leng, n, i + 1)
);
[p1, each inter_pts(p1, p2, n), each _interpolate(sect, leng, n, i + 1)];
function interpolate(sect, n) =
n <= 1 ? sect : _interpolate(sect, len(sect), n);
@@ -53,13 +49,7 @@ module loft(sections, slices = 1) {
new_sect1 = interpolate(sect1, lcm_n / len(sect1));
new_sect2 = interpolate(sect2, lcm_n / len(sect2));
sweep(
concat(
[new_sect1],
inter_sects(new_sect1, new_sect2, lcm_n, slices),
[new_sect2]
)
);
sweep([new_sect1, each inter_sects(new_sect1, new_sect2, lcm_n, slices), new_sect2]);
}
for(i = [0:len(sections) - 2]) {

View File

@@ -51,6 +51,4 @@ function _mz_hamiltonian_travel(dot_pts, p, leng, i = 0) =
dir_i = _mz_hamiltonian_dir(_mz_hamiltonian_corner_value(dot_pts, p.x, p.y)),
nxt_p = p + _mz_hamiltonian_nxt_offset[dir_i]
)
concat(
[p], _mz_hamiltonian_travel(dot_pts, nxt_p, leng, i + 1)
);
[p, each _mz_hamiltonian_travel(dot_pts, nxt_p, leng, i + 1)];

View File

@@ -32,7 +32,7 @@ function set_outwards(cell, outwards) = [
function get_outwards(cell) = cell[5];
function add_outward(cell, outward) = [
cell[0], cell[1], cell[2], cell[3], cell[4], concat(get_outwards(cell), [outward]), cell[6], cell[7]
cell[0], cell[1], cell[2], cell[3], cell[4], [each get_outwards(cell), outward], cell[6], cell[7]
];
function columnLengOfRow(ri, cellWidth, previousColumnLeng, dividedRatio) =
@@ -63,7 +63,7 @@ function _init_theta_maze(ri, maze, totalRows, dividedRatio, cellWidth) =
cell(ri, ci, INWARD_CCW_WALL)
]
)
_init_theta_maze(ri + 1, concat(maze, [row]), totalRows, dividedRatio, cellWidth);
_init_theta_maze(ri + 1, [each maze, row], totalRows, dividedRatio, cellWidth);
function update_maze_row(row, cell) =
let(leng = len(row))

View File

@@ -26,7 +26,7 @@ function _nz_cell_border(cells, p) =
let(
dists = [
for(i = [0:len(cells) - 1])
concat(cells[i], [norm(cells[i] - p)])
[each cells[i], norm(cells[i] - p)]
],
idx = len(cells[0]),
sorted = sort(dists, by = "idx", idx = idx),

View File

@@ -89,7 +89,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
curr_matrix = rot_matrice[i],
prev_matrix = matrice[len(matrice) - 1]
)
concat(matrice, [curr_matrix * prev_matrix]);
[each matrice, curr_matrix * prev_matrix];
cumu_rot_matrice = cumulated_rot_matrice(0);
@@ -137,11 +137,11 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
pth_pts[i + 1]
)
]
) concat([fst_section], remain_sections);
) [fst_section, each remain_sections];
calculated_sections =
closed && pth_pts[0] == pth_pts[len_path_pts_minus_one] ?
concat(sections, [sections[0]]) : // round-robin
[each sections, sections[0]] : // round-robin
sections;
sweep(
@@ -186,8 +186,8 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
calculated_sections =
closed && pth_pts[0] == pth_pts[len_path_pts_minus_one] ?
concat(path_extrude_inner, [path_extrude_inner[0]]) : // round-robin
concat([section(pth_pts[0], pth_pts[1], 0)], path_extrude_inner);
[each path_extrude_inner, path_extrude_inner[0]] : // round-robin
[section(pth_pts[0], pth_pts[1], 0), each path_extrude_inner];
sweep(
calculated_sections,

View File

@@ -5,8 +5,8 @@ function geom_star(outerRadius = 1, innerRadius = 0.381966, height = 0.5, n = 5
half_thetaStep = thetaStep / 2,
half_height = height / 2,
leng_star = n * 2,
points = concat(
[
points = [
each [
for(i = [0:n - 1])
let(
a = thetaStep * i + right,
@@ -15,8 +15,9 @@ function geom_star(outerRadius = 1, innerRadius = 0.381966, height = 0.5, n = 5
)
each [outerPoint, innerPoint]
],
[[0, 0, half_height], [0, 0, -half_height]]
),
[0, 0, half_height],
[0, 0, -half_height]
],
faces = [
for(i = [0:leng_star - 1])
each [[leng_star, (i + 1) % leng_star, i], [i, (i + 1) % leng_star, leng_star + 1]]

View File

@@ -31,24 +31,17 @@ module ring_extrude(shape_pts, radius, angle = 360, twist = 0, scale = 1.0, tria
begin_r = leng / cos((m - 0.5) * a_step - angles[0]);
end_r = leng / cos((n + 0.5) * a_step - angles[1]);
angs = concat(
[[90, 0, angles[0]]],
m > n ? [] : [for(i = [m:n]) [90, 0, a_step * i]]
);
pts = concat(
[__ra_to_xy(begin_r, angles[0])],
m > n ? [] : [for(i = [m:n]) __ra_to_xy(radius, a_step * i)]
);
angs = [[90, 0, angles[0]], each (m > n ? [] : [for(i = [m:n]) [90, 0, a_step * i]])];
pts = [__ra_to_xy(begin_r, angles[0]), each (m > n ? [] : [for(i = [m:n]) __ra_to_xy(radius, a_step * i)])];
is_angle_frag_end = angs[len(angs) - 1][2] == angles[1];
all_angles = is_angle_frag_end ?
angs :
concat(angs, [[90, 0, angles[1]]]);
angs : [each angs, [90, 0, angles[1]]];
all_points = is_angle_frag_end ?
pts :
concat(pts, [__ra_to_xy(end_r, angles[1])]);
pts : [each pts, __ra_to_xy(end_r, angles[1])];
sections = cross_sections(shape_pts, all_points, all_angles, twist, scale);

View File

@@ -13,11 +13,7 @@ use <__comm__/__half_trapezium.scad>;
module rounded_cylinder(radius, h, round_r, convexity = 2, center = false) {
r_corners = __half_trapezium(radius, h, round_r);
shape_pts = concat(
[[0, -h/2]],
r_corners,
[[0, h/2]]
);
shape_pts = [[0, -h/2], each r_corners, [0, h/2]];
center_pt = center ? [0, 0, 0] : [0, 0, h/2];

View File

@@ -23,21 +23,19 @@ function shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
n = floor(angles[1] / a_step),
r_outer = radius + w_offset[0],
r_inner = radius + w_offset[1],
points = concat(
points = [
// outer arc path
[__ra_to_xy(__edge_r_begin(r_outer, angles[0], a_step, m), angles[0])],
m > n ? [] : [
for(i = m; i <= n; i = i + 1) __ra_to_xy(r_outer, a_step * i)
],
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(r_outer, angles[1], a_step, n), angles[1])],
__ra_to_xy(__edge_r_begin(r_outer, angles[0], a_step, m), angles[0]),
if(m <= n) each [for(i = m; i <= n; i = i + 1) __ra_to_xy(r_outer, a_step * i)],
if(angles[1] != a_step * n) __ra_to_xy(__edge_r_end(r_outer, angles[1], a_step, n), angles[1]),
// inner arc path
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(r_inner, angles[1], a_step, n), angles[1])],
m > n ? [] : [
if(angles[1] != a_step * n) __ra_to_xy(__edge_r_end(r_inner, angles[1], a_step, n), angles[1]),
if(m <= n) each [
for(i = m; i <= n; i = i + 1)
let(idx = (n + (m - i)))
__ra_to_xy(r_inner, a_step * idx)
let(idx = (n + (m - i)))
__ra_to_xy(r_inner, a_step * idx)
],
[__ra_to_xy(__edge_r_begin(r_inner, angles[0], a_step, m), angles[0])]
)
__ra_to_xy(__edge_r_begin(r_inner, angles[0], a_step, m), angles[0])
]
) points;

View File

@@ -20,13 +20,14 @@ function shape_pie(radius, angle) =
n = floor(angles[1] / a_step),
edge_r_begin = leng / cos((m - 0.5) * a_step - angles[0]),
edge_r_end = leng / cos((n + 0.5) * a_step - angles[1]),
shape_pts = concat(
[[0, 0], __ra_to_xy(edge_r_begin, angles[0])],
m > n ? [] : [
shape_pts = [
[0, 0],
__ra_to_xy(edge_r_begin, angles[0]),
if(m <= n) each [
for(i = m; i <= n; i = i + 1)
let(a = a_step * i)
__ra_to_xy(radius, a)
let(a = a_step * i)
__ra_to_xy(radius, a)
],
angles[1] == a_step * n ? [] : [__ra_to_xy(edge_r_end, angles[1])]
)
if(angles[1] != a_step * n) __ra_to_xy(edge_r_end, angles[1])
]
) shape_pts;

View File

@@ -36,7 +36,7 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH", con
tri = sort(triangles[i], by = ascending),
n_cnt_tris = [
for(k = [0:leng_pts - 1])
find_index(tri, function(e) e == k) != -1 ? concat(cnt_tris[k], [triangles[i]]) : cnt_tris[k]
find_index(tri, function(e) e == k) != -1 ? [each cnt_tris[k], triangles[i]] : cnt_tris[k]
]
)
_connected_tris(triangles, leng, leng_pts, n_cnt_tris, i + 1);

View File

@@ -96,7 +96,7 @@ module sweep(sections, triangles = "SOLID") {
i + leng_pts_sect * (leng_sects - 1)
];
f_idxes = concat([first_idxes], side_indexes(sects), [last_idxes]);
f_idxes = [first_idxes, each side_indexes(sects), last_idxes];
polyhedron(
v_pts,

View File

@@ -156,7 +156,7 @@ function updateNbrs(d, delaunayTri, neighbors, _indices_hash) =
function delaunayAddCoords(d, p) =
[
concat(delaunay_coords(d), [p]),
[each delaunay_coords(d), p],
delaunay_triangles(d),
delaunay_circles(d)
];
@@ -206,10 +206,10 @@ function _delaunayBoundaries(d, badTriangles, boundaries, t, vi, _indices_hash)
)
_delaunayBoundaries(d, badTriangles, boundaries, nt, nvi, _indices_hash) :
let(
nboundaries = concat(boundaries, [[
nboundaries = [each boundaries, [
[t[(vi + 1) % 3], t[vi > 0 ? vi - 1 : (vi + 2)]], // edge
opTri // delaunayTri
]]),
]],
nvi = (vi + 1) % 3,
v1 = nboundaries[0][0][0],
v2 = nboundaries[len(nboundaries) - 1][0][1]

View File

@@ -68,7 +68,7 @@ function _triangulate_snip(shape_pts, collector, indices, u, v, w, num_of_vertic
)
_triangulate_real_triangulate(
shape_pts,
concat(collector, [[a, b, c]]),
[each collector, [a, b, c]],
_triangulate_remove_v(indices, v, num_of_vertices),
v,
new_nv,

View File

@@ -6,4 +6,4 @@ function _footprints2(cmds, t, leng, i = 0) =
nxt = turtle2d(cmds[i][0], t, cmds[i][1]),
pts = _footprints2(cmds, nxt, leng, i + 1)
)
cmds[i][0] != "forward" ? pts : concat([turtle2d("pt", nxt)], pts);
cmds[i][0] != "forward" ? pts : [turtle2d("pt", nxt), each pts];

View File

@@ -6,4 +6,4 @@ function _footprints3(cmds, t, leng, i = 0) =
nxt = turtle3d(cmds[i][0], t, cmds[i][1]),
pts = _footprints3(cmds, nxt, leng, i + 1)
)
cmds[i][0] != "forward" && cmds[i][0] != "yu_move" && cmds[i][0] != "zu_move" ? pts : concat([turtle3d("pt", nxt)], pts);
cmds[i][0] != "forward" && cmds[i][0] != "yu_move" && cmds[i][0] != "zu_move" ? pts : [turtle3d("pt", nxt), each pts];

View File

@@ -8,7 +8,7 @@ function _lsystem2_derive(axiom, rules, n, rule_prs) =
_derive_p(axiom, rules, rule_prs, n);
function _next_stack(t, code, stack) =
code == "[" ? concat([t], stack) :
code == "[" ? [t, each stack] :
let(leng = len(stack))
code == "]" ?
(leng > 1 ? [for(i = [1:leng - 1]) stack[i]] : []) :

View File

@@ -8,7 +8,7 @@ function _lsystem3_derive(axiom, rules, n, rule_prs) =
_derive_p(axiom, rules, rule_prs, n);
function _next_stack(t, code, stack) =
code == "[" ? concat([t], stack) :
code == "[" ? [t, each stack] :
let(leng = len(stack))
code == "]" ?
(leng > 1 ? [for(i = [1:leng - 1]) stack[i]] : []) :

View File

@@ -16,4 +16,4 @@ function footprints2(cmds, start = [0, 0]) =
t = turtle2d("create", start.x, start.y, 0),
leng = len(cmds)
)
concat([turtle2d("pt", t)], _footprints2(cmds, t, leng));
[turtle2d("pt", t), each _footprints2(cmds, t, leng)];

View File

@@ -16,4 +16,4 @@ function footprints3(cmds, start = [0, 0, 0]) =
t = turtle3d("create", start, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
leng = len(cmds)
)
concat([turtle3d("pt", t)], _footprints3(cmds, t, leng));
[turtle3d("pt", t), each _footprints3(cmds, t, leng)];

View File

@@ -15,4 +15,4 @@ function _dedup_add(buckets, i_elem, eq, hash, bucket_numbers) =
function _add(buckets, bucket, i_elem, b_idx) =
let(leng = len(buckets))
[for(i = 0; i < leng; i = i + 1) i == b_idx ? concat(bucket, [i_elem]) : buckets[i]];
[for(i = 0; i < leng; i = i + 1) i == b_idx ? [each bucket, i_elem] : buckets[i]];

View File

@@ -3,7 +3,7 @@ use <../../__comm__/__fast_fibonacci.scad>;
function _fibonacci_sequence(seq, n, i = 2) =
i > n ? seq :
_fibonacci_sequence(
concat(seq, [seq[i - 1] + seq[i - 2]]),
[each seq, seq[i - 1] + seq[i - 2]],
n,
i + 1
);

View File

@@ -8,7 +8,7 @@ function _vt_sort(lt) =
before = [for(j = 1; j < leng; j = j + 1) if(lessThan(lt[j], pivot)) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(greaterThan(lt[j], pivot) || lt[j] == pivot) lt[j]]
)
concat(_vt_sort(before), [pivot], _vt_sort(after));
[each _vt_sort(before), pivot, each _vt_sort(after)];
function _sort_by_idx(lt, i) =
let(leng = len(lt))
@@ -18,7 +18,7 @@ function _sort_by_idx(lt, i) =
before = [for(j = 1; j < leng; j = j + 1) if(lt[j][i] < pivot[i]) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(lt[j][i] >= pivot[i]) lt[j]]
)
concat(_sort_by_idx(before, i), [pivot], _sort_by_idx(after, i));
[each _sort_by_idx(before, i), pivot, each _sort_by_idx(after, i)];
function _sort_by(lt, by, idx) =
let(
@@ -35,4 +35,4 @@ function _sort_by_cmp(lt, cmp) =
before = [for(j = 1; j < leng; j = j + 1) if(cmp(lt[j], pivot) < 0) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(cmp(lt[j], pivot) >= 0) lt[j]]
)
concat(_sort_by_cmp(before, cmp), [pivot], _sort_by_cmp(after, cmp));
[each _sort_by_cmp(before, cmp), pivot, each _sort_by_cmp(after, cmp)];

View File

@@ -2,13 +2,7 @@ use <../sub_str.scad>;
function _split_t_by(idxs, t) =
let(leng = len(idxs))
concat(
[sub_str(t, 0, idxs[0])],
[
for(i = 0; i < leng; i = i + 1)
sub_str(t, idxs[i] + 1, idxs[i + 1])
]
);
[sub_str(t, 0, idxs[0]), each [for(i = 0; i < leng; i = i + 1) sub_str(t, idxs[i] + 1, idxs[i + 1])]];
function _split_str_impl(t, delimiter) =
len(search(delimiter, t)) == 0 ?

View File

@@ -2,6 +2,9 @@ _identity = function(elems) elems;
function _zipAll_sub(lts, list_to, elem_to, combine, i = 0) =
i > elem_to ? [] :
concat([combine([for(j = [0:list_to]) lts[j][i]])], _zipAll_sub(lts, list_to, elem_to, combine, i + 1));
concat(
[combine([for(j = [0:list_to]) lts[j][i]])],
_zipAll_sub(lts, list_to, elem_to, combine, i + 1)
);
function _zipAll(lts, combine = _identity) = _zipAll_sub(lts, len(lts) - 1, len(lts[0]) - 1, combine);

View File

@@ -18,4 +18,4 @@ function _replace(buckets, b_numbers, bucket, key, value, b_idx, k_idx) =
[for(i = 0; i < b_numbers; i = i + 1) i == b_idx ? n_bucket : buckets[i]];
function _put(buckets, b_numbers, bucket, key, value, b_idx) =
[for(i = 0; i < b_numbers; i = i + 1) i == b_idx ? concat(bucket, [[key, value]]) : buckets[i]];
[for(i = 0; i < b_numbers; i = i + 1) i == b_idx ? [each bucket, [key, value]] : buckets[i]];

View File

@@ -8,8 +8,4 @@
*
**/
function hashmap_keys(map) = [
for(bucket = map)
for(kv = bucket)
kv[0]
];
function hashmap_keys(map) = [for(bucket = map, kv = bucket) kv[0]];

View File

@@ -8,8 +8,4 @@
*
**/
function hashmap_values(map) = [
for(bucket = map)
for(kv = bucket)
kv[1]
];
function hashmap_values(map) = [for(bucket = map, kv = bucket) kv[1]];

View File

@@ -8,4 +8,4 @@ function _hashset_add(buckets, b_numbers, elem, eq, hash) =
some(bucket, function(e) eq(e, elem)) ? buckets : _add(buckets, b_numbers, bucket, elem, idx);
function _add(buckets, b_numbers, bucket, elem, idx) =
[for(i = 0; i < b_numbers; i = i + 1) i == idx ? concat(bucket, [elem]) : buckets[i]];
[for(i = 0; i < b_numbers; i = i + 1) i == idx ? [each bucket, elem] : buckets[i]];

View File

@@ -15,10 +15,10 @@ function swap(lt, i, j) =
a = min([i, j]),
b = max([i, j])
)
concat(
a == 0 ? [] : [for(idx = [0:a - 1]) lt[idx]],
[lt[b]],
b - a == 1? [] : [for(idx = [a + 1:b - 1]) lt[idx]],
[lt[a]],
b == leng - 1 ? [] : [for(idx = [b + 1:leng - 1]) lt[idx]]
);
[
each (a == 0 ? [] : [for(idx = [0:a - 1]) lt[idx]]),
lt[b],
each (b - a == 1 ? [] : [for(idx = [a + 1:b - 1]) lt[idx]]),
lt[a],
each (b == leng - 1 ? [] : [for(idx = [b + 1:leng - 1]) lt[idx]])
];

View File

@@ -29,16 +29,13 @@ module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = f
// 21-nearest-neighbor
function _neighbors(fcord, seed, grid_w, gw, gh) =
let(range = [-1:1])
concat(
[
for(y = [-1:1])
for(x = [-1:1])
cell_pt(fcord, seed, x, y, gw, gh)
],
[for(x = [-1:1]) cell_pt(fcord, seed, x, -2, gw, gh)],
[for(x = [-1:1]) cell_pt(fcord, seed, x, 2, gw, gh)],
[for(y = [-1:1]) cell_pt(fcord, seed, -2, y, gw, gh)],
[for(y = [-1:1]) cell_pt(fcord, seed, 2, y, gw, gh)]
[for(y = range, x = range) cell_pt(fcord, seed, x, y, gw, gh)],
[for(x = range) cell_pt(fcord, seed, x, -2, gw, gh)],
[for(x = range) cell_pt(fcord, seed, x, 2, gw, gh)],
[for(y = range) cell_pt(fcord, seed, -2, y, gw, gh)],
[for(y = range) cell_pt(fcord, seed, 2, y, gw, gh)]
);
region_size = grid_w * 3;

View File

@@ -8,7 +8,7 @@ function _vx_bezier_pt3(p1, p2, p3, p4, pts) =
c = (b1 + b2) * 0.5,
p = [round(c[0]), round(c[1]), round(c[2])]
)
_vx_bezier3(c, b2, a3, p4, _vx_bezier3(p1, a1, b1, c, concat(pts, [p])));
_vx_bezier3(c, b2, a3, p4, _vx_bezier3(p1, a1, b1, c, [each pts, p]));
function _vx_bezier3(p1, p2, p3, p4, pts) =
(abs(p1[0] - p4[0]) < 0.5 && abs(p1[1] - p4[1]) < 0.5 && abs(p1[2] - p4[2]) < 0.5) ?
@@ -25,7 +25,7 @@ function _vx_bezier_pt2(p1, p2, p3, p4, pts) =
c = (b1 + b2) * 0.5,
p = [round(c[0]), round(c[1])]
)
_vx_bezier2(c, b2, a3, p4, _vx_bezier2(p1, a1, b1, c, concat(pts, [p])));
_vx_bezier2(c, b2, a3, p4, _vx_bezier2(p1, a1, b1, c, [each pts, p]));
function _vx_bezier2(p1, p2, p3, p4, pts) =
(abs(p1[0] - p4[0]) < 0.5 && abs(p1[1] - p4[1]) < 0.5) ?

View File

@@ -39,10 +39,7 @@ function _vx_circle_impl(radius, filled) =
)
concat(
filled ?
concat(
[[0, radius], [0, -radius]],
[for(xi = -radius; xi <= radius; xi = xi + 1) [xi, 0]]
)
[[0, radius], [0, -radius], each [for(xi = -radius; xi <= radius; xi = xi + 1) [xi, 0]]]
:
[
[0, -radius],

View File

@@ -29,7 +29,4 @@ function _vx_contour_travel(pts, p, fst) =
dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p[0], p[1])),
nxt_p = p + _vx_contour_nxt_offset[dir_i]
)
nxt_p == fst ? [p] :
concat(
[p], _vx_contour_travel(pts, nxt_p, fst)
);
nxt_p == fst ? [p] : [p, each _vx_contour_travel(pts, nxt_p, fst)];

View File

@@ -26,9 +26,9 @@ function _vx_line_xdominant(start, end, a, s) =
zd = az - shrx,
endx = end[0]
)
concat(
[start],
_vx_line_xdominant_sub(
[
start,
each _vx_line_xdominant_sub(
x + sx,
_vx_line_xdominant_y(y, yd, sy),
_vx_line_xdominant_z(z, zd, sz),
@@ -38,7 +38,7 @@ function _vx_line_xdominant(start, end, a, s) =
_vx_line_xdominant_yd(yd, ax, ay),
_vx_line_xdominant_zd(zd, ax, az)
)
);
];
function _vx_line_xdominant_sub(x, y, z, endx, a, s, yd, zd) =
let(
@@ -49,19 +49,19 @@ function _vx_line_xdominant_sub(x, y, z, endx, a, s, yd, zd) =
sy = s[1],
sz = s[2]
)
x == endx ? [] :
concat([[x, y, z]],
_vx_line_xdominant_sub(
x + sx,
_vx_line_xdominant_y(y, yd, sy),
_vx_line_xdominant_z(z, zd, sz),
endx,
a,
s,
_vx_line_xdominant_yd(yd, ax, ay),
_vx_line_xdominant_zd(zd, ax, az)
)
);
x == endx ? [] : [
[x, y, z],
each _vx_line_xdominant_sub(
x + sx,
_vx_line_xdominant_y(y, yd, sy),
_vx_line_xdominant_z(z, zd, sz),
endx,
a,
s,
_vx_line_xdominant_yd(yd, ax, ay),
_vx_line_xdominant_zd(zd, ax, az)
)
];
// y-dominant
function _vx_line_ydominant_x(x, xd, sx) = xd >= 0 ? x + sx : x;
@@ -85,9 +85,9 @@ function _vx_line_ydominant(start, end, a, s) =
zd = az - shry,
endy = end[1]
)
concat(
[start],
_vx_line_ydominant_sub(
[
start,
each _vx_line_ydominant_sub(
_vx_line_ydominant_x(x, xd, sx),
y + sy,
_vx_line_ydominant_z(z, zd, sz),
@@ -97,7 +97,7 @@ function _vx_line_ydominant(start, end, a, s) =
_vx_line_ydominant_xd(xd, ax, ay),
_vx_line_ydominant_zd(zd, ay, az)
)
);
];
function _vx_line_ydominant_sub(x, y, z, endy, a, s, xd, zd) =
let(
@@ -108,19 +108,19 @@ function _vx_line_ydominant_sub(x, y, z, endy, a, s, xd, zd) =
sy = s[1],
sz = s[2]
)
y == endy ? [] :
concat([[x, y, z]],
_vx_line_ydominant_sub(
_vx_line_ydominant_x(x, xd, sx),
y + sy,
_vx_line_ydominant_z(z, zd, sz),
endy,
a,
s,
_vx_line_ydominant_xd(xd, ax, ay),
_vx_line_ydominant_zd(zd, ay, az)
)
);
y == endy ? [] : [
[x, y, z],
each _vx_line_ydominant_sub(
_vx_line_ydominant_x(x, xd, sx),
y + sy,
_vx_line_ydominant_z(z, zd, sz),
endy,
a,
s,
_vx_line_ydominant_xd(xd, ax, ay),
_vx_line_ydominant_zd(zd, ay, az)
)
];
// z-dominant
function _vx_line_zdominant_x(x, xd, sx) = xd >= 0 ? x + sx : x;
@@ -145,9 +145,9 @@ function _vx_line_zdominant(start, end, a, s) =
yd = ay - shrz,
endz = end[2]
)
concat(
[start],
_vx_line_zdominant_sub(
[
start,
each _vx_line_zdominant_sub(
_vx_line_zdominant_x(x, xd, sx),
_vx_line_zdominant_y(y, yd, sy),
z + sz,
@@ -157,7 +157,7 @@ function _vx_line_zdominant(start, end, a, s) =
_vx_line_zdominant_xd(xd, ax, az),
_vx_line_zdominant_yd(yd, ay, az)
)
);
];
function _vx_line_zdominant_sub(x, y, z, endz, a, s, xd, yd) =
let(
@@ -168,20 +168,20 @@ function _vx_line_zdominant_sub(x, y, z, endz, a, s, xd, yd) =
sy = s[1],
sz = s[2]
)
z == endz ? [] :
concat([[x, y, z]],
_vx_line_zdominant_sub(
_vx_line_zdominant_x(x, xd, sx),
_vx_line_zdominant_y(y, yd, sy),
z + sz,
endz,
a,
s,
_vx_line_zdominant_xd(xd, ax, az),
_vx_line_zdominant_yd(yd, ay, az)
)
);
z == endz ? [] : [
[x, y, z],
each _vx_line_zdominant_sub(
_vx_line_zdominant_x(x, xd, sx),
_vx_line_zdominant_y(y, yd, sy),
z + sz,
endz,
a,
s,
_vx_line_zdominant_xd(xd, ax, az),
_vx_line_zdominant_yd(yd, ay, az)
)
];
function _vx_line_impl(p1, p2) =
let(
is_2d = len(p1) == 2,

View File

@@ -14,15 +14,15 @@ use <../util/dedup.scad>;
function vx_curve(points, tightness = 0) =
let(
leng = len(points),
pts = concat(
[
pts = [
each [
for(i = [0:leng - 4])
let(
pts = _vx_catmull_rom_spline_4pts([for(j = [i:i + 3]) points[j]], tightness)
)
for(i = [0:len(pts) - 2]) pts[i]
],
[points[leng - 2]]
)
points[leng - 2]
]
)
dedup(pts);

View File

@@ -4,7 +4,7 @@ use <../util/dedup.scad>;
use <vx_polyline.scad>;
function vx_polygon(points, filled = false) =
let(contour = vx_polyline(concat(points, [points[0]])))
let(contour = vx_polyline([each points, points[0]]))
!filled ? contour :
let(
sortedXY = sort(contour, by = "vt"),