diff --git a/src/util/_impl/_sort_impl.scad b/src/util/_impl/_sort_impl.scad new file mode 100644 index 00000000..c63135f1 --- /dev/null +++ b/src/util/_impl/_sort_impl.scad @@ -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); \ No newline at end of file diff --git a/src/util/sort.scad b/src/util/sort.scad index ddf98614..85aeaa73 100644 --- a/src/util/sort.scad +++ b/src/util/sort.scad @@ -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); \ No newline at end of file +function sort(lt, by = "idx", idx = 0) = _sort_impl(lt, by, idx); \ No newline at end of file diff --git a/test/util/test_sort.scad b/test/util/test_sort.scad index da776a2b..e45ab38a 100644 --- a/test/util/test_sort.scad +++ b/test/util/test_sort.scad @@ -1,5 +1,5 @@ -include ; -include ; +use ; +use ; module test_sort() { echo("==== test_sort ====");