mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
simplify path threshold adaptive to zoom
This commit is contained in:
parent
33d5886123
commit
0d5091555c
2 changed files with 4 additions and 1 deletions
|
@ -168,6 +168,7 @@ export class LassoTrail extends AnimatedTrail {
|
|||
elementsSegments: this.elementsSegments,
|
||||
intersectedElements: this.intersectedElements,
|
||||
enclosedElements: this.enclosedElements,
|
||||
simplifyDistance: 5 / this.app.state.zoom.value,
|
||||
};
|
||||
|
||||
this.worker?.postMessage(message);
|
||||
|
|
|
@ -79,6 +79,7 @@ export type LassoWorkerInput = {
|
|||
elementsSegments: ElementsSegments;
|
||||
intersectedElements: Set<ExcalidrawElement["id"]>;
|
||||
enclosedElements: Set<ExcalidrawElement["id"]>;
|
||||
simplifyDistance: number;
|
||||
};
|
||||
|
||||
export type LassoWorkerOutput = {
|
||||
|
@ -92,9 +93,10 @@ export const updateSelection = (input: LassoWorkerInput): LassoWorkerOutput => {
|
|||
elementsSegments,
|
||||
intersectedElements,
|
||||
enclosedElements,
|
||||
simplifyDistance,
|
||||
} = input;
|
||||
// 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
|
||||
const closedPath = polygonFromPoints(path);
|
||||
// as the path might not enclose a shape anymore, clear before checking
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue