mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-01 12:30:33 +02:00
use scad to reduce deps
This commit is contained in:
16
src/util/_impl/_sort_impl.scad
Normal file
16
src/util/_impl/_sort_impl.scad
Normal file
@@ -0,0 +1,16 @@
|
||||
function _sort(lt, i) =
|
||||
let(leng = len(lt))
|
||||
leng <= 1 ? lt :
|
||||
let(
|
||||
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_impl(lt, by, idx) =
|
||||
let(
|
||||
dict = [["x", 0], ["y", 1], ["z", 0], ["idx", idx]],
|
||||
i = dict[search(by, dict)[0]][1]
|
||||
)
|
||||
_sort(lt, i);
|
@@ -8,19 +8,6 @@
|
||||
*
|
||||
**/
|
||||
|
||||
function _sort(lt, i) =
|
||||
let(leng = len(lt))
|
||||
leng <= 1 ? lt :
|
||||
let(
|
||||
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));
|
||||
use <_impl/_sort_impl.scad>;
|
||||
|
||||
function sort(lt, by = "idx", idx = 0) =
|
||||
let(
|
||||
dict = [["x", 0], ["y", 1], ["z", 0], ["idx", idx]],
|
||||
i = dict[search(by, dict)[0]][1]
|
||||
)
|
||||
_sort(lt, i);
|
||||
function sort(lt, by = "idx", idx = 0) = _sort_impl(lt, by, idx);
|
@@ -1,5 +1,5 @@
|
||||
include <unittest.scad>;
|
||||
include <util/sort.scad>;
|
||||
use <unittest.scad>;
|
||||
use <util/sort.scad>;
|
||||
|
||||
module test_sort() {
|
||||
echo("==== test_sort ====");
|
||||
|
Reference in New Issue
Block a user