1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +02:00
This commit is contained in:
Justin Lin
2022-03-10 21:57:21 +08:00
parent 63ddbd3104
commit 0ce5d6e1da
4 changed files with 32 additions and 32 deletions

View File

@@ -39,11 +39,10 @@ function _build_cell(cell_radius, cell) =
_row_wall(cell_radius, x, y), _row_wall(cell_radius, x, y),
[_is_top_wall(cell) || _is_top_right_wall(cell) ? _top(cell_radius) : []], [_is_top_wall(cell) || _is_top_right_wall(cell) ? _top(cell_radius) : []],
[_is_right_wall(cell) || _is_top_right_wall(cell) ? _right_wall(cell_radius, x) : []] [_is_right_wall(cell) || _is_top_right_wall(cell) ? _right_wall(cell_radius, x) : []]
) ),
cell_p = _cell_position(cell_radius, x, y)
) )
[ [
for(wall = walls) for(wall = walls)
if(wall != []) if(wall != []) [for(p = wall) cell_p + p]
[for(p = wall)
_cell_position(cell_radius, x, y) + p]
]; ];

View File

@@ -2,15 +2,14 @@ use <_mz_square_comm.scad>;
// create a starting maze for being visited later. // create a starting maze for being visited later.
function _rc_maze(rows, columns) = [ function _rc_maze(rows, columns) = [
for(y = [0:rows - 1]) for(y = [0:rows - 1], x = [0:columns - 1])
for(x = [0:columns - 1]) cell(
cell( x, y,
x, y, // all cells have top and right walls
// all cells have top and right walls 3,
3, // unvisited
// unvisited false
false )
)
]; ];
function _mz_mask(mask) = function _mz_mask(mask) =

View File

@@ -9,10 +9,10 @@ function _chebyshev(p1, p2) =
function _nz_cell_classic(cells, p, dist) = function _nz_cell_classic(cells, p, dist) =
let( let(
dists = [ dists = [
for(i = [0:len(cells) - 1]) for(cell = cells)
dist == "euclidean" ? norm(cells[i] - p) : dist == "euclidean" ? norm(cell - p) :
dist == "manhattan" ? _manhattan(cells[i] - p) : dist == "manhattan" ? _manhattan(cell - p) :
dist == "chebyshev" ? _chebyshev(cells[i], p) : dist == "chebyshev" ? _chebyshev(cell, p) :
assert("Unknown distance option") assert("Unknown distance option")
] ]
) )
@@ -21,13 +21,15 @@ function _nz_cell_classic(cells, p, dist) =
function _nz_cell_border(cells, p) = function _nz_cell_border(cells, p) =
let( let(
dists = [ dists = [
for(i = [0:len(cells) - 1]) for(cell = cells)
[each cells[i], norm(cells[i] - p)] [each cell, norm(cell - p)]
], ],
idx = len(cells[0]), idx = len(cells[0]),
sorted = sort(dists, by = "idx", idx = idx), sorted = sort(dists, by = "idx", idx = idx),
a = [for(i = [0:idx - 1]) sorted[0][i]], sorted0 = sorted[0],
b = [for(i = [0:idx - 1]) sorted[1][i]], sorted1 = sorted[1],
a = [for(i = [0:idx - 1]) sorted0[i]],
b = [for(i = [0:idx - 1]) sorted1[i]],
m = (a + b) / 2 m = (a + b) / 2
) )
(p - m) * (a - m); (p - m) * (a - m);

View File

@@ -5,17 +5,17 @@ function _neighbors(fcord, seed, grid_w) =
let(range = [-1:1]) let(range = [-1:1])
[ [
for(z = range, y = range, x = range) for(z = range, y = range, x = range)
let( let(
nx = fcord.x + x, nx = fcord.x + x,
ny = fcord.y + y, ny = fcord.y + y,
nz = fcord.z + z, nz = fcord.z + z,
sd_base = abs(nx + ny * grid_w + nz * grid_w * grid_w), sd_base = abs(nx + ny * grid_w + nz * grid_w * grid_w),
sd1 = _lookup_noise_table(seed + sd_base), sd1 = _lookup_noise_table(seed + sd_base),
sd2 = _lookup_noise_table(sd1 * 255 + sd_base), sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
sd3 = _lookup_noise_table(sd2 * 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 = [(nx + sd1) * grid_w, (ny + sd2) * grid_w, (nz + sd3) * grid_w]
) )
nbr nbr
]; ];
function _nz_worley3_classic(p, nbrs, dist) = function _nz_worley3_classic(p, nbrs, dist) =