diff --git a/src/util/sort.scad b/src/util/sort.scad index ce3bbdf4..7c4c4c46 100644 --- a/src/util/sort.scad +++ b/src/util/sort.scad @@ -1,19 +1,16 @@ -function _sort(pts, i) = - let(leng = len(pts)) - leng <= 1 ? pts : +function _sort(lt, i) = + let(leng = len(lt)) + leng <= 1 ? lt : let( - pivot = pts[0], - before = [for(j = 1; j < leng; j = j + 1) if(pts[j][i] < pivot[i]) pts[j]], - after = [for(j = 1; j < leng; j = j + 1) if(pts[j][i] >= pivot[i]) pts[j]] + 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(points, by, idx = -1) = +function sort(lt, by, idx = -1) = let( - i = by == "x" ? 0 : ( - by == "y" ? 1 : ( - by == "z" ? 2 : idx - ) - ) + dict = [["x", 0], ["y", 1], ["z", 0], ["idx", idx]], + i = dict[search(by, dict)[0]][1] ) - _sort(points, i); \ No newline at end of file + _sort(lt, i); \ No newline at end of file