fix: lasso selection issues (#9353)

* revert stroke slicing hack for knot

* fix incorrect closing of path

* nonzero enclosure

* lint
This commit is contained in:
Ryan Di
2025-04-08 00:50:52 +10:00
committed by GitHub
parent e48b63a0ae
commit 6fc85022ae
3 changed files with 35 additions and 15 deletions
+6 -10
View File
@@ -2,9 +2,9 @@ import { simplify } from "points-on-curve";
import {
polygonFromPoints,
polygonIncludesPoint,
lineSegment,
lineSegmentIntersectionPoints,
polygonIncludesPointNonZero,
} from "@excalidraw/math";
import type { GlobalPoint, LineSegment } from "@excalidraw/math/types";
@@ -35,8 +35,6 @@ export const getLassoSelectedElementIds = (input: {
if (simplifyDistance) {
path = simplify(lassoPath, simplifyDistance) as GlobalPoint[];
}
// close the path to form a polygon for enclosure check
const closedPath = polygonFromPoints(path);
// as the path might not enclose a shape anymore, clear before checking
enclosedElements.clear();
for (const element of elements) {
@@ -44,15 +42,11 @@ export const getLassoSelectedElementIds = (input: {
!intersectedElements.has(element.id) &&
!enclosedElements.has(element.id)
) {
const enclosed = enclosureTest(closedPath, element, elementsSegments);
const enclosed = enclosureTest(path, element, elementsSegments);
if (enclosed) {
enclosedElements.add(element.id);
} else {
const intersects = intersectionTest(
closedPath,
element,
elementsSegments,
);
const intersects = intersectionTest(path, element, elementsSegments);
if (intersects) {
intersectedElements.add(element.id);
}
@@ -79,7 +73,9 @@ const enclosureTest = (
}
return segments.some((segment) => {
return segment.some((point) => polygonIncludesPoint(point, lassoPolygon));
return segment.some((point) =>
polygonIncludesPointNonZero(point, lassoPolygon),
);
});
};