From 95a2b03686f1957bf6d53a2f048094d307f9537a Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Wed, 23 Apr 2025 16:07:50 +0200 Subject: [PATCH] Corner snapping for diamonds no longer has dead zones Signed-off-by: Mark Tolmacs --- packages/element/src/binding.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index 3664744d31..bb6d1bc86f 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -1104,9 +1104,11 @@ export const snapToMid = ( const horizontalThrehsold = clamp(tolerance * width, 5, 80); if ( - nonRotated[0] <= x + width / 2 && - nonRotated[1] > center[1] - verticalThrehsold && - nonRotated[1] < center[1] + verticalThrehsold + element.type === "diamond" + ? nonRotated[0] <= x + width * (element.roundness ? 0.035 : 1) + : nonRotated[0] <= x + width / 2 && + nonRotated[1] > center[1] - verticalThrehsold && + nonRotated[1] < center[1] + verticalThrehsold ) { // LEFT return pointRotateRads( @@ -1115,9 +1117,11 @@ export const snapToMid = ( angle, ); } else if ( - nonRotated[1] <= y + height / 2 && - nonRotated[0] > center[0] - horizontalThrehsold && - nonRotated[0] < center[0] + horizontalThrehsold + element.type === "diamond" + ? nonRotated[1] <= y + height * (element.roundness ? 0.035 : 1) + : nonRotated[1] <= y + height / 2 && + nonRotated[0] > center[0] - horizontalThrehsold && + nonRotated[0] < center[0] + horizontalThrehsold ) { // TOP return pointRotateRads( @@ -1126,9 +1130,11 @@ export const snapToMid = ( angle, ); } else if ( - nonRotated[0] >= x + width / 2 && - nonRotated[1] > center[1] - verticalThrehsold && - nonRotated[1] < center[1] + verticalThrehsold + element.type === "diamond" + ? nonRotated[0] >= x + width * (element.roundness ? 0.035 : 1) + : nonRotated[0] >= x + width / 2 && + nonRotated[1] > center[1] - verticalThrehsold && + nonRotated[1] < center[1] + verticalThrehsold ) { // RIGHT return pointRotateRads( @@ -1137,9 +1143,11 @@ export const snapToMid = ( angle, ); } else if ( - nonRotated[1] >= y + height / 2 && - nonRotated[0] > center[0] - horizontalThrehsold && - nonRotated[0] < center[0] + horizontalThrehsold + element.type === "diamond" + ? nonRotated[1] >= y - height * (element.roundness ? 0.035 : 1) + : nonRotated[1] >= y + height / 2 && + nonRotated[0] > center[0] - horizontalThrehsold && + nonRotated[0] < center[0] + horizontalThrehsold ) { // DOWN return pointRotateRads(