From f97366ccdfecdda28c527c59c4886f60513f2816 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 18 Mar 2022 16:19:27 +0800 Subject: [PATCH] refactor --- src/maze/mz_wang_tiles.scad | 6 ++++-- src/voxel/vx_bezier.scad | 4 +++- src/voxel/vx_curve.scad | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/maze/mz_wang_tiles.scad b/src/maze/mz_wang_tiles.scad index f163cc06..411133f8 100644 --- a/src/maze/mz_wang_tiles.scad +++ b/src/maze/mz_wang_tiles.scad @@ -8,11 +8,13 @@ * **/ +use <../__comm__/_pt2_hash.scad>; use <_impl/_mz_wang_tiles_impl.scad>; use ; use ; use <../util/sort.scad>; -use <../util/dedup.scad>; +use <../util/set/hashset.scad>; +use <../util/set/hashset_elems.scad>; function mz_wang_tiles(rows, columns, start = [0, 0], init_cells, seed) = let( @@ -37,7 +39,7 @@ function mz_wang_tiles(rows, columns, start = [0, 0], init_cells, seed) = [for(x = [0:columns - 1]) [x * 2 + 1, 0]], [for(y = [0:rows - 1]) [0, y * 2 + 1]] ), - dot_pts = dedup(sort(all, by = "vt")) + dot_pts = sort(hashset_elems(hashset(all, hash = function(p) _pt2_hash(p))), by = "vt") ) [ for(y = [0:rows - 1], x = [0:columns - 1]) diff --git a/src/voxel/vx_bezier.scad b/src/voxel/vx_bezier.scad index 22d86252..9a379443 100644 --- a/src/voxel/vx_bezier.scad +++ b/src/voxel/vx_bezier.scad @@ -8,6 +8,8 @@ * **/ +use <../__comm__/_pt2_hash.scad>; +use <../__comm__/_pt3_hash.scad>; use <../__comm__/__to2d.scad>; use <../__comm__/__to3d.scad>; use <_impl/_vx_bezier_impl.scad>; @@ -18,6 +20,6 @@ function vx_bezier(p1, p2, p3, p4) = is2d = len(p1) == 2, pts = is2d ? _vx_bezier2(__to3d(p1), __to3d(p2), __to3d(p3), __to3d(p4), []) : _vx_bezier3(p1, p2, p3, p4, []), - deduped = dedup(pts) + deduped = dedup(pts, hash = is2d ? function(p) _pt2_hash(p) : function(p) _pt3_hash(p)) ) is2d ? [for(p = deduped) __to2d(p)] : deduped; \ No newline at end of file diff --git a/src/voxel/vx_curve.scad b/src/voxel/vx_curve.scad index 09b5cbc2..487cd90b 100644 --- a/src/voxel/vx_curve.scad +++ b/src/voxel/vx_curve.scad @@ -8,6 +8,8 @@ * **/ +use <../__comm__/_pt2_hash.scad>; +use <../__comm__/_pt3_hash.scad>; use <_impl/_vx_curve_impl.scad>; use <../util/dedup.scad>; @@ -22,4 +24,4 @@ function vx_curve(points, tightness = 0) = for(i = [0:len(pts) - 2]) pts[i] ], points[leng - 2] - ]); \ No newline at end of file + ], hash = len(points[0]) == 2 ? function(p) _pt2_hash(p) : function(p) _pt3_hash(p)); \ No newline at end of file