fix: hit test for closed sharp curves (#7881)

This commit is contained in:
Ryan Di 2024-04-12 18:58:51 +08:00 committed by GitHub
parent 0ae9b383d6
commit 4689a6b300
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -4383,6 +4383,7 @@ class App extends React.Component<AppProps, AppState> {
return shouldTestInside(element)
? getClosedCurveShape(
element,
roughShape,
[element.x, element.y],
element.angle,

View File

@ -20,6 +20,7 @@ import {
ExcalidrawFreeDrawElement,
ExcalidrawIframeElement,
ExcalidrawImageElement,
ExcalidrawLinearElement,
ExcalidrawRectangleElement,
ExcalidrawSelectionElement,
ExcalidrawTextElement,
@ -233,12 +234,12 @@ export const getFreedrawShape = (
};
export const getClosedCurveShape = (
element: ExcalidrawLinearElement,
roughShape: Drawable,
startingPoint: Point = [0, 0],
angleInRadian: number,
center: Point,
): GeometricShape => {
const ops = getCurvePathOps(roughShape);
const transform = (p: Point) =>
pointRotate(
[p[0] + startingPoint[0], p[1] + startingPoint[1]],
@ -246,6 +247,15 @@ export const getClosedCurveShape = (
center,
);
if (element.roundness === null) {
return {
type: "polygon",
data: close(element.points.map((p) => transform(p as Point))),
};
}
const ops = getCurvePathOps(roughShape);
const points: Point[] = [];
let odd = false;
for (const operation of ops) {