From ca11fbe0f92ab3149dbda9af14f5f9cdae222a2a Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 15 Dec 2020 08:24:19 +0800 Subject: [PATCH] use _in_convex --- src/voronoi/_impl/_convex_intersection.scad | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/voronoi/_impl/_convex_intersection.scad b/src/voronoi/_impl/_convex_intersection.scad index 9051a5b8..1d4232ac 100644 --- a/src/voronoi/_impl/_convex_intersection.scad +++ b/src/voronoi/_impl/_convex_intersection.scad @@ -1,8 +1,20 @@ -use <../../in_shape.scad>; use <../../lines_intersection.scad>; use <_convex_ct_clk_order.scad>; +function _in_convex_r(i, j, preC, convex_pts, pt, leng, convex_pts, pt) = + j == leng ? true : + let(c = cross(convex_pts[i] - pt, convex_pts[j] - pt)) + c * preC < 0 ? false : _in_convex_r(j, j + 1, c, convex_pts, pt, leng, convex_pts, pt) ; + +function _in_convex(convex_pts, pt) = + let( + leng = len(convex_pts), + c = cross(convex_pts[leng - 1] - pt, convex_pts[0] - pt) + ) + _in_convex_r(0, 1, c, convex_pts, pt, leng, convex_pts, pt); + + function _intersection_ps(shape, line_pts, epsilon) = let( leng = len(shape), @@ -22,8 +34,8 @@ function _convex_intersection(shape1, shape2, epsilon = 0.0001) = ) _convex_ct_clk_order( concat( - [for(p = shape1) if(in_shape(shape2, p, include_edge = true)) p], - [for(p = shape2) if(in_shape(shape1, p, include_edge = true)) p], + [for(p = shape1) if(_in_convex(shape2, p)) p], + [for(p = shape2) if(_in_convex(shape1, p)) p], [for(i = [0:leng - 1]) each _intersection_ps(shape2, [pts[i], pts[i + 1]], epsilon)] ) ); \ No newline at end of file