diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index ee5d037a8c..2236746c82 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -1171,6 +1171,48 @@ export const snapToMid = ( center, angle, ); + } else if (element.type === "diamond") { + const sqrtFixedDistance = Math.sqrt(FIXED_BINDING_DISTANCE); + const topLeft = pointFrom( + x + width / 4 - sqrtFixedDistance, + y + height / 4 - sqrtFixedDistance, + ); + const topRight = pointFrom( + x + (3 * width) / 4 + sqrtFixedDistance, + y + height / 4 - sqrtFixedDistance, + ); + const bottomLeft = pointFrom( + x + width / 4 - sqrtFixedDistance, + y + (3 * height) / 4 + sqrtFixedDistance, + ); + const bottomRight = pointFrom( + x + (3 * width) / 4 + sqrtFixedDistance, + y + (3 * height) / 4 + sqrtFixedDistance, + ); + if ( + pointDistance(topLeft, p) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(topLeft, center, angle); + } + if ( + pointDistance(topRight, p) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(topRight, center, angle); + } + if ( + pointDistance(bottomLeft, p) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(bottomLeft, center, angle); + } + if ( + pointDistance(bottomRight, p) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(bottomRight, center, angle); + } } return p;