From 85611b8754665f4ca0975f77727c385c63198d9f Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Thu, 3 Oct 2024 11:38:42 +0200 Subject: [PATCH] Fix distance filtering --- packages/excalidraw/element/collision.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/excalidraw/element/collision.ts b/packages/excalidraw/element/collision.ts index d6c5225c55..1bf179771b 100644 --- a/packages/excalidraw/element/collision.ts +++ b/packages/excalidraw/element/collision.ts @@ -264,7 +264,7 @@ const intersectRectanguloidWithLine = ( .filter( (p, idx, points) => points.findIndex((d) => pointsEqual(p, d)) === idx, ) - .sort((g, h) => pointDistanceSq(g!, b) - pointDistanceSq(h!, b)) + .sort((g, h) => pointDistanceSq(g!, a) - pointDistanceSq(h!, a)) ); }; @@ -390,7 +390,7 @@ const intersectDiamondWithLine = ( .filter( (p, idx, points) => points.findIndex((d) => pointsEqual(p, d)) === idx, ) - .sort((g, h) => pointDistanceSq(g!, b) - pointDistanceSq(h!, b)) + .sort((g, h) => pointDistanceSq(g!, a) - pointDistanceSq(h!, a)) ); }; @@ -418,5 +418,7 @@ const intersectEllipseWithLine = ( return ellipseLineIntersectionPoints( ellipse(center, element.width / 2 + offset, element.height / 2 + offset), line(rotatedA, rotatedB), - ).map((p) => pointRotateRads(p, center, element.angle)); + ) + .map((p) => pointRotateRads(p, center, element.angle)) + .sort((g, h) => pointDistanceSq(g!, a) - pointDistanceSq(h!, a)); };