mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-11-18 19:54:35 +01:00
chore: Refactor doBoundsIntersect (#9657)
This commit is contained in:
@@ -10,6 +10,12 @@ export function rectangle<P extends GlobalPoint | LocalPoint>(
|
||||
return [topLeft, bottomRight] as Rectangle<P>;
|
||||
}
|
||||
|
||||
export function rectangleFromNumberSequence<
|
||||
Point extends LocalPoint | GlobalPoint,
|
||||
>(minX: number, minY: number, maxX: number, maxY: number) {
|
||||
return rectangle(pointFrom<Point>(minX, minY), pointFrom<Point>(maxX, maxY));
|
||||
}
|
||||
|
||||
export function rectangleIntersectLineSegment<
|
||||
Point extends LocalPoint | GlobalPoint,
|
||||
>(r: Rectangle<Point>, l: LineSegment<Point>): Point[] {
|
||||
@@ -22,3 +28,12 @@ export function rectangleIntersectLineSegment<
|
||||
.map((s) => lineSegmentIntersectionPoints(l, s))
|
||||
.filter((i): i is Point => !!i);
|
||||
}
|
||||
|
||||
export function rectangleIntersectRectangle<
|
||||
Point extends LocalPoint | GlobalPoint,
|
||||
>(rectangle1: Rectangle<Point>, rectangle2: Rectangle<Point>): boolean {
|
||||
const [[minX1, minY1], [maxX1, maxY1]] = rectangle1;
|
||||
const [[minX2, minY2], [maxX2, maxY2]] = rectangle2;
|
||||
|
||||
return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user