mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-10 00:36:40 +02:00
always sort before dedup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use <experimental/_impl/_mz_hamiltonian_impl.scad>;
|
||||
use <experimental/mz_blocks.scad>;
|
||||
use <experimental/mz_get.scad>;
|
||||
use <util/sort.scad>;
|
||||
use <util/dedup.scad>;
|
||||
|
||||
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);
|
@@ -8,4 +8,7 @@ Preview
|
||||
|
||||
- sweep
|
||||
- util/has
|
||||
- util/dedup
|
||||
- util/dedup
|
||||
|
||||
bugs:
|
||||
- util/sort: z not sorted
|
@@ -9,6 +9,9 @@
|
||||
**/
|
||||
|
||||
use <pixel/_impl/_px_circle_impl.scad>;
|
||||
use <util/sort.scad>;
|
||||
use <util/dedup.scad>;
|
||||
|
||||
function px_circle(radius, filled = false) = dedup(_px_circle_impl(radius, filled));
|
||||
function px_circle(radius, filled = false) =
|
||||
let(all = _px_circle_impl(radius, filled))
|
||||
dedup(sort(sort(all, by = "x"), by = "y"), sorted = true);
|
@@ -9,7 +9,9 @@
|
||||
**/
|
||||
|
||||
use <pixel/_impl/_px_cylinder_impl.scad>;
|
||||
use <util/sort.scad>;
|
||||
use <util/dedup.scad>;
|
||||
|
||||
function px_cylinder(r, h, filled = false, thickness = 1) =
|
||||
dedup(_px_cylinder_impl(r, h, filled, thickness));
|
||||
let(all = _px_cylinder_impl(r, h, filled, thickness))
|
||||
dedup(sort(sort(sort(all, by = "x"), by = "y"), by = "z"), sorted = true);
|
@@ -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
|
||||
]
|
||||
)
|
||||
);
|
||||
)
|
||||
dedup(sort(sort(all, by = "x"), by = "y"), sorted = true);
|
@@ -12,6 +12,7 @@ use <__comm__/__to3d.scad>;
|
||||
use <__comm__/__to2d.scad>;
|
||||
use <__comm__/__lines_from.scad>;
|
||||
use <pixel/px_line.scad>;
|
||||
use <util/sort.scad>;
|
||||
use <util/dedup.scad>;
|
||||
|
||||
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);
|
||||
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);
|
Reference in New Issue
Block a user