This commit is contained in:
Ryan Di 2025-04-09 11:28:13 +10:00
parent 2032c857fe
commit 4eefbdbf8f

View file

@ -82,18 +82,15 @@ export class EraserTrail extends AnimatedTrail {
}
private updateElementsToBeErased(restoreToErase?: boolean) {
let eraserPath = super
.getCurrentTrail()
?.originalPoints?.map((p) => pointFrom<GlobalPoint>(p[0], p[1]));
let eraserPath: GlobalPoint[] =
super
.getCurrentTrail()
?.originalPoints?.map((p) => pointFrom<GlobalPoint>(p[0], p[1])) || [];
// for efficiency and avoid unnecessary calculations,
// take only POINTS_ON_TRAIL points to form some number of segments
eraserPath = eraserPath?.slice(eraserPath.length - POINTS_ON_TRAIL);
if (!eraserPath || eraserPath.length === 0) {
return [];
}
const visibleElementsMap = arrayToMap(this.app.visibleElements);
const pathSegments = eraserPath.reduce((acc, point, index) => {
@ -104,6 +101,10 @@ export class EraserTrail extends AnimatedTrail {
return acc;
}, [] as LineSegment<GlobalPoint>[]);
if (pathSegments.length === 0) {
return [];
}
for (const element of this.app.visibleElements) {
// restore only if already added to the to-be-erased set
if (restoreToErase && this.elementsToErase.has(element.id)) {