Skip to content

Commit

Permalink
fix: hit test for closed sharp curves (excalidraw#7881)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-di authored Apr 12, 2024
1 parent 0ae9b38 commit 4689a6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4383,6 +4383,7 @@ class App extends React.Component<AppProps, AppState> {

return shouldTestInside(element)
? getClosedCurveShape(
element,
roughShape,
[element.x, element.y],
element.angle,
Expand Down
12 changes: 11 additions & 1 deletion packages/utils/geometry/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ExcalidrawFreeDrawElement,
ExcalidrawIframeElement,
ExcalidrawImageElement,
ExcalidrawLinearElement,
ExcalidrawRectangleElement,
ExcalidrawSelectionElement,
ExcalidrawTextElement,
Expand Down Expand Up @@ -233,19 +234,28 @@ 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]],
angleToDegrees(angleInRadian),
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) {
Expand Down

0 comments on commit 4689a6b

Please sign in to comment.