1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 09:14:29 +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),
[_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) : []]
)
),
cell_p = _cell_position(cell_radius, x, y)
)
[
for(wall = walls)
if(wall != [])
[for(p = wall)
_cell_position(cell_radius, x, y) + p]
if(wall != []) [for(p = wall) cell_p + p]
];

View File

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

View File

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

View File

@@ -5,17 +5,17 @@ function _neighbors(fcord, seed, grid_w) =
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
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
];
function _nz_worley3_classic(p, nbrs, dist) =