mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-01 04:20:27 +02:00
half_sort is enough
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use <_nz_worley_comm.scad>;
|
||||
use <../../util/sorted.scad>;
|
||||
|
||||
_key = function(elem) elem[2];
|
||||
_less = function(a, b) a[2] < b[2];
|
||||
|
||||
function _neighbors(fcord, seed, grid_w) =
|
||||
let(range = [-1:1], fx = fcord.x, fy = fcord.y)
|
||||
@@ -25,12 +24,12 @@ function _nz_worley2_classic(p, nbrs, dist) =
|
||||
dist == "chebyshev" ? [for(nbr = nbrs) [each nbr, _chebyshev(nbr, p)]] :
|
||||
assert("Unknown distance option")
|
||||
)
|
||||
sorted(cells, key = _key)[0];
|
||||
_euclidean_half_sorted(cells, _less)[0];
|
||||
|
||||
function _nz_worley2_border(p, nbrs) =
|
||||
let(
|
||||
cells = [for(nbr = nbrs) [each nbr, norm(nbr - p)]],
|
||||
sorted_cells = sorted(cells, key = _key),
|
||||
sorted_cells = _border_half_sorted(cells, _less),
|
||||
fst = sorted_cells[0],
|
||||
snd = orted_cells[1],
|
||||
a = [fst.x, fst.y],
|
||||
|
@@ -1,7 +1,6 @@
|
||||
use <_nz_worley_comm.scad>;
|
||||
use <../../util/sorted.scad>;
|
||||
|
||||
_key = function(elem) elem[3];
|
||||
_less = function(a, b) a[3] < b[3];
|
||||
|
||||
function _neighbors(fcord, seed, grid_w) =
|
||||
let(range = [-1:1], fx = fcord.x, fy = fcord.y, fz = fcord.z)
|
||||
@@ -27,12 +26,12 @@ function _nz_worley3_classic(p, nbrs, dist) =
|
||||
dist == "chebyshev" ? [for(nbr = nbrs) [each nbr, _chebyshev(nbr, p)]] :
|
||||
assert("Unknown distance option")
|
||||
)
|
||||
sorted(cells, key = _key)[0];
|
||||
_euclidean_half_sorted(cells, _less)[0];
|
||||
|
||||
function _nz_worley3_border(p, nbrs) =
|
||||
let(
|
||||
cells = [for(nbr = nbrs) [each nbr, norm(nbr - p)]],
|
||||
sorted_cells = sorted(cells, key = _key),
|
||||
sorted_cells = _border_half_sorted(cells, _less),
|
||||
fst = sorted_cells[0],
|
||||
snd = sorted_cells[1],
|
||||
a = [fst.x, fst.y, fst.z],
|
||||
|
@@ -8,4 +8,26 @@ 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 _euclidean_half_sorted(cells, less) =
|
||||
let(leng = len(cells))
|
||||
leng <= 1 ? cells :
|
||||
leng == 2 ? less(cells[0], cells[1]) ? cells : [cells[1], cells[0]] :
|
||||
let(
|
||||
pivot = cells[0],
|
||||
before = [for(j = 1; j < leng; j = j + 1) if(less(cells[j], pivot)) cells[j]]
|
||||
)
|
||||
[each _euclidean_half_sorted(before, less), pivot];
|
||||
|
||||
function _border_half_sorted(cells, less) =
|
||||
let(leng = len(cells))
|
||||
leng <= 1 ? cells :
|
||||
leng == 2 ? less(cells[0], cells[1]) ? cells : [cells[1], cells[0]] :
|
||||
let(
|
||||
pivot = cells[0],
|
||||
before = [for(j = 1; j < leng; j = j + 1) if(less(cells[j], pivot)) cells[j]]
|
||||
)
|
||||
before == [] ?
|
||||
[pivot, each _border_half_sorted([for(j = 1; j < leng; j = j + 1) if(!less(cells[j], pivot)) cells[j]], less)] :
|
||||
[each _border_half_sorted(before, less), pivot];
|
||||
|
Reference in New Issue
Block a user