Virtual whiteboard for sketching hand-drawn like diagrams
fix: move doBoundsIntersect from element/src/bounds.ts to common/math/src/utils.ts (#9650)
zsviczian84e96e939358
diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.tsindex 82bb97e79d..af66ebd9fe 100644--- a/packages/element/src/binding.ts+++ b/packages/element/src/binding.ts@@ -24,6 +24,7 @@ import {pointsEqual,lineSegmentIntersectionPoints,PRECISION,+ doBoundsIntersect,} from "@excalidraw/math";import type { LocalPoint, Radians } from "@excalidraw/math";@@ -32,11 +33,7 @@ import type { AppState } from "@excalidraw/excalidraw/types";import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";-import {- getCenterForBounds,- getElementBounds,- doBoundsIntersect,-} from "./bounds";+import { getCenterForBounds, getElementBounds } from "./bounds";import { intersectElementWithLineSegment } from "./collision";import { distanceToElement } from "./distance";import {diff --git a/packages/element/src/bounds.ts b/packages/element/src/bounds.tsindex d5a6e300d5..260a9bd4ed 100644--- a/packages/element/src/bounds.ts+++ b/packages/element/src/bounds.ts@@ -1165,20 +1165,6 @@ export const getCenterForBounds = (bounds: Bounds): GlobalPoint =>bounds[1] + (bounds[3] - bounds[1]) / 2,);-export const doBoundsIntersect = (- bounds1: Bounds | null,- bounds2: Bounds | null,-): boolean => {- if (bounds1 == null || bounds2 == null) {- return false;- }-- const [minX1, minY1, maxX1, maxY1] = bounds1;- const [minX2, minY2, maxX2, maxY2] = bounds2;-- return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;-};-/*** Get the axis-aligned bounding box for a given element*/diff --git a/packages/element/src/collision.ts b/packages/element/src/collision.tsindex 008b50cc9c..5ae7753e63 100644--- a/packages/element/src/collision.ts+++ b/packages/element/src/collision.ts@@ -11,6 +11,7 @@ import {vectorFromPoint,vectorNormalize,vectorScale,+ doBoundsIntersect,} from "@excalidraw/math";import {@@ -25,7 +26,6 @@ import type { FrameNameBounds } from "@excalidraw/excalidraw/types";import { isPathALoop } from "./utils";import {type Bounds,- doBoundsIntersect,elementCenterPoint,getCenterForBounds,getElementBounds,diff --git a/packages/excalidraw/lasso/utils.ts b/packages/excalidraw/lasso/utils.tsindex 2cab64662b..8256f0069a 100644--- a/packages/excalidraw/lasso/utils.ts+++ b/packages/excalidraw/lasso/utils.ts@@ -4,12 +4,12 @@ import {polygonFromPoints,lineSegment,polygonIncludesPointNonZero,+ doBoundsIntersect,} from "@excalidraw/math";import {type Bounds,computeBoundTextPosition,- doBoundsIntersect,getBoundTextElement,getElementBounds,intersectElementWithLineSegment,diff --git a/packages/math/src/curve.ts b/packages/math/src/curve.tsindex 614f072504..3323456b51 100644--- a/packages/math/src/curve.ts+++ b/packages/math/src/curve.ts@@ -1,8 +1,9 @@-import { doBoundsIntersect, type Bounds } from "@excalidraw/element";+import { type Bounds } from "@excalidraw/element";import { isPoint, pointDistance, pointFrom, pointFromVector } from "./point";import { vector, vectorNormal, vectorNormalize, vectorScale } from "./vector";import { LegendreGaussN24CValues, LegendreGaussN24TValues } from "./constants";+import { doBoundsIntersect } from "./utils";import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";diff --git a/packages/math/src/utils.ts b/packages/math/src/utils.tsindex 8807c275e4..912ddd1358 100644--- a/packages/math/src/utils.ts+++ b/packages/math/src/utils.ts@@ -1,3 +1,5 @@+import { type Bounds } from "@excalidraw/element";+export const PRECISION = 10e-5;export const clamp = (value: number, min: number, max: number) => {@@ -31,3 +33,17 @@ export const isFiniteNumber = (value: any): value is number => {export const isCloseTo = (a: number, b: number, precision = PRECISION) =>Math.abs(a - b) < precision;++export const doBoundsIntersect = (+ bounds1: Bounds | null,+ bounds2: Bounds | null,+): boolean => {+ if (bounds1 == null || bounds2 == null) {+ return false;+ }++ const [minX1, minY1, maxX1, maxY1] = bounds1;+ const [minX2, minY2, maxX2, maxY2] = bounds2;++ return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;+};