mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
simplify distance helper and factor out common bounds helper (#581)
* simplify distance helper * factor out common bounds helper
This commit is contained in:
parent
5853fba821
commit
7b842fc330
7 changed files with 42 additions and 77 deletions
|
@ -57,3 +57,20 @@ export function getLinePoints(element: ExcalidrawElement) {
|
|||
|
||||
return [x1, y1, x2, y2];
|
||||
}
|
||||
|
||||
export function getCommonBounds(elements: readonly ExcalidrawElement[]) {
|
||||
let minX = Infinity;
|
||||
let maxX = -Infinity;
|
||||
let minY = Infinity;
|
||||
let maxY = -Infinity;
|
||||
|
||||
elements.forEach(element => {
|
||||
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
|
||||
minX = Math.min(minX, x1);
|
||||
minY = Math.min(minY, y1);
|
||||
maxX = Math.max(maxX, x2);
|
||||
maxY = Math.max(maxY, y2);
|
||||
});
|
||||
|
||||
return [minX, minY, maxX, maxY];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
export { newElement, newTextElement, duplicateElement } from "./newElement";
|
||||
export {
|
||||
getElementAbsoluteCoords,
|
||||
getCommonBounds,
|
||||
getDiamondPoints,
|
||||
getArrowPoints,
|
||||
getLinePoints,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue