1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-13 18:24:28 +02:00

always sort before dedup

This commit is contained in:
Justin Lin
2020-03-13 09:19:39 +08:00
parent 2413e9160f
commit f6b9b4b0c5
6 changed files with 39 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
use <experimental/_impl/_mz_hamiltonian_impl.scad>; use <experimental/_impl/_mz_hamiltonian_impl.scad>;
use <experimental/mz_blocks.scad>; use <experimental/mz_blocks.scad>;
use <experimental/mz_get.scad>; use <experimental/mz_get.scad>;
use <util/sort.scad>;
use <util/dedup.scad>; use <util/dedup.scad>;
function mz_hamiltonian(rows, columns, start) = function mz_hamiltonian(rows, columns, start) =
@@ -9,8 +10,7 @@ function mz_hamiltonian(rows, columns, start) =
[1, 1], [1, 1],
rows, columns rows, columns
), ),
dot_pts = dedup( all = concat(
concat(
[ [
for(block = blocks) for(block = blocks)
let( let(
@@ -25,7 +25,7 @@ function mz_hamiltonian(rows, columns, start) =
], ],
[for(x = [0:columns * 2 - 1]) [x, 0]], [for(x = [0:columns * 2 - 1]) [x, 0]],
[for(y = [0:rows * 2 - 1]) [0, y]] [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); _mz_hamiltonian_travel(dot_pts, start, rows * columns * 4);

View File

@@ -9,3 +9,6 @@ Preview
- sweep - sweep
- util/has - util/has
- util/dedup - util/dedup
bugs:
- util/sort: z not sorted

View File

@@ -9,6 +9,9 @@
**/ **/
use <pixel/_impl/_px_circle_impl.scad>; use <pixel/_impl/_px_circle_impl.scad>;
use <util/sort.scad>;
use <util/dedup.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);

View File

@@ -9,7 +9,9 @@
**/ **/
use <pixel/_impl/_px_cylinder_impl.scad>; use <pixel/_impl/_px_cylinder_impl.scad>;
use <util/sort.scad>;
use <util/dedup.scad>; use <util/dedup.scad>;
function px_cylinder(r, h, filled = false, thickness = 1) = 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);

View File

@@ -15,10 +15,8 @@ function px_polygon(points, filled = false) =
idxes = search(y, sortedXY, num_returns_per_match = 0, index_col_num = 1) idxes = search(y, sortedXY, num_returns_per_match = 0, index_col_num = 1)
) )
[for(i = idxes) sortedXY[i]] [for(i = idxes) sortedXY[i]]
] ],
) all = concat(
dedup(
concat(
sortedXY, sortedXY,
[ [
for(row = rows) for(row = rows)
@@ -29,4 +27,5 @@ function px_polygon(points, filled = false) =
if(in_shape(points, p)) p if(in_shape(points, p)) p
] ]
) )
); )
dedup(sort(sort(all, by = "x"), by = "y"), sorted = true);

View File

@@ -12,6 +12,7 @@ use <__comm__/__to3d.scad>;
use <__comm__/__to2d.scad>; use <__comm__/__to2d.scad>;
use <__comm__/__lines_from.scad>; use <__comm__/__lines_from.scad>;
use <pixel/px_line.scad>; use <pixel/px_line.scad>;
use <util/sort.scad>;
use <util/dedup.scad>; use <util/dedup.scad>;
function px_polyline(points) = function px_polyline(points) =
@@ -20,4 +21,8 @@ function px_polyline(points) =
pts = is_2d ? [for(pt = points) __to3d(pt)] : points, pts = is_2d ? [for(pt = points) __to3d(pt)] : points,
polyline = [for(line = __lines_from(pts)) each px_line(line[0], line[1])] 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);