mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-04-19 21:51:57 +02:00
by vt, for example, sort by zyx for points
This commit is contained in:
parent
5b0f5c0259
commit
cd0a24e17f
@ -1,3 +1,22 @@
|
||||
function _greaterThan(elem1, elem2, i) =
|
||||
i == -1 ? false :
|
||||
elem1[i] > elem2[i] ? true :
|
||||
elem1[i] == elem2[i] ? _greaterThan(elem1, elem2, i - 1) : false;
|
||||
|
||||
function greaterThan(elem1, elem2) = _greaterThan(elem1, elem2, len(elem1));
|
||||
|
||||
function lessThan(elem1, elem2) = !greaterThan(elem1, elem2) && elem1 != elem2;
|
||||
|
||||
function _default_sort(lt) =
|
||||
let(leng = len(lt))
|
||||
leng <= 1 ? lt :
|
||||
let(
|
||||
pivot = lt[0],
|
||||
before = [for(j = 1; j < leng; j = j + 1) if(lessThan(lt[j], pivot)) lt[j]],
|
||||
after = [for(j = 1; j < leng; j = j + 1) if(greaterThan(lt[j], pivot) || lt[j] == pivot) lt[j]]
|
||||
)
|
||||
concat(_default_sort(before), [pivot], _default_sort(after));
|
||||
|
||||
function _sort(lt, i) =
|
||||
let(leng = len(lt))
|
||||
leng <= 1 ? lt :
|
||||
|
@ -10,4 +10,6 @@
|
||||
|
||||
use <util/_impl/_sort_impl.scad>;
|
||||
|
||||
function sort(lt, by = "idx", idx = 0) = _sort_impl(lt, by, idx);
|
||||
function sort(lt, by = "idx", idx = 0) =
|
||||
by == "vt" ? _default_sort(lt) : // for example, sort by zyx for a list of points
|
||||
_sort_impl(lt, by, idx);
|
Loading…
x
Reference in New Issue
Block a user