Common center point util

This commit is contained in:
Mark Tolmacs 2025-02-28 19:39:04 +01:00
parent 0cd5a259ae
commit ca5e9c3ad9
5 changed files with 21 additions and 46 deletions

View file

@ -18,6 +18,7 @@ import { getDiamondPoints } from "./bounds";
import type {
ExcalidrawDiamondElement,
ExcalidrawElement,
ExcalidrawRectanguloidElement,
} from "./types";
@ -68,10 +69,7 @@ export function deconstructRectanguloidElement(
return [sides, []];
}
const center = pointFrom<GlobalPoint>(
element.x + element.width / 2,
element.y + element.height / 2,
);
const center = elementCenterPoint(element);
const r = rectangle(
pointFrom(element.x, element.y),
@ -254,10 +252,7 @@ export function deconstructDiamondElement(
return [[topRight, bottomRight, bottomLeft, topLeft], []];
}
const center = pointFrom<GlobalPoint>(
element.x + element.width / 2,
element.y + element.height / 2,
);
const center = elementCenterPoint(element);
const [top, right, bottom, left]: GlobalPoint[] = [
pointFrom(element.x + topX, element.y + topY),
@ -357,3 +352,10 @@ export function deconstructDiamondElement(
return [sides, corners];
}
export function elementCenterPoint(element: ExcalidrawElement) {
return pointFrom<GlobalPoint>(
element.x + element.width / 2,
element.y + element.height / 2,
);
}