From 3d24874d6d6ae107d3f779fb355bc2165646ca1d Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 18 Mar 2022 15:54:58 +0800 Subject: [PATCH] refactor --- src/voronoi/_impl/_convex_intersection.scad | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/voronoi/_impl/_convex_intersection.scad b/src/voronoi/_impl/_convex_intersection.scad index bf77c67c..57ed6ad8 100644 --- a/src/voronoi/_impl/_convex_intersection.scad +++ b/src/voronoi/_impl/_convex_intersection.scad @@ -1,7 +1,8 @@ - -use <../../util/dedup.scad>; +use <../../__comm__/_pt2_hash.scad>; use <../../lines_intersection.scad>; use <_convex_ct_clk_order.scad>; +use <../../util/set/hashset.scad>; +use <../../util/set/hashset_elems.scad>; function _in_convex_r(i, j, preC, convex_pts, pt, leng, convex_pts, pt) = j == leng || ( @@ -18,12 +19,18 @@ function _in_convex(convex_pts, pt) = function _intersection_ps(shape, line_pts, epsilon) = - let(pts = [each shape, shape[0]]) - dedup([ - for(i = [0:len(shape) - 1]) - let(p = lines_intersection(line_pts, [pts[i], pts[i + 1]], epsilon = epsilon)) - if(p != []) p - ]); + let( + pts = [each shape, shape[0]], + npts = [ + for(i = [0:len(shape) - 1]) + let(p = lines_intersection(line_pts, [pts[i], pts[i + 1]], epsilon = epsilon)) + if(p != []) p + ], + leng = len(npts) + ) + leng < 2 ? npts : + leng == 2 ? (npts[0] != npts[1] ? npts : [npts[0]]) : + hashset_elems(hashset(npts, hash = function(p) _pt2_hash(p))); function _convex_intersection(shape1, shape2, epsilon = 0.0001) = (shape1 == [] || shape2 == []) ? [] :