1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 01:34:12 +02:00
This commit is contained in:
Justin Lin
2019-06-29 10:15:28 +08:00
parent 2b36c42c99
commit e45c16fe3f

View File

@@ -1,19 +1,16 @@
function _sort(pts, i) = function _sort(lt, i) =
let(leng = len(pts)) let(leng = len(lt))
leng <= 1 ? pts : leng <= 1 ? lt :
let( let(
pivot = pts[0], pivot = lt[0],
before = [for(j = 1; j < leng; j = j + 1) if(pts[j][i] < pivot[i]) pts[j]], before = [for(j = 1; j < leng; j = j + 1) if(lt[j][i] < pivot[i]) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(pts[j][i] >= pivot[i]) pts[j]] after = [for(j = 1; j < leng; j = j + 1) if(lt[j][i] >= pivot[i]) lt[j]]
) )
concat(_sort(before, i), [pivot], _sort(after, i)); concat(_sort(before, i), [pivot], _sort(after, i));
function sort(points, by, idx = -1) = function sort(lt, by, idx = -1) =
let( let(
i = by == "x" ? 0 : ( dict = [["x", 0], ["y", 1], ["z", 0], ["idx", idx]],
by == "y" ? 1 : ( i = dict[search(by, dict)[0]][1]
by == "z" ? 2 : idx
)
)
) )
_sort(points, i); _sort(lt, i);