diff --git a/docs/lib-in_line.md b/docs/lib-in_polyline2d.md similarity index 57% rename from docs/lib-in_line.md rename to docs/lib-in_polyline2d.md index 6016b781..bcd3555b 100644 --- a/docs/lib-in_line.md +++ b/docs/lib-in_polyline2d.md @@ -1,4 +1,4 @@ -# in_line +# in_polyline2d Checks wether a point is on a line. @@ -12,7 +12,7 @@ Checks wether a point is on a line. ## Examples - include ; + include ; pts = [ [0, 0], @@ -20,7 +20,7 @@ Checks wether a point is on a line. [10, 10] ]; - echo(in_line(pts, [-2, -3])); // false - echo(in_line(pts, [5, 0])); // true - echo(in_line(pts, [10, 5])); // true - echo(in_line(pts, [10, 15])); // false \ No newline at end of file + echo(in_polyline2d(pts, [-2, -3])); // false + echo(in_polyline2d(pts, [5, 0])); // true + echo(in_polyline2d(pts, [10, 5])); // true + echo(in_polyline2d(pts, [10, 15])); // false \ No newline at end of file diff --git a/src/__private__/__in_line.scad b/src/__private__/__in_line2d.scad similarity index 71% rename from src/__private__/__in_line.scad rename to src/__private__/__in_line2d.scad index 8493bfcc..2a96cd69 100644 --- a/src/__private__/__in_line.scad +++ b/src/__private__/__in_line2d.scad @@ -1,4 +1,4 @@ -function __in_line(line_pts, pt, epsilon = 0.0001) = +function __in_line2d(line_pts, pt, epsilon = 0.0001) = let( v1 = line_pts[0] - pt, v2 = line_pts[1] - pt diff --git a/src/in_line.scad b/src/in_line.scad deleted file mode 100644 index ff6995d9..00000000 --- a/src/in_line.scad +++ /dev/null @@ -1,10 +0,0 @@ -include <__private__/__in_line.scad>; - -function _in_line_sub(line_pts, pt, epsilon, iend, i = 0) = - i == iend ? false : ( - __in_line([line_pts[i], line_pts[i + 1]], pt, epsilon) ? true : - _in_line_sub(line_pts, pt, epsilon, iend, i + 1) - ); - -function in_line(line_pts, pt, epsilon = 0.0001) = _in_line_sub(line_pts, pt, epsilon, len(line_pts) - 1); - \ No newline at end of file diff --git a/src/in_polyline2d.scad b/src/in_polyline2d.scad new file mode 100644 index 00000000..1bb179ab --- /dev/null +++ b/src/in_polyline2d.scad @@ -0,0 +1,10 @@ +include <__private__/__in_line2d.scad>; + +function _in_polyline2d_sub(line_pts, pt, epsilon, iend, i = 0) = + i == iend ? false : ( + __in_line2d([line_pts[i], line_pts[i + 1]], pt, epsilon) ? true : + _in_polyline2d_sub(line_pts, pt, epsilon, iend, i + 1) + ); + +function in_polyline2d(line_pts, pt, epsilon = 0.0001) = _in_polyline2d_sub(line_pts, pt, epsilon, len(line_pts) - 1); + \ No newline at end of file diff --git a/src/in_shape.scad b/src/in_shape.scad index ee7a204b..3617e1b7 100644 --- a/src/in_shape.scad +++ b/src/in_shape.scad @@ -1,5 +1,5 @@ include <__private__/__lines_from.scad>; -include <__private__/__in_line.scad>; +include <__private__/__in_line2d.scad>; function _in_shape_in_line_equation(edge, pt) = let( @@ -14,7 +14,7 @@ function _in_shape_in_line_equation(edge, pt) = function _in_shape_in_any_edges_sub(edges, leng, pt, i, epsilon) = leng == i ? false : ( - __in_line(edges[i], pt, epsilon) ? true : _in_shape_in_any_edges_sub(edges, leng, pt, i + 1, epsilon) + __in_line2d(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, epsilon) = _in_shape_in_any_edges_sub(edges, len(edges), pt, 0, epsilon); diff --git a/src/trim_shape.scad b/src/trim_shape.scad index 5c849dee..f90c8c7e 100644 --- a/src/trim_shape.scad +++ b/src/trim_shape.scad @@ -1,12 +1,12 @@ include <__private__/__line_intersection.scad>; -include <__private__/__in_line.scad>; +include <__private__/__in_line2d.scad>; include <__private__/__lines_from.scad>; function _trim_shape_any_intersection_sub(lines, line, lines_leng, i, epsilon) = let( p = __line_intersection(lines[i], line, epsilon) ) - (p != [] && __in_line(line, p, epsilon) && __in_line(lines[i], p, epsilon)) ? [i, p] : _trim_shape_any_intersection(lines, line, lines_leng, i + 1, epsilon); + (p != [] && __in_line2d(line, p, epsilon) && __in_line2d(lines[i], p, epsilon)) ? [i, p] : _trim_shape_any_intersection(lines, line, lines_leng, i + 1, epsilon); // return [idx, [x, y]] or [] function _trim_shape_any_intersection(lines, line, lines_leng, i, epsilon) =