diff --git a/src/__private__/__in_line.scad b/src/__private__/__in_line.scad new file mode 100644 index 00000000..45f0a57e --- /dev/null +++ b/src/__private__/__in_line.scad @@ -0,0 +1,8 @@ +function __in_line(line_pts, pt, epsilon = 0.0001) = + let( + pts = len(line_pts[0]) == 2 ? [for(pt = line_pts) __to3d(pt)] : line_pts, + pt3d = len(pt) == 2 ? __to3d(pt) : pt, + v1 = pts[0] - pt3d, + v2 = pts[1] - pt3d + ) + (norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon); \ No newline at end of file diff --git a/src/__private__/__in_line2d.scad b/src/__private__/__in_line2d.scad deleted file mode 100644 index 12430ba8..00000000 --- a/src/__private__/__in_line2d.scad +++ /dev/null @@ -1,6 +0,0 @@ -function __in_line2d(line_pts, pt, epsilon = 0.0001) = - let( - v1 = line_pts[0] - pt, - v2 = line_pts[1] - pt - ) - (norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon); \ No newline at end of file diff --git a/src/in_polyline.scad b/src/in_polyline.scad index bde6ee46..d2e438ed 100644 --- a/src/in_polyline.scad +++ b/src/in_polyline.scad @@ -1,16 +1,12 @@ include <__private__/__to3d.scad>; -include <__private__/__in_line2d.scad>; +include <__private__/__in_line.scad>; function _in_polyline_sub(pts, pt, epsilon, iend, i = 0) = i == iend ? false : ( - __in_line2d([pts[i], pts[i + 1]], pt, epsilon) ? true : + __in_line([pts[i], pts[i + 1]], pt, epsilon) ? true : _in_polyline_sub(pts, pt, epsilon, iend, i + 1) ); function in_polyline(line_pts, pt, epsilon = 0.0001) = - let( - pts = len(line_pts[0]) == 2 ? [for(pt = line_pts) __to3d(pt)] : line_pts, - pt3d = len(pt) == 2 ? __to3d(pt) : pt - ) - _in_polyline_sub(pts, pt3d, epsilon, len(pts) - 1); + _in_polyline_sub(line_pts, pt, epsilon, len(pts) - 1); \ No newline at end of file