From 779203076556189c0d9e002447ec068e24e5d182 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 3 May 2022 17:24:28 +0800 Subject: [PATCH] refactor --- src/voronoi/_impl/_convex_intersection.scad | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/voronoi/_impl/_convex_intersection.scad b/src/voronoi/_impl/_convex_intersection.scad index 98a84a8d..9339b281 100644 --- a/src/voronoi/_impl/_convex_intersection.scad +++ b/src/voronoi/_impl/_convex_intersection.scad @@ -5,18 +5,19 @@ use <../../util/set/hashset_elems.scad>; include <../../__comm__/_pt2_hash.scad>; -function _in_convex_r(i, j, preC, convex_pts, pt, leng, convex_pts, pt) = - j == leng || ( - let(c = cross(convex_pts[i] - pt, convex_pts[j] - pt)) - c * preC > 0 && _in_convex_r(j, j + 1, c, convex_pts, pt, leng, convex_pts, pt) - ); +function _in_convex_r(s, convex_pts, pt, leng, i = 0) = + i + 1 == leng || + s * cross(convex_pts[i] - pt, convex_pts[i + 1] - pt) > 0 && + _in_convex_r(s, convex_pts, pt, leng, i + 1); 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); + let(leng = len(convex_pts)) + _in_convex_r( + cross(convex_pts[leng - 1] - pt, convex_pts[0] - pt), + convex_pts, + pt, + leng + ); function _intersection_ps(closed_shape, line_pts, epsilon) = let(