mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
add a tiny threshold for checks
This commit is contained in:
parent
0d5091555c
commit
ba7e3439f4
2 changed files with 9 additions and 4 deletions
|
@ -166,7 +166,8 @@ const intersectionTest = (
|
||||||
return lassoSegments.some((lassoSegment) =>
|
return lassoSegments.some((lassoSegment) =>
|
||||||
elementSegments.some(
|
elementSegments.some(
|
||||||
(elementSegment) =>
|
(elementSegment) =>
|
||||||
lineSegmentIntersectionPoints(lassoSegment, elementSegment) !== null,
|
// introduce a bit of tolerance to account for roughness and simplification of paths
|
||||||
|
lineSegmentIntersectionPoints(lassoSegment, elementSegment, 1) !== null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -159,13 +159,17 @@ export const distanceToLineSegment = <Point extends LocalPoint | GlobalPoint>(
|
||||||
*/
|
*/
|
||||||
export function lineSegmentIntersectionPoints<
|
export function lineSegmentIntersectionPoints<
|
||||||
Point extends GlobalPoint | LocalPoint,
|
Point extends GlobalPoint | LocalPoint,
|
||||||
>(l: LineSegment<Point>, s: LineSegment<Point>): Point | null {
|
>(
|
||||||
|
l: LineSegment<Point>,
|
||||||
|
s: LineSegment<Point>,
|
||||||
|
threshold?: number,
|
||||||
|
): Point | null {
|
||||||
const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));
|
const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!candidate ||
|
!candidate ||
|
||||||
!pointOnLineSegment(candidate, s) ||
|
!pointOnLineSegment(candidate, s, threshold) ||
|
||||||
!pointOnLineSegment(candidate, l)
|
!pointOnLineSegment(candidate, l, threshold)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue