simplify distance helper and factor out common bounds helper (#581)

* simplify distance helper

* factor out common bounds helper
This commit is contained in:
David Luzar
2020-01-26 19:15:08 +00:00
committed by Christopher Chedeau
parent 5853fba821
commit 7b842fc330
7 changed files with 42 additions and 77 deletions
+17
View File
@@ -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
View File
@@ -1,6 +1,7 @@
export { newElement, newTextElement, duplicateElement } from "./newElement";
export {
getElementAbsoluteCoords,
getCommonBounds,
getDiamondPoints,
getArrowPoints,
getLinePoints,