1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-28 08:50:30 +02:00

add epsilon

This commit is contained in:
Justin Lin
2019-05-29 09:08:34 +08:00
parent e0256a0925
commit 7dbfbc3741
3 changed files with 8 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
function __in_line(line_pts, pt) =
function __in_line(line_pts, pt, epsilon = 0.0001) =
let(
v1 = line_pts[0] - pt,
v2 = line_pts[1] - pt
)
(cross(v1, v2) == 0) && ((v1 * v2) <= 0);
(abs(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon);

View File

@@ -1,3 +1,3 @@
include <__private__/__in_line.scad>;
function in_line(line_pts, pt) = __in_line(line_pts, pt);
function in_line(line_pts, pt, epsilon = 0.0001) = __in_line(line_pts, pt, epsilon);

View File

@@ -12,14 +12,13 @@ function _in_shape_in_line_equation(edge, pt) =
)
(pt[1] == a * pt[0] + b);
function _in_shape_in_any_edges_sub(edges, leng, pt, i) =
function _in_shape_in_any_edges_sub(edges, leng, pt, i, epsilon) =
leng == i ? false : (
__in_line(edges[i], pt) ? true : _in_shape_in_any_edges_sub(edges, leng, pt, i + 1)
__in_line(edges[i], pt, epsilon) ? true : _in_shape_in_any_edges_sub(edges, leng, pt, i + 1, epsilon)
);
function _in_shape_in_any_edges(edges, pt) = _in_shape_in_any_edges_sub(edges, len(edges), pt, 0);
function _in_shape_in_any_edges(edges, pt, epsilon) = _in_shape_in_any_edges_sub(edges, len(edges), pt, 0, epsilon);
function _in_shape_interpolate_x(y, p1, p2) =
p1[1] == p2[1] ? p1[0] : (
p1[0] + (p2[0] - p1[0]) * (y - p1[1]) / (p2[1] - p1[1])
@@ -37,10 +36,10 @@ function _in_shape_sub(shapt_pts, leng, pt, cond, i, j) =
_in_shape_sub(shapt_pts, leng, pt, cond, j, j + 1)
);
function in_shape(shapt_pts, pt, include_edge = false) =
function in_shape(shapt_pts, pt, include_edge = false, epsilon = 0.0001) =
let(
leng = len(shapt_pts),
edges = __edges_from(points)
)
_in_shape_in_any_edges(edges, pt) ? include_edge :
_in_shape_in_any_edges(edges, pt, epsilon) ? include_edge :
_in_shape_sub(shapt_pts, leng, pt, false, leng - 1, 0);