Files
Webklar.com/node_modules/react-resizable-panels/src/utils/rects/getIntersectingRectangle.ts
Basilosaurusrex f027651f9b main repo
2025-11-24 18:09:40 +01:00

29 lines
668 B
TypeScript

import { intersects } from "./intersects";
import { Rectangle } from "./types";
export function getIntersectingRectangle(
rectOne: Rectangle,
rectTwo: Rectangle,
strict: boolean
): Rectangle {
if (!intersects(rectOne, rectTwo, strict)) {
return {
x: 0,
y: 0,
width: 0,
height: 0,
};
}
return {
x: Math.max(rectOne.x, rectTwo.x),
y: Math.max(rectOne.y, rectTwo.y),
width:
Math.min(rectOne.x + rectOne.width, rectTwo.x + rectTwo.width) -
Math.max(rectOne.x, rectTwo.x),
height:
Math.min(rectOne.y + rectOne.height, rectTwo.y + rectTwo.height) -
Math.max(rectOne.y, rectTwo.y),
};
}