From ba7e3439f4f49e4c9a9467d87af9332ecf46aad5 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Fri, 28 Feb 2025 15:41:35 +1100 Subject: [PATCH] add a tiny threshold for checks --- packages/excalidraw/lasso/worker.ts | 3 ++- packages/math/segment.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/excalidraw/lasso/worker.ts b/packages/excalidraw/lasso/worker.ts index aa1379c90..74290a9a9 100644 --- a/packages/excalidraw/lasso/worker.ts +++ b/packages/excalidraw/lasso/worker.ts @@ -166,7 +166,8 @@ const intersectionTest = ( return lassoSegments.some((lassoSegment) => elementSegments.some( (elementSegment) => - lineSegmentIntersectionPoints(lassoSegment, elementSegment) !== null, + // introduce a bit of tolerance to account for roughness and simplification of paths + lineSegmentIntersectionPoints(lassoSegment, elementSegment, 1) !== null, ), ); }; diff --git a/packages/math/segment.ts b/packages/math/segment.ts index 60943aacb..608342471 100644 --- a/packages/math/segment.ts +++ b/packages/math/segment.ts @@ -159,13 +159,17 @@ export const distanceToLineSegment = ( */ export function lineSegmentIntersectionPoints< Point extends GlobalPoint | LocalPoint, ->(l: LineSegment, s: LineSegment): Point | null { +>( + l: LineSegment, + s: LineSegment, + threshold?: number, +): Point | null { const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1])); if ( !candidate || - !pointOnLineSegment(candidate, s) || - !pointOnLineSegment(candidate, l) + !pointOnLineSegment(candidate, s, threshold) || + !pointOnLineSegment(candidate, l, threshold) ) { return null; }