1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-01 04:20:27 +02:00
This commit is contained in:
Justin Lin
2020-03-29 10:48:54 +08:00
parent cff96e2d2b
commit 6c273250c7
3 changed files with 29 additions and 28 deletions

View File

@@ -0,0 +1,27 @@
use <experimental/_impl/_nz_worley_comm.scad>;
function _neighbors(fcord, seed, dim, m, n) = [
for(y = [-1:1])
for(x = [-1:1])
let(
nx = fcord[0] + x,
ny = fcord[1] + y,
sd_base = nx + ny * dim,
sd1 = _lookup_noise_table(seed + sd_base),
sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
nbr = [(nx + sd1) * m, (ny + sd2) * n]
)
nbr
];
function _nz_worley2(p, seed, dim, m, n, dist) =
let(
fcord = [floor(p[0] / m), floor(p[1] / n)],
nbrs = _neighbors(fcord, seed, dim, m, n),
dists = [
for(nbr = nbrs)
if(!is_undef(nbr[1])) // Here's a workaround for a weired undef problem. bug of 2019.05?
_distance(nbr, p, dist)
]
)
min(dists);

View File

@@ -4,20 +4,6 @@ _noise_table = [0.592157, 0.627451, 0.537255, 0.356863, 0.352941, 0.0588235, 0.5
function _lookup_noise_table(i) = _noise_table[i % 256];
function _neighbors(fcord, seed, dim, m, n) = [
for(y = [-1:1])
for(x = [-1:1])
let(
nx = fcord[0] + x,
ny = fcord[1] + y,
sd_base = nx + ny * dim,
sd1 = _lookup_noise_table(seed + sd_base),
sd2 = _lookup_noise_table(sd1 * 255 + sd_base),
nbr = [(nx + sd1) * m, (ny + sd2) * n]
)
nbr
];
function _manhattan(v) = sum([for(d = v) abs(d)]);
function _chebyshev(p1, p2) =
@@ -27,16 +13,4 @@ function _distance(nbr, p, dist) =
dist == "euclidean" ? norm(nbr - p) :
dist == "manhattan" ? _manhattan(nbr - p) :
dist == "chebyshev" ? _chebyshev(nbr, p) :
assert("Unknown distance option");
function _nz_worley2(p, seed, dim, m, n, dist) =
let(
fcord = [floor(p[0] / m), floor(p[1] / n)],
nbrs = _neighbors(fcord, seed, dim, m, n),
dists = [
for(nbr = nbrs)
if(!is_undef(nbr[1])) // Here's a workaround for a weired undef problem. bug of 2019.05?
_distance(nbr, p, dist)
]
)
min(dists);
assert("Unknown distance option");

View File

@@ -1,5 +1,5 @@
use <util/rand.scad>;
use <experimental/_impl/_nz_worley2_comm.scad>;
use <experimental/_impl/_nz_worley2_impl.scad>;
function nz_worley2(size, x, y, seed, dim = 3, dist = "euclidean") =
let(