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

add epsilon

This commit is contained in:
Justin Lin
2019-05-29 13:41:31 +08:00
parent 652f763c90
commit 6a83c26e9b
3 changed files with 6 additions and 6 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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);