fix: collision regressions from vector geometry rewrite (#7902)

This commit is contained in:
Ryan Di 2024-04-17 19:31:12 +08:00 committed by GitHub
parent f92f04c13c
commit bbcca06b94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 8 deletions

View file

@ -12,8 +12,11 @@
* to pure shapes
*/
import { getElementAbsoluteCoords } from "../../excalidraw/element";
import {
ElementsMap,
ExcalidrawDiamondElement,
ExcalidrawElement,
ExcalidrawEllipseElement,
ExcalidrawEmbeddableElement,
ExcalidrawFrameLikeElement,
@ -133,6 +136,36 @@ export const getPolygonShape = (
};
};
// return the selection box for an element, possibly rotated as well
export const getSelectionBoxShape = (
element: ExcalidrawElement,
elementsMap: ElementsMap,
padding = 10,
) => {
let [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(
element,
elementsMap,
true,
);
x1 -= padding;
x2 += padding;
y1 -= padding;
y2 += padding;
const angleInDegrees = angleToDegrees(element.angle);
const center: Point = [cx, cy];
const topLeft = pointRotate([x1, y1], angleInDegrees, center);
const topRight = pointRotate([x2, y1], angleInDegrees, center);
const bottomLeft = pointRotate([x1, y2], angleInDegrees, center);
const bottomRight = pointRotate([x2, y2], angleInDegrees, center);
return {
type: "polygon",
data: [topLeft, topRight, bottomRight, bottomLeft],
} as GeometricShape;
};
// ellipse
export const getEllipseShape = (
element: ExcalidrawEllipseElement,