diff --git a/src/experimental/mz_hamiltonian.scad b/src/experimental/mz_hamiltonian.scad index c6ae1b5b..e3f062d9 100644 --- a/src/experimental/mz_hamiltonian.scad +++ b/src/experimental/mz_hamiltonian.scad @@ -1,6 +1,7 @@ use ; use ; use ; +use ; use ; function mz_hamiltonian(rows, columns, start) = @@ -9,23 +10,22 @@ function mz_hamiltonian(rows, columns, start) = [1, 1], rows, columns ), - dot_pts = dedup( - concat( - [ - for(block = blocks) - let( - x = mz_get(block, "x"), - y = mz_get(block, "y"), - wall_type = mz_get(block, "w"), - pts = wall_type == "UPPER_WALL" ? _mz_hamiltonian_upper(x, y) : - wall_type == "RIGHT_WALL" ? _mz_hamiltonian_right(x, y) : - wall_type == "UPPER_RIGHT_WALL" ? _mz_hamiltonian_upper_right(x, y) : [] - ) - each pts - ], - [for(x = [0:columns * 2 - 1]) [x, 0]], - [for(y = [0:rows * 2 - 1]) [0, y]] - ) - ) + all = concat( + [ + for(block = blocks) + let( + x = mz_get(block, "x"), + y = mz_get(block, "y"), + wall_type = mz_get(block, "w"), + pts = wall_type == "UPPER_WALL" ? _mz_hamiltonian_upper(x, y) : + wall_type == "RIGHT_WALL" ? _mz_hamiltonian_right(x, y) : + wall_type == "UPPER_RIGHT_WALL" ? _mz_hamiltonian_upper_right(x, y) : [] + ) + each pts + ], + [for(x = [0:columns * 2 - 1]) [x, 0]], + [for(y = [0:rows * 2 - 1]) [0, y]] + ), + dot_pts = dedup(sort(sort(all, by = "x"), by = "y"), sorted = true) ) _mz_hamiltonian_travel(dot_pts, start, rows * columns * 4); \ No newline at end of file diff --git a/src/experimental/todo.txt b/src/experimental/todo.txt index 4ad3fe86..c84df401 100644 --- a/src/experimental/todo.txt +++ b/src/experimental/todo.txt @@ -8,4 +8,7 @@ Preview - sweep - util/has -- util/dedup \ No newline at end of file +- util/dedup + +bugs: +- util/sort: z not sorted \ No newline at end of file diff --git a/src/pixel/px_circle.scad b/src/pixel/px_circle.scad index 0110dbf1..43b87746 100644 --- a/src/pixel/px_circle.scad +++ b/src/pixel/px_circle.scad @@ -9,6 +9,9 @@ **/ use ; +use ; use ; -function px_circle(radius, filled = false) = dedup(_px_circle_impl(radius, filled)); \ No newline at end of file +function px_circle(radius, filled = false) = + let(all = _px_circle_impl(radius, filled)) + dedup(sort(sort(all, by = "x"), by = "y"), sorted = true); \ No newline at end of file diff --git a/src/pixel/px_cylinder.scad b/src/pixel/px_cylinder.scad index 80e5b3db..d52ad88b 100644 --- a/src/pixel/px_cylinder.scad +++ b/src/pixel/px_cylinder.scad @@ -9,7 +9,9 @@ **/ use ; +use ; use ; function px_cylinder(r, h, filled = false, thickness = 1) = - dedup(_px_cylinder_impl(r, h, filled, thickness)); \ No newline at end of file + let(all = _px_cylinder_impl(r, h, filled, thickness)) + dedup(sort(sort(sort(all, by = "x"), by = "y"), by = "z"), sorted = true); \ No newline at end of file diff --git a/src/pixel/px_polygon.scad b/src/pixel/px_polygon.scad index 14a6e77c..8c1d461e 100644 --- a/src/pixel/px_polygon.scad +++ b/src/pixel/px_polygon.scad @@ -15,10 +15,8 @@ function px_polygon(points, filled = false) = idxes = search(y, sortedXY, num_returns_per_match = 0, index_col_num = 1) ) [for(i = idxes) sortedXY[i]] - ] - ) - dedup( - concat( + ], + all = concat( sortedXY, [ for(row = rows) @@ -29,4 +27,5 @@ function px_polygon(points, filled = false) = if(in_shape(points, p)) p ] ) - ); \ No newline at end of file + ) + dedup(sort(sort(all, by = "x"), by = "y"), sorted = true); \ No newline at end of file diff --git a/src/pixel/px_polyline.scad b/src/pixel/px_polyline.scad index eefa9e00..48873b22 100644 --- a/src/pixel/px_polyline.scad +++ b/src/pixel/px_polyline.scad @@ -12,6 +12,7 @@ use <__comm__/__to3d.scad>; use <__comm__/__to2d.scad>; use <__comm__/__lines_from.scad>; use ; +use ; use ; function px_polyline(points) = @@ -20,4 +21,8 @@ function px_polyline(points) = pts = is_2d ? [for(pt = points) __to3d(pt)] : points, polyline = [for(line = __lines_from(pts)) each px_line(line[0], line[1])] ) - dedup(is_2d ? [for(pt = polyline) __to2d(pt)] : polyline); \ No newline at end of file + dedup(is_2d ? + sort(sort([for(pt = polyline) __to2d(pt)], by = "x"), by = "y") + : + sort(sort(sort(polyline, by = "x"), by = "y"), by = "z") + , sorted = true); \ No newline at end of file