mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: adjust line-confirm-threshold based on zoom (#2884)
Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
parent
ba9b65b051
commit
e6cd97c4f2
5 changed files with 18 additions and 12 deletions
15
src/math.ts
15
src/math.ts
|
@ -1,4 +1,4 @@
|
|||
import { Point } from "./types";
|
||||
import { NormalizedZoomValue, Point, Zoom } from "./types";
|
||||
import { LINE_CONFIRM_THRESHOLD } from "./constants";
|
||||
import { ExcalidrawLinearElement } from "./element/types";
|
||||
|
||||
|
@ -147,13 +147,16 @@ export const centerPoint = (a: Point, b: Point): Point => {
|
|||
// to be considered a loop
|
||||
export const isPathALoop = (
|
||||
points: ExcalidrawLinearElement["points"],
|
||||
/** supply if you want the loop detection to account for current zoom */
|
||||
zoomValue: Zoom["value"] = 1 as NormalizedZoomValue,
|
||||
): boolean => {
|
||||
if (points.length >= 3) {
|
||||
const [firstPoint, lastPoint] = [points[0], points[points.length - 1]];
|
||||
return (
|
||||
distance2d(firstPoint[0], firstPoint[1], lastPoint[0], lastPoint[1]) <=
|
||||
LINE_CONFIRM_THRESHOLD
|
||||
);
|
||||
const [first, last] = [points[0], points[points.length - 1]];
|
||||
const distance = distance2d(first[0], first[1], last[0], last[1]);
|
||||
|
||||
// Adjusting LINE_CONFIRM_THRESHOLD to current zoom so that when zoomed in
|
||||
// really close we make the threshold smaller, and vice versa.
|
||||
return distance <= LINE_CONFIRM_THRESHOLD / zoomValue;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue