Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

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

Ryan Di4689a6b300d8
diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx
index 322096d634..6a0fd10316 100644
--- a/packages/excalidraw/components/App.tsx
+++ b/packages/excalidraw/components/App.tsx
@@ -4383,6 +4383,7 @@ class App extends React.Component<AppProps, AppState> {
return shouldTestInside(element)
? getClosedCurveShape(
+ element,
roughShape,
[element.x, element.y],
element.angle,
diff --git a/packages/utils/geometry/shape.ts b/packages/utils/geometry/shape.ts
index 1fbcd7935c..87c0fe0992 100644
--- a/packages/utils/geometry/shape.ts
+++ b/packages/utils/geometry/shape.ts
@@ -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) {