mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-13 18:24:28 +02:00
refactor
This commit is contained in:
@@ -38,7 +38,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
[
|
||||
(scale.x - 1) / len_path_pts_minus_one,
|
||||
(scale.y - 1) / len_path_pts_minus_one,
|
||||
is_undef(scale[2]) ? 0 : (scale.z - 1) / len_path_pts_minus_one
|
||||
is_undef(scale.z) ? 0 : (scale.z - 1) / len_path_pts_minus_one
|
||||
];
|
||||
|
||||
// get rotation matrice for sections
|
||||
@@ -114,15 +114,17 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
let(
|
||||
vt0 = pth_pts[j] - pth_pts[j - 1],
|
||||
vt1 = pth_pts[j + 1] - pth_pts[j],
|
||||
ms = cumu_rot_matrice[j - 1]
|
||||
ms = cumu_rot_matrice[j - 1],
|
||||
ms0 = ms[0],
|
||||
ms1 = ms[1],
|
||||
ms2 = ms[2],
|
||||
ms0p = [ms0[0], ms0[1], ms0[2]],
|
||||
ms1p = [ms1[0], ms1[1], ms1[2]],
|
||||
ms2p = [ms2[0], ms2[1], ms2[2]]
|
||||
)
|
||||
[
|
||||
for(p = init_section(init_a, init_s))
|
||||
[
|
||||
[ms[0][0], ms[0][1], ms[0][2]] * p,
|
||||
[ms[1][0], ms[1][1], ms[1][2]] * p,
|
||||
[ms[2][0], ms[2][1], ms[2][2]] * p
|
||||
]
|
||||
[ms0p * p, ms1p * p, ms2p * p]
|
||||
];
|
||||
|
||||
sections =
|
||||
|
@@ -31,9 +31,15 @@ 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 = [[90, 0, angles[0]], each (m > n ? [] : [for(i = [m:n]) [90, 0, a_step * i]])];
|
||||
angs = [
|
||||
[90, 0, angles[0]],
|
||||
if(m <= n) each [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)])];
|
||||
pts = [
|
||||
__ra_to_xy(begin_r, angles[0]),
|
||||
if(m <= n) each [for(i = [m:n]) __ra_to_xy(radius, a_step * i)]
|
||||
];
|
||||
|
||||
is_angle_frag_end = angs[len(angs) - 1][2] == angles[1];
|
||||
|
||||
|
@@ -30,10 +30,8 @@ module rounded_cube(size, corner_r, center = false) {
|
||||
|
||||
pair = [1, -1];
|
||||
corners = [
|
||||
for(z = pair)
|
||||
for(y = pair)
|
||||
for(x = pair)
|
||||
[half_l * x, half_w * y, half_h * z]
|
||||
for(z = pair, y = pair, x = pair)
|
||||
[half_l * x, half_w * y, half_h * z]
|
||||
];
|
||||
|
||||
module corner(i) {
|
||||
|
@@ -12,10 +12,10 @@ use <__comm__/__half_trapezium.scad>;
|
||||
|
||||
module rounded_cylinder(radius, h, round_r, convexity = 2, center = false) {
|
||||
r_corners = __half_trapezium(radius, h, round_r);
|
||||
half_h = h / 2;
|
||||
shape_pts = [[0, -half_h], each r_corners, [0, half_h]];
|
||||
|
||||
shape_pts = [[0, -h/2], each r_corners, [0, h/2]];
|
||||
|
||||
center_pt = center ? [0, 0, 0] : [0, 0, h/2];
|
||||
center_pt = center ? [0, 0, 0] : [0, 0, half_h];
|
||||
|
||||
translate(center_pt)
|
||||
rotate(180)
|
||||
|
@@ -32,7 +32,7 @@ module starburst(r1, r2, n, height) {
|
||||
module burst() {
|
||||
hull() {
|
||||
half_burst();
|
||||
mirror([0, 1,0]) half_burst();
|
||||
mirror([0, 1, 0]) half_burst();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,22 +21,20 @@ module sweep(sections, triangles = "SOLID") {
|
||||
)
|
||||
concat(
|
||||
[
|
||||
for(j = range_j)
|
||||
for(i = range_i)
|
||||
[
|
||||
j + i,
|
||||
j + (i + 1) % leng_pts_sect,
|
||||
j + (i + 1) % leng_pts_sect + leng_pts_sect
|
||||
]
|
||||
for(j = range_j, i = range_i)
|
||||
[
|
||||
j + i,
|
||||
j + (i + 1) % leng_pts_sect,
|
||||
j + (i + 1) % leng_pts_sect + leng_pts_sect
|
||||
]
|
||||
],
|
||||
[
|
||||
for(j = range_j)
|
||||
for(i = range_i)
|
||||
[
|
||||
j + i,
|
||||
j + (i + 1) % leng_pts_sect + leng_pts_sect ,
|
||||
j + i + leng_pts_sect
|
||||
]
|
||||
for(j = range_j, i = range_i)
|
||||
[
|
||||
j + i,
|
||||
j + (i + 1) % leng_pts_sect + leng_pts_sect ,
|
||||
j + i + leng_pts_sect
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
@@ -45,21 +43,14 @@ module sweep(sections, triangles = "SOLID") {
|
||||
(p == f_sect[i] ? i : search_at(f_sect, p, leng_pts_sect, i + 1)) : -1;
|
||||
|
||||
function the_same_after_twisting(f_sect, l_sect, leng_pts_sect) =
|
||||
let(
|
||||
found_at_i = search_at(f_sect, l_sect[0], leng_pts_sect)
|
||||
)
|
||||
let(found_at_i = search_at(f_sect, l_sect[0], leng_pts_sect))
|
||||
found_at_i <= 0 ? false :
|
||||
l_sect == concat(
|
||||
[for(i = found_at_i; i < leng_pts_sect; i = i + 1) f_sect[i]],
|
||||
[for(i = 0; i < found_at_i; i = i + 1) f_sect[i]]
|
||||
);
|
||||
|
||||
function to_v_pts(sects) =
|
||||
[
|
||||
for(sect = sects)
|
||||
for(pt = sect)
|
||||
pt
|
||||
];
|
||||
function to_v_pts(sects) = [for(sect = sects) each sect];
|
||||
|
||||
module solid_sections(sects) {
|
||||
|
||||
@@ -68,11 +59,7 @@ module sweep(sections, triangles = "SOLID") {
|
||||
first_sect = sects[0];
|
||||
last_sect = sects[leng_sects - 1];
|
||||
|
||||
v_pts = [
|
||||
for(sect = sects)
|
||||
for(pt = sect)
|
||||
pt
|
||||
];
|
||||
v_pts = [for(sect = sects) each sect];
|
||||
|
||||
begin_end_the_same =
|
||||
first_sect == last_sect ||
|
||||
|
@@ -3,12 +3,7 @@ use <../../util/map/hashmap_get.scad>;
|
||||
use <../../util/find_index.scad>;
|
||||
|
||||
function indicesOfCell(iTris, triIndices) =
|
||||
let(
|
||||
vi = iTris[0][0],
|
||||
indices = [],
|
||||
leng = len(iTris)
|
||||
)
|
||||
_indicesOfCell(iTris, triIndices, leng, indices, vi);
|
||||
_indicesOfCell(iTris, triIndices, len(iTris), [], iTris[0][0]);
|
||||
|
||||
function _indicesOfCell(iTris, triIndices, leng, indices, vi, i = 0) =
|
||||
i == leng ? indices :
|
||||
|
@@ -28,9 +28,10 @@ function tri_delaunay_voronoi(d) =
|
||||
i_rts = [
|
||||
for(i = i_range)
|
||||
let(
|
||||
a = tris[i][0],
|
||||
b = tris[i][1],
|
||||
c = tris[i][2],
|
||||
tris_i = tris[i],
|
||||
a = tris_i[0],
|
||||
b = tris_i[1],
|
||||
c = tris_i[2],
|
||||
rt1 = [b, c, a],
|
||||
rt2 = [c, a, b],
|
||||
rt3 = [a, b, c]
|
||||
@@ -44,9 +45,10 @@ function tri_delaunay_voronoi(d) =
|
||||
triIndices = hashmap([
|
||||
for(i = i_range)
|
||||
let(
|
||||
a = tris[i][0],
|
||||
b = tris[i][1],
|
||||
c = tris[i][2],
|
||||
tris_i = tris[i],
|
||||
a = tris_i[0],
|
||||
b = tris_i[1],
|
||||
c = tris_i[2],
|
||||
rt1 = [b, c, a],
|
||||
rt2 = [c, a, b],
|
||||
rt3 = [a, b, c]
|
||||
|
@@ -12,8 +12,5 @@ use <_impl/_footprints2.scad>;
|
||||
use <turtle2d.scad>;
|
||||
|
||||
function footprints2(cmds, start = [0, 0]) =
|
||||
let(
|
||||
t = turtle2d("create", start.x, start.y, 0),
|
||||
leng = len(cmds)
|
||||
)
|
||||
[turtle2d("pt", t), each _footprints2(cmds, t, leng)];
|
||||
let(t = turtle2d("create", start.x, start.y, 0))
|
||||
[turtle2d("pt", t), each _footprints2(cmds, t, len(cmds))];
|
@@ -12,8 +12,5 @@ use <_impl/_footprints3.scad>;
|
||||
use <turtle3d.scad>;
|
||||
|
||||
function footprints3(cmds, start = [0, 0, 0]) =
|
||||
let(
|
||||
t = turtle3d("create", start, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
|
||||
leng = len(cmds)
|
||||
)
|
||||
[turtle3d("pt", t), each _footprints3(cmds, t, leng)];
|
||||
let(t = turtle3d("create", start, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]))
|
||||
[turtle3d("pt", t), each _footprints3(cmds, t, len(cmds))];
|
@@ -16,9 +16,9 @@ function swap(lt, i, j) =
|
||||
b = max([i, j])
|
||||
)
|
||||
[
|
||||
each (a == 0 ? [] : [for(idx = [0:a - 1]) lt[idx]]),
|
||||
if(a != 0) each [for(idx = [0:a - 1]) lt[idx]],
|
||||
lt[b],
|
||||
each (b - a == 1 ? [] : [for(idx = [a + 1:b - 1]) lt[idx]]),
|
||||
if(b - a != 1) each [for(idx = [a + 1:b - 1]) lt[idx]],
|
||||
lt[a],
|
||||
each (b == leng - 1 ? [] : [for(idx = [b + 1:leng - 1]) lt[idx]])
|
||||
if(b != leng - 1) each [for(idx = [b + 1:leng - 1]) lt[idx]]
|
||||
];
|
@@ -4,7 +4,6 @@ use <_convex_centroid.scad>;
|
||||
function _convex_ct_clk_order(points) =
|
||||
let(
|
||||
cpt = _convex_centroid(points),
|
||||
pts_as = [for(p = points) [p, atan2(p.y - cpt.y, p.x - cpt.x)]],
|
||||
sorted = sort(pts_as, by = "idx", idx = 1)
|
||||
pts_as = [for(p = points) [p, atan2(p.y - cpt.y, p.x - cpt.x)]]
|
||||
)
|
||||
[for(v = sorted) v[0]];
|
||||
[for(v = sort(pts_as, by = "idx", idx = 1)) v[0]];
|
@@ -6,8 +6,8 @@ function _lookup_noise_table(i) = _noise_table[i % 256];
|
||||
|
||||
function cell_pt(fcord, grid_w, seed, x, y, gw, gh) =
|
||||
let(
|
||||
nx = fcord[0] + x,
|
||||
ny = fcord[1] + y,
|
||||
nx = fcord.x + x,
|
||||
ny = fcord.y + y,
|
||||
sd_x = nx < 0 ? nx + gw :
|
||||
nx >= gw ? nx % gw : nx,
|
||||
sd_y = ny < 0 ? ny + gh :
|
||||
|
@@ -18,10 +18,10 @@ function vrn2_cells_space(size, grid_w, seed) =
|
||||
region_size = grid_w * 3,
|
||||
half_region_size = region_size * 0.5,
|
||||
shape = shape_square(grid_w * 3),
|
||||
gw = size[0] / grid_w,
|
||||
gh = size[1] / grid_w,
|
||||
cell_nbrs_lt = [for(cy = [-grid_w:grid_w:size[1]])
|
||||
for(cx = [-grid_w:grid_w:size[0]])
|
||||
gw = size.x / grid_w,
|
||||
gh = size.y / grid_w,
|
||||
cell_nbrs_lt = [for(cy = [-grid_w:grid_w:size.y])
|
||||
for(cx = [-grid_w:grid_w:size.x])
|
||||
let(
|
||||
nbrs = _neighbors(
|
||||
[floor(cx / grid_w), floor(cy / grid_w)],
|
||||
|
@@ -15,8 +15,8 @@ module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = f
|
||||
|
||||
function cell_pt(fcord, seed, x, y, gw, gh) =
|
||||
let(
|
||||
nx = fcord[0] + x,
|
||||
ny = fcord[1] + y,
|
||||
nx = fcord.x + x,
|
||||
ny = fcord.y + y,
|
||||
sd_x = nx < 0 ? nx + gw :
|
||||
nx >= gw ? nx % gw : nx,
|
||||
sd_y = ny < 0 ? ny + gh :
|
||||
@@ -59,8 +59,8 @@ module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = f
|
||||
gw = size[0] / grid_w;
|
||||
gh = size[1] / grid_w;
|
||||
|
||||
cell_nbrs_lt = [for(cy = [-grid_w:grid_w:size[1]])
|
||||
for(cx = [-grid_w:grid_w:size[0]])
|
||||
cell_nbrs_lt = [
|
||||
for(cy = [-grid_w:grid_w:size.y], cx = [-grid_w:grid_w:size.x])
|
||||
let(
|
||||
nbrs = _neighbors(
|
||||
[floor(cx / grid_w), floor(cy / grid_w)],
|
||||
|
@@ -17,20 +17,19 @@ module vrn3_space(size, grid_w, seed, spacing = 1) {
|
||||
function _lookup_noise_table(i) = _noise_table[i % 256];
|
||||
|
||||
function _neighbors(fcord, seed, grid_w) = [
|
||||
for(z = [-1:1])
|
||||
for(y = [-1:1])
|
||||
for(x = [-1:1])
|
||||
let(
|
||||
nx = fcord[0] + x,
|
||||
ny = fcord[1] + y,
|
||||
nz = fcord[2] + z,
|
||||
sd_base = abs(nx + ny * grid_w + nz * grid_w * grid_w),
|
||||
sd1 = _lookup_noise_table(seed + sd_base),
|
||||
sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
|
||||
sd3 = _lookup_noise_table(sd2 * 255 + sd_base),
|
||||
nbr = [(nx + sd1) * grid_w, (ny + sd2) * grid_w, (nz + sd3) * grid_w]
|
||||
)
|
||||
nbr
|
||||
let(range = [-1:1])
|
||||
for(z = range, y = range, x = range)
|
||||
let(
|
||||
nx = fcord.x + x,
|
||||
ny = fcord.y + y,
|
||||
nz = fcord.z + z,
|
||||
sd_base = abs(nx + ny * grid_w + nz * grid_w * grid_w),
|
||||
sd1 = _lookup_noise_table(seed + sd_base),
|
||||
sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
|
||||
sd3 = _lookup_noise_table(sd2 * 255 + sd_base),
|
||||
nbr = [(nx + sd1) * grid_w, (ny + sd2) * grid_w, (nz + sd3) * grid_w]
|
||||
)
|
||||
nbr
|
||||
];
|
||||
|
||||
space_size = grid_w * 3;
|
||||
@@ -55,22 +54,20 @@ module vrn3_space(size, grid_w, seed, spacing = 1) {
|
||||
It can be avoided by taking 177-nearest-neighbor cells but the time taken would be unacceptable.
|
||||
*/
|
||||
cell_nbrs_lt = [
|
||||
for(cz = [0:grid_w:size[2]])
|
||||
for(cy = [0:grid_w:size[1]])
|
||||
for(cx = [0:grid_w:size[0]])
|
||||
let(
|
||||
nbrs = _neighbors(
|
||||
[floor(cx / grid_w), floor(cy / grid_w), floor(cz / grid_w)],
|
||||
sd,
|
||||
grid_w
|
||||
),
|
||||
p = nbrs[13],
|
||||
points = concat(
|
||||
[for(i = [0:12]) nbrs[i]],
|
||||
[for(i = [14:len(nbrs) - 1]) nbrs[i]]
|
||||
)
|
||||
)
|
||||
[p, points]
|
||||
for(cz = [0:grid_w:size.z], cy = [0:grid_w:size.y], cx = [0:grid_w:size.x])
|
||||
let(
|
||||
nbrs = _neighbors(
|
||||
[floor(cx / grid_w), floor(cy / grid_w), floor(cz / grid_w)],
|
||||
sd,
|
||||
grid_w
|
||||
),
|
||||
p = nbrs[13],
|
||||
points = concat(
|
||||
[for(i = [0:12]) nbrs[i]],
|
||||
[for(i = [14:len(nbrs) - 1]) nbrs[i]]
|
||||
)
|
||||
)
|
||||
[p, points]
|
||||
];
|
||||
|
||||
for(cell_nbrs = cell_nbrs_lt) {
|
||||
|
@@ -27,7 +27,7 @@ function _vx_cylinder_diff_r(r, h, filled, thickness) =
|
||||
let(r = round(r1 + dr * i))
|
||||
each [
|
||||
for(pt = _vx_cylinder_vx_circle(r, filled, thickness))
|
||||
[pt.x, pt.y, i]
|
||||
[each pt, i]
|
||||
]
|
||||
];
|
||||
|
||||
@@ -36,8 +36,7 @@ function _vx_cylinder_same_r(r, h, filled, thickness) =
|
||||
[
|
||||
for(i = 0; i < h; i = i + 1)
|
||||
each [
|
||||
for(pt = c)
|
||||
[pt.x, pt.y, i]
|
||||
for(pt = c) [each pt, i]
|
||||
]
|
||||
];
|
||||
|
||||
|
@@ -8,7 +8,7 @@ function vx_polygon(points, filled = false) =
|
||||
!filled ? contour :
|
||||
let(
|
||||
sortedXY = sort(contour, by = "vt"),
|
||||
ys = [for(p = sortedXY) p[1]],
|
||||
ys = [for(p = sortedXY) p.y],
|
||||
rows = [
|
||||
for(y = [min(ys):max(ys)])
|
||||
let(
|
||||
@@ -20,9 +20,9 @@ function vx_polygon(points, filled = false) =
|
||||
sortedXY,
|
||||
[
|
||||
for(row = rows)
|
||||
let(to = len(row) - 1, y = row[0][1])
|
||||
if(to > 0 && (row[0][0] + 1 != row[to][0]))
|
||||
for(i = [row[0][0] + 1:row[to][0] - 1])
|
||||
let(to = len(row) - 1, row0 = row[0], y = row0[1])
|
||||
if(to > 0 && (row0[0] + 1 != row[to][0]))
|
||||
for(i = [row0[0] + 1:row[to][0] - 1])
|
||||
let(p = [i, y])
|
||||
if(in_shape(points, p)) p
|
||||
]
|
||||
|
Reference in New Issue
Block a user