fix: move doBoundsIntersect from element/src/bounds.ts to common/math/src/utils.ts (#9650)

move doBoundsIntersect to math/utils

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
zsviczian 2025-06-14 13:01:30 +02:00 committed by GitHub
parent 320af405e9
commit 84e96e9393
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 22 deletions

View File

@ -24,6 +24,7 @@ import {
pointsEqual, pointsEqual,
lineSegmentIntersectionPoints, lineSegmentIntersectionPoints,
PRECISION, PRECISION,
doBoundsIntersect,
} from "@excalidraw/math"; } from "@excalidraw/math";
import type { LocalPoint, Radians } 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 type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
import { import { getCenterForBounds, getElementBounds } from "./bounds";
getCenterForBounds,
getElementBounds,
doBoundsIntersect,
} from "./bounds";
import { intersectElementWithLineSegment } from "./collision"; import { intersectElementWithLineSegment } from "./collision";
import { distanceToElement } from "./distance"; import { distanceToElement } from "./distance";
import { import {

View File

@ -1165,20 +1165,6 @@ export const getCenterForBounds = (bounds: Bounds): GlobalPoint =>
bounds[1] + (bounds[3] - bounds[1]) / 2, 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 * Get the axis-aligned bounding box for a given element
*/ */

View File

@ -11,6 +11,7 @@ import {
vectorFromPoint, vectorFromPoint,
vectorNormalize, vectorNormalize,
vectorScale, vectorScale,
doBoundsIntersect,
} from "@excalidraw/math"; } from "@excalidraw/math";
import { import {
@ -25,7 +26,6 @@ import type { FrameNameBounds } from "@excalidraw/excalidraw/types";
import { isPathALoop } from "./utils"; import { isPathALoop } from "./utils";
import { import {
type Bounds, type Bounds,
doBoundsIntersect,
elementCenterPoint, elementCenterPoint,
getCenterForBounds, getCenterForBounds,
getElementBounds, getElementBounds,

View File

@ -4,12 +4,12 @@ import {
polygonFromPoints, polygonFromPoints,
lineSegment, lineSegment,
polygonIncludesPointNonZero, polygonIncludesPointNonZero,
doBoundsIntersect,
} from "@excalidraw/math"; } from "@excalidraw/math";
import { import {
type Bounds, type Bounds,
computeBoundTextPosition, computeBoundTextPosition,
doBoundsIntersect,
getBoundTextElement, getBoundTextElement,
getElementBounds, getElementBounds,
intersectElementWithLineSegment, intersectElementWithLineSegment,

View File

@ -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 { isPoint, pointDistance, pointFrom, pointFromVector } from "./point";
import { vector, vectorNormal, vectorNormalize, vectorScale } from "./vector"; import { vector, vectorNormal, vectorNormalize, vectorScale } from "./vector";
import { LegendreGaussN24CValues, LegendreGaussN24TValues } from "./constants"; import { LegendreGaussN24CValues, LegendreGaussN24TValues } from "./constants";
import { doBoundsIntersect } from "./utils";
import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types"; import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";

View File

@ -1,3 +1,5 @@
import { type Bounds } from "@excalidraw/element";
export const PRECISION = 10e-5; export const PRECISION = 10e-5;
export const clamp = (value: number, min: number, max: number) => { 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) => export const isCloseTo = (a: number, b: number, precision = PRECISION) =>
Math.abs(a - b) < 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;
};