1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-06 14:56:47 +02:00

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

This commit is contained in:
Justin Lin
2022-02-27 18:50:19 +08:00
parent 69bfe3fdfa
commit 7d407d8cda
8 changed files with 38 additions and 47 deletions

View File

@@ -1,10 +1,7 @@
function __lines_from(pts, closed = false) = function __lines_from(pts, closed = false) =
let( let(
leng = len(pts), leng = len(pts),
endi = leng - 1 endi = leng - 1,
lines = [for(i = 0; i < endi; i = i + 1) [pts[i], pts[i + 1]]]
) )
concat( closed ? [each lines, [pts[endi], pts[0]]] : lines;
[for(i = 0; i < endi; i = i + 1) [pts[i], pts[i + 1]]],
closed ? [[pts[len(pts) - 1], pts[0]]] : []
);

View File

@@ -2,17 +2,11 @@ function __pie_for_rounding(r, begin_a, end_a, frags) =
let( let(
sector_angle = end_a - begin_a, sector_angle = end_a - begin_a,
step_a = sector_angle / frags, step_a = sector_angle / frags,
is_integer = frags % 1 == 0 is_integer = frags % 1 == 0,
pie = [
for(ang = begin_a; ang <= end_a; ang = ang + step_a)
[r * cos(ang), r * sin(ang)]
]
) )
r < 0.00005 ? [[0, 0]] : concat([ r < 0.00005 ? [[0, 0]] :
for(ang = begin_a; ang <= end_a; ang = ang + step_a) is_integer ? pie : [each pie, [r * cos(end_a), r * sin(end_a)]];
[
r * cos(ang),
r * sin(ang)
]
],
is_integer ? [] : [[
r * cos(end_a),
r * sin(end_a)
]]
);

View File

@@ -11,7 +11,7 @@ function _convex_hull_sort_by_xy(lt) =
before = [for(j = 1; j < leng; j = j + 1) if(_convex_hull_lt_than_by_xy(lt[j], pivot)) lt[j]], before = [for(j = 1; j < leng; j = j + 1) if(_convex_hull_lt_than_by_xy(lt[j], pivot)) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(!_convex_hull_lt_than_by_xy(lt[j], pivot)) lt[j]] after = [for(j = 1; j < leng; j = j + 1) if(!_convex_hull_lt_than_by_xy(lt[j], pivot)) lt[j]]
) )
concat(_convex_hull_sort_by_xy(before), [pivot], _convex_hull_sort_by_xy(after)); [each _convex_hull_sort_by_xy(before), pivot, each _convex_hull_sort_by_xy(after)];
// oa->ob ct_clk : greater than 0 // oa->ob ct_clk : greater than 0
function _convex_hull_impl_dir(o, a, b) = function _convex_hull_impl_dir(o, a, b) =
@@ -28,7 +28,7 @@ function _convex_hull_lower_chain(points, leng, chain, m, i) =
_convex_hull_lower_chain( _convex_hull_lower_chain(
points, points,
leng, leng,
concat(slice(chain, 0, current_m), [points[i]]), [each slice(chain, 0, current_m), points[i]],
current_m + 1, current_m + 1,
i + 1 i + 1
); );
@@ -44,7 +44,7 @@ function _convex_hull_upper_chain(points, chain, m, t, i) =
) )
_convex_hull_upper_chain( _convex_hull_upper_chain(
points, points,
concat(slice(chain, 0, current_m), [points[i]]), [each slice(chain, 0, current_m), points[i]],
current_m + 1, current_m + 1,
t, t,
i - 1 i - 1

View File

@@ -13,7 +13,7 @@ function _convex_hull_sort_by_xyz(pts) =
before = [for(j = 1; j < leng; j = j + 1) if(_cmp(pts[j], pivot)) pts[j]], before = [for(j = 1; j < leng; j = j + 1) if(_cmp(pts[j], pivot)) pts[j]],
after = [for(j = 1; j < leng; j = j + 1) if(!_cmp(pts[j], pivot)) pts[j]] after = [for(j = 1; j < leng; j = j + 1) if(!_cmp(pts[j], pivot)) pts[j]]
) )
concat(_convex_hull_sort_by_xyz(before), [pivot], _convex_hull_sort_by_xyz(after)); [each _convex_hull_sort_by_xyz(before), pivot, each _convex_hull_sort_by_xyz(after)];
function normal(pts, f) = cross(pts[f[1]] - pts[f[0]], pts[f[2]] - pts[f[0]]); function normal(pts, f) = cross(pts[f[1]] - pts[f[0]], pts[f[2]] - pts[f[0]]);
@@ -33,25 +33,25 @@ function m_assign(m, i, j, v) =
let( let(
lt = m[i], lt = m[i],
leng_lt = len(lt), leng_lt = len(lt),
nlt = concat( nlt = [
j == 0 ? [] : [for(idx = [0:j - 1]) lt[idx]], each (j == 0 ? [] : [for(idx = [0:j - 1]) lt[idx]]),
[v], v,
j == leng_lt - 1 ? [] : [for(idx = [j + 1:leng_lt - 1]) lt[idx]] each (j == leng_lt - 1 ? [] : [for(idx = [j + 1:leng_lt - 1]) lt[idx]])
), ],
leng_m = len(m) leng_m = len(m)
) )
concat( [
i == 0 ? [] : [for(idx = [0:i - 1]) m[idx]], each (i == 0 ? [] : [for(idx = [0:i - 1]) m[idx]]),
[nlt], nlt,
i == leng_m - 1 ? [] : [for(idx = [i + 1:leng_m - 1]) m[idx]] each (i == leng_m - 1 ? [] : [for(idx = [i + 1:leng_m - 1]) m[idx]])
); ];
function next_vis(i, pts, cur_faces, cur_faces_leng, next, vis, j = 0) = function next_vis(i, pts, cur_faces, cur_faces_leng, next, vis, j = 0) =
j == cur_faces_leng ? [next, vis] : j == cur_faces_leng ? [next, vis] :
let( let(
f = cur_faces[j], f = cur_faces[j],
d = (pts[f[0]] - pts[i]) * normal(pts, f), d = (pts[f[0]] - pts[i]) * normal(pts, f),
nx = d >= 0 ? concat(next, [f]) : next, nx = d >= 0 ? [each next, f] : next,
s = d > 0 ? 1 : s = d > 0 ? 1 :
d < 0 ? -1 : 0, d < 0 ? -1 : 0,
vis1 = m_assign(vis, f[0], f[1], s), vis1 = m_assign(vis, f[0], f[1], s),
@@ -68,11 +68,11 @@ function next2(i, cur_faces, cur_faces_leng, vis, next, j = 0) =
b = f[1], b = f[1],
c = f[2], c = f[2],
nx1 = vis[a][b] < 0 && vis[a][b] != vis[b][a] ? nx1 = vis[a][b] < 0 && vis[a][b] != vis[b][a] ?
concat(next, [[a, b, i]]) : next, [each next, [a, b, i]] : next,
nx2 = vis[b][c] < 0 && vis[b][c] != vis[c][b] ? nx2 = vis[b][c] < 0 && vis[b][c] != vis[c][b] ?
concat(nx1, [[b, c, i]]) : nx1, [each nx1, [b, c, i]] : nx1,
nx3 = vis[c][a] < 0 && vis[c][a] != vis[a][c] ? nx3 = vis[c][a] < 0 && vis[c][a] != vis[a][c] ?
concat(nx2, [[c, a, i]]) : nx2 [each nx2, [c, a, i]] : nx2
) )
next2(i, cur_faces, cur_faces_leng, vis, nx3, j + 1); next2(i, cur_faces, cur_faces_leng, vis, nx3, j + 1);

View File

@@ -20,7 +20,7 @@ function _connected_faces(faces, leng, leng_pts, cnt_faces, i = 0) =
facei = sort(faces[i], by = ascending), facei = sort(faces[i], by = ascending),
n_cnt_faces = [ n_cnt_faces = [
for(k = [0:leng_pts - 1]) for(k = [0:leng_pts - 1])
find_index(facei, function(e) e == k) != -1 ? concat(cnt_faces[k], [faces[i]]) : cnt_faces[k] find_index(facei, function(e) e == k) != -1 ? [each cnt_faces[k], faces[i]] : cnt_faces[k]
] ]
) )
_connected_faces(faces, leng, leng_pts, n_cnt_faces, i + 1); _connected_faces(faces, leng, leng_pts, n_cnt_faces, i + 1);

View File

@@ -19,7 +19,7 @@ function _in_convex(convex_pts, pt) =
function _intersection_ps(shape, line_pts, epsilon) = function _intersection_ps(shape, line_pts, epsilon) =
let( let(
leng = len(shape), leng = len(shape),
pts = concat(shape, [shape[0]]) pts = [each shape, shape[0]]
) )
dedup([ dedup([
for(i = [0:leng - 1]) for(i = [0:leng - 1])
@@ -31,7 +31,7 @@ function _convex_intersection(shape1, shape2, epsilon = 0.0001) =
(shape1 == [] || shape2 == []) ? [] : (shape1 == [] || shape2 == []) ? [] :
let( let(
leng = len(shape1), leng = len(shape1),
pts = concat(shape1, [shape1[0]]) pts = [each shape1, shape1[0]]
) )
_convex_ct_clk_order( _convex_ct_clk_order(
concat( concat(

View File

@@ -20,16 +20,16 @@ function cell_pt(fcord, grid_w, seed, x, y, gw, gh) =
// 21-nearest-neighbor // 21-nearest-neighbor
function _neighbors(fcord, seed, grid_w, gw, gh) = function _neighbors(fcord, seed, grid_w, gw, gh) =
let(range = [-1:1])
concat( concat(
[ [
for(y = [-1:1]) for(y = range, x = range)
for(x = [-1:1])
cell_pt(fcord, grid_w, seed, x, y, gw, gh) cell_pt(fcord, grid_w, seed, x, y, gw, gh)
], ],
[for(x = [-1:1]) cell_pt(fcord, grid_w, seed, x, -2, gw, gh)], [for(x = range) cell_pt(fcord, grid_w, seed, x, -2, gw, gh)],
[for(x = [-1:1]) cell_pt(fcord, grid_w, seed, x, 2, gw, gh)], [for(x = range) cell_pt(fcord, grid_w, seed, x, 2, gw, gh)],
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, -2, y, gw, gh)], [for(y = range) cell_pt(fcord, grid_w, seed, -2, y, gw, gh)],
[for(y = [-1:1]) cell_pt(fcord, grid_w, seed, 2, y, gw, gh)] [for(y = range) cell_pt(fcord, grid_w, seed, 2, y, gw, gh)]
); );
function _cells_lt_before_intersection(shape, size, points, pt, half_region_size) = function _cells_lt_before_intersection(shape, size, points, pt, half_region_size) =

View File

@@ -6,7 +6,7 @@ function vrn_sphere(points) =
r = norm(points[0]), r = norm(points[0]),
plane_pts = [for(p = points) stereographic_proj_to_plane(p / r)], plane_pts = [for(p = points) stereographic_proj_to_plane(p / r)],
inifinity = [4e7, 0], inifinity = [4e7, 0],
vrn2_cells = vrn2_cells_from(concat(plane_pts, [inifinity])) vrn2_cells = vrn2_cells_from([each plane_pts, inifinity])
) )
[ [
for(i = [0:len(vrn2_cells) - 2]) for(i = [0:len(vrn2_cells) - 2])