mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-04 22:07:44 +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) =
|
use <_impl/_sort_impl.scad>;
|
||||||
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(lt, by = "idx", idx = 0) =
|
function sort(lt, by = "idx", idx = 0) = _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);
|
|
@@ -1,5 +1,5 @@
|
|||||||
include <unittest.scad>;
|
use <unittest.scad>;
|
||||||
include <util/sort.scad>;
|
use <util/sort.scad>;
|
||||||
|
|
||||||
module test_sort() {
|
module test_sort() {
|
||||||
echo("==== test_sort ====");
|
echo("==== test_sort ====");
|
||||||
|
Reference in New Issue
Block a user