diff --git a/packages/element/src/sizeHelpers.ts b/packages/element/src/sizeHelpers.ts index 02f6ea9231..b312378579 100644 --- a/packages/element/src/sizeHelpers.ts +++ b/packages/element/src/sizeHelpers.ts @@ -8,25 +8,28 @@ import { pointsEqual } from "@excalidraw/math"; import type { AppState, Offsets, Zoom } from "@excalidraw/excalidraw/types"; import { getCommonBounds, getElementBounds } from "./bounds"; -import { isElbowArrow, isFreeDrawElement, isLinearElement } from "./typeChecks"; +import { isFreeDrawElement, isLinearElement } from "./typeChecks"; import type { ElementsMap, ExcalidrawElement } from "./types"; +export const INVISIBLY_SMALL_ELEMENT_SIZE = 0.1; + // TODO: remove invisible elements consistently actions, so that invisible elements are not recorded by the store, exported, broadcasted or persisted // - perhaps could be as part of a standalone 'cleanup' action, in addition to 'finalize' // - could also be part of `_clearElements` export const isInvisiblySmallElement = ( element: ExcalidrawElement, ): boolean => { - if (isElbowArrow(element)) { + if (isLinearElement(element) || isFreeDrawElement(element)) { return ( element.points.length < 2 || - pointsEqual(element.points[0], element.points[element.points.length - 1]) + pointsEqual( + element.points[0], + element.points[element.points.length - 1], + INVISIBLY_SMALL_ELEMENT_SIZE, + ) ); } - if (isLinearElement(element) || isFreeDrawElement(element)) { - return element.points.length < 2; - } return element.width === 0 && element.height === 0; }; diff --git a/packages/math/src/point.ts b/packages/math/src/point.ts index b6054a10a3..863febfd41 100644 --- a/packages/math/src/point.ts +++ b/packages/math/src/point.ts @@ -91,9 +91,10 @@ export function isPoint(p: unknown): p is LocalPoint | GlobalPoint { export function pointsEqual( a: Point, b: Point, + tolerance: number = PRECISION, ): boolean { const abs = Math.abs; - return abs(a[0] - b[0]) < PRECISION && abs(a[1] - b[1]) < PRECISION; + return abs(a[0] - b[0]) < tolerance && abs(a[1] - b[1]) < tolerance; } /**