1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-13 18:24:28 +02:00

optimization

This commit is contained in:
Justin Lin
2022-05-06 17:54:26 +08:00
parent 8c483f6c8b
commit 590d8ab7c3

View File

@@ -1,7 +1,7 @@
use <_nz_worley_comm.scad>; use <_nz_worley_comm.scad>;
function _neighbors(fcord, seed, grid_w) = function _neighbors(fcord, seed, grid_w, gwv) =
let(range = [-1:1], gwv = [1, grid_w, grid_w ^ 2]) let(range = [-1:1])
[ [
for(z = range, y = range, x = range) for(z = range, y = range, x = range)
let( let(
@@ -14,7 +14,8 @@ function _neighbors(fcord, seed, grid_w) =
function _nz_worley3(p, seed, grid_w, dist) = function _nz_worley3(p, seed, grid_w, dist) =
let( let(
fcord = [floor(p.x / grid_w), floor(p.y / grid_w), floor(p.z / grid_w)], fcord = [floor(p.x / grid_w), floor(p.y / grid_w), floor(p.z / grid_w)],
nbrs = _neighbors(fcord, seed, grid_w) gwv = [1, grid_w, grid_w ^ 2],
nbrs = _neighbors(fcord, seed, grid_w, gwv)
) )
dist == "euclidean" ? _nz_worley_euclidean(p, nbrs) : dist == "euclidean" ? _nz_worley_euclidean(p, nbrs) :
dist == "manhattan" ? _nz_worley_manhattan(p, nbrs) : dist == "manhattan" ? _nz_worley_manhattan(p, nbrs) :
@@ -28,13 +29,14 @@ function _nz_worley3s(points, seed, grid_w, dist) =
dist == "manhattan" ? function(p, nbrs) _nz_worley_manhattan(p, nbrs) : dist == "manhattan" ? function(p, nbrs) _nz_worley_manhattan(p, nbrs) :
dist == "chebyshev" ? function(p, nbrs) _nz_worley_chebyshev(p, nbrs) : dist == "chebyshev" ? function(p, nbrs) _nz_worley_chebyshev(p, nbrs) :
dist == "border" ? function(p, nbrs) _nz_worley_border(p, nbrs) : dist == "border" ? function(p, nbrs) _nz_worley_border(p, nbrs) :
assert("Unknown distance option") assert("Unknown distance option"),
gwv = [1, grid_w, grid_w ^ 2]
) )
[ [
for(p = points) for(p = points)
let( let(
fcord = [floor(p.x / grid_w), floor(p.y / grid_w), floor(p.z / grid_w)], fcord = [floor(p.x / grid_w), floor(p.y / grid_w), floor(p.z / grid_w)],
nbrs = _neighbors(fcord, seed, grid_w) nbrs = _neighbors(fcord, seed, grid_w, gwv)
) )
noise(p, nbrs) noise(p, nbrs)
]; ];