diff --git a/packages/math/src/point.ts b/packages/math/src/point.ts index 923377dc08..2687ea9881 100644 --- a/packages/math/src/point.ts +++ b/packages/math/src/point.ts @@ -245,18 +245,20 @@ export const isPointWithinBounds =
( export const perpendicularDistance =
( p: P, start: P, - end: P): - number => { + end: P, +): number => { const dx = end[0] - start[0]; const dy = end[1] - start[1]; if (dx === 0 && dy === 0) { return Math.hypot(p[0] - start[0], p[1] - start[1]); } // Equation of line distance - const numerator = Math.abs(dy * p[0] - dx * p[1] + end[0] * start[1] - end[1] * start[0]); + const numerator = Math.abs( + dy * p[0] - dx * p[1] + end[0] * start[1] - end[1] * start[0], + ); const denom = Math.hypot(dx, dy); return numerator / denom; -} +}; /** * Calculates the angle between three points in degrees. * The angle is calculated at the first point (p0) using the second (p1) and third (p2) points. @@ -266,7 +268,7 @@ export const perpendicularDistance =
( * @param p1 The vertex point where the angle is calculated. * @param p2 The second point used to form the angle. * @returns The angle in degrees between the three points. -**/ + **/ export const angleBetween =
( p0: P, p1: P, @@ -276,8 +278,12 @@ export const angleBetween =
( const v2 = vectorFromPoint(p1, p2); // dot and cross product - const magnitude1 = Math.hypot(v1[0], v1[1]), magnitude2 = Math.hypot(v2[0], v2[1]); - if (magnitude1 === 0 || magnitude2 === 0) return 0 as Degrees; + const magnitude1 = Math.hypot(v1[0], v1[1]); + const magnitude2 = Math.hypot(v2[0], v2[1]); + + if (magnitude1 === 0 || magnitude2 === 0) { + return 0 as Degrees; + } const dot = vectorDot(v1, v2); @@ -287,4 +293,4 @@ export const angleBetween =
(
const rad = Math.acos(cos) as Radians;
return radiansToDegrees(rad);
-}
+};
diff --git a/packages/utils/src/snapToShape.ts b/packages/utils/src/snapToShape.ts
index 4707c4f4f6..9d900b78eb 100644
--- a/packages/utils/src/snapToShape.ts
+++ b/packages/utils/src/snapToShape.ts
@@ -1,3 +1,23 @@
+import {
+ getCenterForBounds,
+ getCommonBoundingBox,
+} from "@excalidraw/element/bounds";
+import {
+ newArrowElement,
+ newElement,
+ newLinearElement,
+} from "@excalidraw/element/newElement";
+
+import {
+ angleBetween,
+ perpendicularDistance,
+ pointDistance,
+} from "@excalidraw/math";
+import { ROUNDNESS } from "@excalidraw/common";
+
+import type { LocalPoint } from "@excalidraw/math";
+
+import type { BoundingBox, Bounds } from "@excalidraw/element/bounds";
import type {
ExcalidrawArrowElement,
ExcalidrawDiamondElement,
@@ -7,11 +27,6 @@ import type {
ExcalidrawLinearElement,
ExcalidrawRectangleElement,
} from "@excalidraw/element/types";
-import type { BoundingBox, Bounds } from "@excalidraw/element/bounds";
-import { getCenterForBounds, getCommonBoundingBox } from "@excalidraw/element/bounds";
-import { newArrowElement, newElement, newLinearElement } from "@excalidraw/element/newElement";
-import { angleBetween, GlobalPoint, LocalPoint, perpendicularDistance, pointDistance } from "@excalidraw/math";
-import { ROUNDNESS } from "@excalidraw/common";
type Shape =
| ExcalidrawRectangleElement["type"]
@@ -53,7 +68,6 @@ const DEFAULT_OPTIONS = {
ellipseRadiusVarianceThreshold: 0.5,
} as const; // Use 'as const' for stricter typing of default values
-
// Options for shape recognition, allowing partial overrides
type ShapeRecognitionOptions = typeof DEFAULT_OPTIONS;
type PartialShapeRecognitionOptions = Partial