1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 09:14:29 +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) =
let(leng = len(pts))
leng <= 1 ? pts :
function _sort(lt, i) =
let(leng = len(lt))
leng <= 1 ? lt :
let(
pivot = pts[0],
before = [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(pts[j][i] >= pivot[i]) pts[j]]
pivot = lt[0],
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(lt[j][i] >= pivot[i]) lt[j]]
)
concat(_sort(before, i), [pivot], _sort(after, i));
function sort(points, by, idx = -1) =
function sort(lt, by, idx = -1) =
let(
i = by == "x" ? 0 : (
by == "y" ? 1 : (
by == "z" ? 2 : idx
)
)
dict = [["x", 0], ["y", 1], ["z", 0], ["idx", idx]],
i = dict[search(by, dict)[0]][1]
)
_sort(points, i);
_sort(lt, i);