chore: Refactor binding gap calc

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-05-10 12:12:06 +00:00
parent 60f29dc188
commit 73c940bcf6
10 changed files with 255 additions and 300 deletions
+7 -12
View File
@@ -111,18 +111,13 @@ export type BindingStrategy =
* IMPORTANT: currently must be > 0 (this also applies to the computed gap)
*/
export const BASE_BINDING_GAP = 5;
export const BASE_BINDING_GAP_ELBOW = 5;
export const BASE_ARROW_MIN_LENGTH = 10;
export const FOCUS_POINT_SIZE = 10 / 1.5;
export const getBindingGap = (
bindTarget: ExcalidrawBindableElement,
opts: Pick<ExcalidrawArrowElement, "elbowed">,
): number => {
return (
(opts.elbowed ? BASE_BINDING_GAP_ELBOW : BASE_BINDING_GAP) +
bindTarget.strokeWidth / 2
);
return BASE_BINDING_GAP + bindTarget.strokeWidth / 2;
};
export const maxBindingDistance_simple = (zoom?: AppState["zoom"]): number => {
@@ -1416,7 +1411,7 @@ export const bindPointToSnapToElementOutline = (
startOrEnd === "start" ? 1 : -2,
elementsMap,
);
const bindingGap = getBindingGap(bindableElement, arrowElement);
const bindingGap = getBindingGap(bindableElement);
const aabb = aabbForElement(bindableElement, elementsMap);
const bindableCenter = getCenterForBounds(aabb);
@@ -1477,7 +1472,7 @@ export const bindPointToSnapToElementOutline = (
bindableElement,
elementsMap,
anotherIntersector,
BASE_BINDING_GAP_ELBOW,
BASE_BINDING_GAP,
).sort(pointDistanceSq)[0];
}
} else {
@@ -1536,7 +1531,7 @@ export const avoidRectangularCorner = (
-bindTarget.angle as Radians,
);
const bindingGap = getBindingGap(bindTarget, arrowElement);
const bindingGap = getBindingGap(bindTarget);
if (nonRotatedPoint[0] < bindTarget.x && nonRotatedPoint[1] < bindTarget.y) {
// Top left
@@ -1714,7 +1709,7 @@ export const updateBoundPoint = (
otherBindable,
elementsMap,
intersector,
getBindingGap(otherBindable, arrow),
getBindingGap(otherBindable),
).sort(
(a, b) => pointDistanceSq(a, focusPoint) - pointDistanceSq(b, focusPoint),
)[0];
@@ -1724,7 +1719,7 @@ export const updateBoundPoint = (
bindableElement,
elementsMap,
intersector,
getBindingGap(bindableElement, arrow),
getBindingGap(bindableElement),
).sort(
(a, b) =>
pointDistanceSq(a, otherFocusPointOrArrowPoint) -
@@ -1752,7 +1747,7 @@ export const updateBoundPoint = (
element: otherBindable,
point: outlinePoint,
elementsMap,
threshold: getBindingGap(otherBindable, arrow),
threshold: getBindingGap(otherBindable),
overrideShouldTestInside: true,
})
) {