1
0
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:
Justin Lin
2020-01-26 16:54:09 +08:00
parent c16d43669e
commit 8c4fb236bf
3 changed files with 20 additions and 17 deletions

View 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);

View File

@@ -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);

View File

@@ -1,5 +1,5 @@
include <unittest.scad>;
include <util/sort.scad>;
use <unittest.scad>;
use <util/sort.scad>;
module test_sort() {
echo("==== test_sort ====");