mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
More precise binding distance for elbow arrows
This commit is contained in:
parent
192c4e7658
commit
7f23f37a01
1 changed files with 23 additions and 32 deletions
|
@ -27,7 +27,7 @@ import {
|
||||||
PRECISION,
|
PRECISION,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import { isPointOnShape } from "@excalidraw/utils/collision";
|
import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision";
|
||||||
|
|
||||||
import type { LocalPoint, Radians } from "@excalidraw/math";
|
import type { LocalPoint, Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ import {
|
||||||
isTextElement,
|
isTextElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
import { aabbForElement, getElementShape, pointInsideBounds } from "./shapes";
|
import { aabbForElement, getElementShape } from "./shapes";
|
||||||
import { updateElbowArrowPoints } from "./elbowArrow";
|
import { updateElbowArrowPoints } from "./elbowArrow";
|
||||||
|
|
||||||
import type Scene from "./Scene";
|
import type Scene from "./Scene";
|
||||||
|
@ -230,7 +230,13 @@ const getOriginalBindingIfStillCloseOfLinearElementEdge = (
|
||||||
const element = elementsMap.get(elementId);
|
const element = elementsMap.get(elementId);
|
||||||
if (
|
if (
|
||||||
isBindableElement(element) &&
|
isBindableElement(element) &&
|
||||||
bindingBorderTest(element, coors, elementsMap, zoom)
|
bindingBorderTest(
|
||||||
|
element,
|
||||||
|
coors,
|
||||||
|
elementsMap,
|
||||||
|
zoom,
|
||||||
|
isElbowArrow(element),
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
@ -567,19 +573,7 @@ export const getHoveredElementForBinding = (
|
||||||
elements,
|
elements,
|
||||||
(element) =>
|
(element) =>
|
||||||
isBindableElement(element, false) &&
|
isBindableElement(element, false) &&
|
||||||
bindingBorderTest(
|
bindingBorderTest(element, pointerCoords, elementsMap, zoom, fullShape),
|
||||||
element,
|
|
||||||
pointerCoords,
|
|
||||||
elementsMap,
|
|
||||||
zoom,
|
|
||||||
(fullShape ||
|
|
||||||
!isBindingFallthroughEnabled(
|
|
||||||
element as ExcalidrawBindableElement,
|
|
||||||
)) &&
|
|
||||||
// disable fullshape snapping for frame elements so we
|
|
||||||
// can bind to frame children
|
|
||||||
!isFrameLikeElement(element),
|
|
||||||
),
|
|
||||||
).filter((element) => {
|
).filter((element) => {
|
||||||
if (cullRest) {
|
if (cullRest) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -621,16 +615,7 @@ export const getHoveredElementForBinding = (
|
||||||
elements,
|
elements,
|
||||||
(element) =>
|
(element) =>
|
||||||
isBindableElement(element, false) &&
|
isBindableElement(element, false) &&
|
||||||
bindingBorderTest(
|
bindingBorderTest(element, pointerCoords, elementsMap, zoom, fullShape),
|
||||||
element,
|
|
||||||
pointerCoords,
|
|
||||||
elementsMap,
|
|
||||||
zoom,
|
|
||||||
// disable fullshape snapping for frame elements so we
|
|
||||||
// can bind to frame children
|
|
||||||
(fullShape || !isBindingFallthroughEnabled(element)) &&
|
|
||||||
!isFrameLikeElement(element),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return hoveredElement as NonDeleted<ExcalidrawBindableElement> | null;
|
return hoveredElement as NonDeleted<ExcalidrawBindableElement> | null;
|
||||||
|
@ -1512,13 +1497,19 @@ export const bindingBorderTest = (
|
||||||
fullShape?: boolean,
|
fullShape?: boolean,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const threshold = maxBindingGap(element, element.width, element.height, zoom);
|
const threshold = maxBindingGap(element, element.width, element.height, zoom);
|
||||||
|
|
||||||
const shape = getElementShape(element, elementsMap);
|
const shape = getElementShape(element, elementsMap);
|
||||||
return (
|
const shouldTestInside =
|
||||||
isPointOnShape(pointFrom(x, y), shape, threshold) ||
|
// disable fullshape snapping for frame elements so we
|
||||||
(fullShape === true &&
|
// can bind to frame children
|
||||||
pointInsideBounds(pointFrom(x, y), aabbForElement(element)))
|
(fullShape || !isBindingFallthroughEnabled(element)) &&
|
||||||
);
|
!isFrameLikeElement(element);
|
||||||
|
|
||||||
|
return shouldTestInside
|
||||||
|
? // Since `inShape` tests STRICTLY againt the insides of a shape
|
||||||
|
// we would need `onShape` as well to include the "borders"
|
||||||
|
isPointInShape(pointFrom(x, y), shape) ||
|
||||||
|
isPointOnShape(pointFrom(x, y), shape, threshold)
|
||||||
|
: isPointOnShape(pointFrom(x, y), shape, threshold);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const maxBindingGap = (
|
export const maxBindingGap = (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue