1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 09:44:16 +02:00
This commit is contained in:
Justin Lin
2022-05-04 08:10:03 +08:00
parent 794730402b
commit bd69e673b1
2 changed files with 3 additions and 6 deletions

View File

@@ -7,13 +7,10 @@ function _in_shape_in_any_edges(edges, pt, epsilon) =
) )
is_undef(maybe_last); is_undef(maybe_last);
function _in_shape_interpolate_x(y, p1, p2) =
lookup(y, [[p1.y, p1.x], [p2.y, p2.x]]);
function _in_shape_does_pt_cross(pi, pj, pt) = 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)); ((pi.y - pt.y) * (pj.y - pt.y) < 0) && (pt.x < lookup(pt.y, [[pi.y, pi.x], [pj.y, pj.x]]));
function _in_shape_sub(shapt_pts, leng, pt, cond, i) = function _in_shape_sub(shapt_pts, leng, pt, cond, i = 0) =
let(j = i + 1) 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); 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) edges = __lines_from(shapt_pts, true)
) )
_in_shape_in_any_edges(edges, pt, epsilon) ? include_edge : _in_shape_in_any_edges(edges, pt, epsilon) ? include_edge :
_in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts[leng - 1], shapt_pts[0], pt), 0); _in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts[leng - 1], shapt_pts[0], pt));