mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-16 19:54:29 +02:00
add epsilon
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
function __line_intersection(line_pts1, line_pts2) =
|
function __line_intersection(line_pts1, line_pts2, epsilon = 0.0001) =
|
||||||
let(
|
let(
|
||||||
a1 = line_pts1[0],
|
a1 = line_pts1[0],
|
||||||
a2 = line_pts1[1],
|
a2 = line_pts1[1],
|
||||||
@@ -8,5 +8,5 @@ function __line_intersection(line_pts1, line_pts2) =
|
|||||||
b = b2 - b1,
|
b = b2 - b1,
|
||||||
s = b1 - a1
|
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);
|
a1 + a * cross(s, b) / cross(a, b);
|
@@ -42,12 +42,12 @@ function _bijection__bijection_offset_edges(edges, d) =
|
|||||||
_bijection_offset_edge(edge, dx, dy)
|
_bijection_offset_edge(edge, dx, dy)
|
||||||
];
|
];
|
||||||
|
|
||||||
function bijection_offset(pts, d) =
|
function bijection_offset(pts, d, epsilon = 0.0001) =
|
||||||
let(
|
let(
|
||||||
es = __lines_from(pts, true),
|
es = __lines_from(pts, true),
|
||||||
offset_es = _bijection__bijection_offset_edges(es, d),
|
offset_es = _bijection__bijection_offset_edges(es, d),
|
||||||
leng = len(offset_es),
|
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(
|
concat(
|
||||||
[
|
[
|
||||||
@@ -55,7 +55,7 @@ function bijection_offset(pts, d) =
|
|||||||
let(
|
let(
|
||||||
this_edge = offset_es[i],
|
this_edge = offset_es[i],
|
||||||
next_edge = offset_es[i + 1],
|
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]
|
// p == p to avoid [nan, nan], because [nan, nan] != [nan, nan]
|
||||||
if(p != [] && p == p) p
|
if(p != [] && p == p) p
|
||||||
|
@@ -4,7 +4,7 @@ include <__private__/__lines_from.scad>;
|
|||||||
|
|
||||||
function _trim_shape_any_intersection_sub(lines, line, lines_leng, i, epsilon) =
|
function _trim_shape_any_intersection_sub(lines, line, lines_leng, i, epsilon) =
|
||||||
let(
|
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);
|
(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);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user