mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-21 05:52:16 +02:00
refactor: extract dist cond
This commit is contained in:
@@ -18,10 +18,10 @@ function _neighbors(fcord, seed, grid_w) =
|
||||
|
||||
function _nz_worley2_classic(p, nbrs, dist) =
|
||||
let(
|
||||
cells = [
|
||||
for(nbr = nbrs)
|
||||
[each nbr, _distance(nbr, p, dist)]
|
||||
],
|
||||
cells = dist == "euclidean" ? [for(nbr = nbrs) [each nbr, norm(nbr - p)]] :
|
||||
dist == "manhattan" ? [for(nbr = nbrs) [each nbr, _manhattan(nbr - p)]] :
|
||||
dist == "chebyshev" ? [for(nbr = nbrs) [each nbr, _chebyshev(nbr, p)]] :
|
||||
assert("Unknown distance option"),
|
||||
sorted = sort(cells, by = "idx", idx = 2)
|
||||
)
|
||||
sorted[0];
|
||||
|
@@ -20,10 +20,10 @@ function _neighbors(fcord, seed, grid_w) =
|
||||
|
||||
function _nz_worley3_classic(p, nbrs, dist) =
|
||||
let(
|
||||
cells = [
|
||||
for(nbr = nbrs)
|
||||
[each nbr, _distance(nbr, p, dist)]
|
||||
],
|
||||
cells = dist == "euclidean" ? [for(nbr = nbrs) [each nbr, norm(nbr - p)]] :
|
||||
dist == "manhattan" ? [for(nbr = nbrs) [each nbr, _manhattan(nbr - p)]] :
|
||||
dist == "chebyshev" ? [for(nbr = nbrs) [each nbr, _chebyshev(nbr, p)]] :
|
||||
assert("Unknown distance option"),
|
||||
sorted = sort(cells, by = "idx", idx = 3)
|
||||
)
|
||||
sorted[0];
|
||||
|
@@ -9,8 +9,3 @@ 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])]);
|
||||
|
||||
function _distance(nbr, p, dist) =
|
||||
dist == "euclidean" ? norm(nbr - p) :
|
||||
dist == "manhattan" ? _manhattan(nbr - p) :
|
||||
dist == "chebyshev" ? _chebyshev(nbr, p) :
|
||||
assert("Unknown distance option");
|
Reference in New Issue
Block a user