diff --git a/src/__private__/__line_intersection.scad b/src/__private__/__line_intersection.scad index 9d958107..a72cfb44 100644 --- a/src/__private__/__line_intersection.scad +++ b/src/__private__/__line_intersection.scad @@ -1,4 +1,4 @@ -function __line_intersection(line_pts1, line_pts2) = +function __line_intersection(line_pts1, line_pts2, epsilon = 0.0001) = let( a1 = line_pts1[0], a2 = line_pts1[1], @@ -8,5 +8,5 @@ function __line_intersection(line_pts1, line_pts2) = b = b2 - b1, s = b1 - a1 ) - cross(a, b) == 0 ? [] : // they are parallel or conincident edges + abs(cross(a, b)) == epsilon ? [] : // they are parallel or conincident edges a1 + a * cross(s, b) / cross(a, b); \ No newline at end of file diff --git a/src/bijection_offset.scad b/src/bijection_offset.scad index 838c574b..d02291e7 100644 --- a/src/bijection_offset.scad +++ b/src/bijection_offset.scad @@ -42,12 +42,12 @@ function _bijection__bijection_offset_edges(edges, d) = _bijection_offset_edge(edge, dx, dy) ]; -function bijection_offset(pts, d) = +function bijection_offset(pts, d, epsilon = 0.0001) = let( es = __lines_from(pts, true), offset_es = _bijection__bijection_offset_edges(es, d), leng = len(offset_es), - last_p = __line_intersection(offset_es[leng - 1], offset_es[0]) + last_p = __line_intersection(offset_es[leng - 1], offset_es[0], epsilon) ) concat( [ @@ -55,7 +55,7 @@ function bijection_offset(pts, d) = let( this_edge = offset_es[i], next_edge = offset_es[i + 1], - p = __line_intersection(this_edge, next_edge) + p = __line_intersection(this_edge, next_edge, epsilon) ) // p == p to avoid [nan, nan], because [nan, nan] != [nan, nan] if(p != [] && p == p) p diff --git a/src/trim_shape.scad b/src/trim_shape.scad index 3980f7b6..5c849dee 100644 --- a/src/trim_shape.scad +++ b/src/trim_shape.scad @@ -4,7 +4,7 @@ include <__private__/__lines_from.scad>; function _trim_shape_any_intersection_sub(lines, line, lines_leng, i, epsilon) = let( - p = __line_intersection(lines[i], line) + 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);