1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-29 11:58:39 +01:00

refactor: pass i

This commit is contained in:
Justin Lin 2022-05-04 07:49:48 +08:00
parent 444fde9cc0
commit d92586e839
2 changed files with 5 additions and 5 deletions

View File

@ -10,10 +10,10 @@ function _in_shape_in_any_edges(edges, pt, epsilon) =
function _in_shape_interpolate_x(y, p1, p2) =
lookup(y, [[p1.y, p1.x], [p2.y, p2.x]]);
function _in_shape_does_pt_cross(pts, i, j, pt) =
let(pi = pts[i], pj = pts[j])
function _in_shape_does_pt_cross(pi, pj, pt) =
((pi.y - pt.y) * (pj.y - pt.y) < 0) && (pt.x < _in_shape_interpolate_x(pt.y, pi, pj));
function _in_shape_sub(shapt_pts, leng, pt, cond, i, j) =
j == leng ? cond : _in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts, i, j, pt) ? !cond : cond, j, j + 1);
function _in_shape_sub(shapt_pts, leng, pt, cond, i) =
let(j = i + 1)
j == leng ? cond : _in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts[i], shapt_pts[j], pt) ? !cond : cond, j);

View File

@ -17,4 +17,4 @@ function in_shape(shapt_pts, pt, include_edge = false, epsilon = 0.0001) =
edges = __lines_from(shapt_pts, true)
)
_in_shape_in_any_edges(edges, pt, epsilon) ? include_edge :
_in_shape_sub(shapt_pts, leng, pt, false, leng - 1, 0);
_in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts[leng - 1], shapt_pts[0], pt), 0);