mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Unify bounds calculation
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
parent
c0915c6b98
commit
0c47bd0004
9 changed files with 80 additions and 94 deletions
|
@ -2,7 +2,6 @@ import type {
|
|||
ExcalidrawElement,
|
||||
ExcalidrawLinearElement,
|
||||
ExcalidrawFreeDrawElement,
|
||||
NonDeleted,
|
||||
ExcalidrawTextElementWithContainer,
|
||||
ElementsMap,
|
||||
} from "./types";
|
||||
|
@ -643,33 +642,6 @@ export const getClosestElementBounds = (
|
|||
return getElementBounds(closestElement, elementsMap);
|
||||
};
|
||||
|
||||
export interface BoundingBox {
|
||||
minX: number;
|
||||
minY: number;
|
||||
maxX: number;
|
||||
maxY: number;
|
||||
midX: number;
|
||||
midY: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export const getCommonBoundingBox = (
|
||||
elements: ExcalidrawElement[] | readonly NonDeleted<ExcalidrawElement>[],
|
||||
): BoundingBox => {
|
||||
const [minX, minY, maxX, maxY] = getCommonBounds(elements);
|
||||
return {
|
||||
minX,
|
||||
minY,
|
||||
maxX,
|
||||
maxY,
|
||||
width: maxX - minX,
|
||||
height: maxY - minY,
|
||||
midX: (minX + maxX) / 2,
|
||||
midY: (minY + maxY) / 2,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* returns scene coords of user's editor viewport (visible canvas area) bounds
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@ import {
|
|||
getElementAbsoluteCoords,
|
||||
getCommonBounds,
|
||||
getResizedElementAbsoluteCoords,
|
||||
getCommonBoundingBox,
|
||||
} from "./bounds";
|
||||
import {
|
||||
isArrowElement,
|
||||
|
@ -808,9 +807,11 @@ export const resizeMultipleElements = (
|
|||
return [...acc, { ...text, ...xy }];
|
||||
}, [] as ExcalidrawTextElementWithContainer[]);
|
||||
|
||||
const { minX, minY, maxX, maxY, midX, midY } = getCommonBoundingBox(
|
||||
const [minX, minY, maxX, maxY] = getCommonBounds(
|
||||
targetElements.map(({ orig }) => orig).concat(boundTextElements),
|
||||
);
|
||||
const midX = (minX + maxX) / 2;
|
||||
const midY = (minY + maxY) / 2;
|
||||
const width = maxX - minX;
|
||||
const height = maxY - minY;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue