simplify path threshold adaptive to zoom

This commit is contained in:
Ryan Di 2025-02-27 19:09:22 +11:00
parent 33d5886123
commit 0d5091555c
2 changed files with 4 additions and 1 deletions

View file

@ -168,6 +168,7 @@ export class LassoTrail extends AnimatedTrail {
elementsSegments: this.elementsSegments, elementsSegments: this.elementsSegments,
intersectedElements: this.intersectedElements, intersectedElements: this.intersectedElements,
enclosedElements: this.enclosedElements, enclosedElements: this.enclosedElements,
simplifyDistance: 5 / this.app.state.zoom.value,
}; };
this.worker?.postMessage(message); this.worker?.postMessage(message);

View file

@ -79,6 +79,7 @@ export type LassoWorkerInput = {
elementsSegments: ElementsSegments; elementsSegments: ElementsSegments;
intersectedElements: Set<ExcalidrawElement["id"]>; intersectedElements: Set<ExcalidrawElement["id"]>;
enclosedElements: Set<ExcalidrawElement["id"]>; enclosedElements: Set<ExcalidrawElement["id"]>;
simplifyDistance: number;
}; };
export type LassoWorkerOutput = { export type LassoWorkerOutput = {
@ -92,9 +93,10 @@ export const updateSelection = (input: LassoWorkerInput): LassoWorkerOutput => {
elementsSegments, elementsSegments,
intersectedElements, intersectedElements,
enclosedElements, enclosedElements,
simplifyDistance,
} = input; } = input;
// simplify the path to reduce the number of points // simplify the path to reduce the number of points
const path = simplify(lassoPath, 2) as GlobalPoint[]; let path = simplify(lassoPath, simplifyDistance) as GlobalPoint[];
// close the path to form a polygon for enclosure check // close the path to form a polygon for enclosure check
const closedPath = polygonFromPoints(path); const closedPath = polygonFromPoints(path);
// as the path might not enclose a shape anymore, clear before checking // as the path might not enclose a shape anymore, clear before checking