1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 06:08:31 +01:00
This commit is contained in:
Justin Lin 2022-05-06 19:39:15 +08:00
parent 193f38d531
commit 42fa6df7cc
2 changed files with 24 additions and 16 deletions

View File

@ -1,32 +1,37 @@
use <../../util/sorted.scad>;
use <../../util/sum.scad>;
function _manhattan(v) = sum([for(d = v) abs(d)]);
function _chebyshev(p1, p2) =
max([for(i = [0:len(p1) - 1]) abs(p1[i] - p2[i])]);
max([for(i = [0:len(p1) - 1]) abs(p1[i] - p2[i])]);
function _nz_cell_classic(cells, p, dist) =
function _nz_worley_euclidean(p, cells) =
_nz_worley_from(cells, [for(cell = cells) norm(cell - p)]);
function _nz_worley_manhattan(p, cells) =
_nz_worley_from(cells, [for(cell = cells) _manhattan(cell - p)]);
function _nz_worley_chebyshev(p, cells) =
_nz_worley_from(cells, [for(cell = cells) _chebyshev(cell, p)]);
function _nz_worley_from(cells, dists) =
let(
dists =
dist == "euclidean" ? [for(cell = cells) norm(cell - p)] :
dist == "manhattan" ? [for(cell = cells) _manhattan(cell - p)] :
dist == "chebyshev" ? [for(cell = cells) _chebyshev(cell, p)] :
assert("Unknown distance option")
m = min(dists),
i = search(m, dists)[0]
)
min(dists);
m;
function _nz_cell_border(cells, p) =
function _nz_worley_border(p, cells) =
let(
dists = [for(cell = cells) norm(cell - p)],
m1 = min(dists),
i1 = search(m1, dists)[0],
dists2 = [for(i = [0:len(dists) - 1]) if(i != i1) dists[i]],
cells2 = [for(i = [0:len(cells) - 1]) if(i != i1) cells[i]],
nbrs2 = [for(i = [0:len(cells) - 1]) if(i != i1) cells[i]],
m2 = min(dists2),
i2 = search(m2, dists2)[0],
fst = cells[i1],
snd = cells2[i2],
m = (fst + snd) / 2
snd = nbrs2[i2],
m = (fst + snd) / 2
)
(p - m) * (fst - m);
(p - m) * (fst - m);

View File

@ -11,5 +11,8 @@
use <_impl/_nz_cell_impl.scad>;
function nz_cell(points, p, dist = "euclidean") =
dist == "border" ? _nz_cell_border(points, p) :
_nz_cell_classic(points, p, dist);
dist == "euclidean" ? _nz_worley_euclidean(p, points) :
dist == "manhattan" ? _nz_worley_manhattan(p, points) :
dist == "chebyshev" ? _nz_worley_chebyshev(p, points) :
dist == "border" ? _nz_worley_border(p, points) :
assert("Unknown distance option");