diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index 88100cc8b2..d63b1c043a 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -44,6 +44,7 @@ import { intersectElementWithLineSegment } from "./collision"; import { distanceToBindableElement } from "./distance"; import { headingForPointFromElement, + headingIsHorizontal, vectorToHeading, type Heading, } from "./heading"; @@ -922,16 +923,23 @@ export const bindPointToSnapToElementOutline = ( let intersection: GlobalPoint | null = null; if (elbowed) { + const isHorizontal = headingIsHorizontal( + headingForPointFromElement(bindableElement, aabb, globalP), + ); + const otherPoint = pointFrom( + isHorizontal ? center[0] : edgePoint[0], + !isHorizontal ? center[1] : edgePoint[1], + ); intersection = intersectElementWithLineSegment( bindableElement, lineSegment( - center, + otherPoint, pointFromVector( vectorScale( - vectorNormalize(vectorFromPoint(edgePoint, center)), + vectorNormalize(vectorFromPoint(edgePoint, otherPoint)), Math.max(bindableElement.width, bindableElement.height) * 2, ), - center, + otherPoint, ), ), )[0];