From d4f70e9f31addc5f1f5afc39112aef6a18364c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Tolm=C3=A1cs?= Date: Mon, 5 May 2025 11:34:40 +0200 Subject: [PATCH] feat: Quarter snap points for diamonds (#9387) --- packages/element/src/binding.ts | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index ee5d037a8..d44123b71 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 distance = FIXED_BINDING_DISTANCE - 1; + const topLeft = pointFrom( + x + width / 4 - distance, + y + height / 4 - distance, + ); + const topRight = pointFrom( + x + (3 * width) / 4 + distance, + y + height / 4 - distance, + ); + const bottomLeft = pointFrom( + x + width / 4 - distance, + y + (3 * height) / 4 + distance, + ); + const bottomRight = pointFrom( + x + (3 * width) / 4 + distance, + y + (3 * height) / 4 + distance, + ); + if ( + pointDistance(topLeft, nonRotated) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(topLeft, center, angle); + } + if ( + pointDistance(topRight, nonRotated) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(topRight, center, angle); + } + if ( + pointDistance(bottomLeft, nonRotated) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(bottomLeft, center, angle); + } + if ( + pointDistance(bottomRight, nonRotated) < + Math.max(horizontalThrehsold, verticalThrehsold) + ) { + return pointRotateRads(bottomRight, center, angle); + } } return p;