mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Move path related function into the math package
This commit is contained in:
parent
1b56cf90fb
commit
9eb08df3ea
9 changed files with 72 additions and 46 deletions
|
@ -2,9 +2,11 @@ export * from "./arc";
|
|||
export * from "./angle";
|
||||
export * from "./curve";
|
||||
export * from "./line";
|
||||
export * from "./path";
|
||||
export * from "./point";
|
||||
export * from "./polygon";
|
||||
export * from "./range";
|
||||
export * from "./rectangle";
|
||||
export * from "./segment";
|
||||
export * from "./triangle";
|
||||
export * from "./types";
|
||||
|
|
27
packages/math/path.ts
Normal file
27
packages/math/path.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { pointDistance } from "./point";
|
||||
import type { LocalPoint } from "./types";
|
||||
|
||||
/**
|
||||
* Checks if the first and last point are close enough to be considered a loop
|
||||
*
|
||||
* @param points
|
||||
* @param threshold
|
||||
* @returns
|
||||
*/
|
||||
export const pathIsALoop = (
|
||||
points: readonly LocalPoint[],
|
||||
/** supply if you want the loop detection to account for current zoom */
|
||||
threshold: number,
|
||||
//zoomValue: Zoom["value"] = 1 as NormalizedZoomValue,
|
||||
): boolean => {
|
||||
if (points.length >= 3) {
|
||||
const [first, last] = [points[0], points[points.length - 1]];
|
||||
const distance = pointDistance(first, last);
|
||||
|
||||
// Adjusting LINE_CONFIRM_THRESHOLD to current zoom so that when zoomed in
|
||||
// really close we make the threshold smaller, and vice versa.
|
||||
|
||||
return distance <= threshold; // LINE_CONFIRM_THRESHOLD / zoomValue;
|
||||
}
|
||||
return false;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue