From 5daf1a1b4e9bd09a9c258d83933d5f6c121c42e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Tolm=C3=A1cs?= Date: Mon, 12 Aug 2024 11:07:58 +0200 Subject: [PATCH] fix: Round coordinates and sizes for rectangle intersection (#8366) Round coordinates and sizes for rectangle intersection --- packages/excalidraw/element/binding.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/excalidraw/element/binding.ts b/packages/excalidraw/element/binding.ts index eb982470e..4bc6bf212 100644 --- a/packages/excalidraw/element/binding.ts +++ b/packages/excalidraw/element/binding.ts @@ -765,7 +765,18 @@ export const bindPointToSnapToElementOutline = ( return i; } - const d = distanceToBindableElement(bindableElement, i, elementsMap); + const d = distanceToBindableElement( + { + ...bindableElement, + x: Math.round(bindableElement.x), + y: Math.round(bindableElement.y), + width: Math.round(bindableElement.width), + height: Math.round(bindableElement.height), + }, + [Math.round(i[0]), Math.round(i[1])], + new Map(), + ); + return d >= bindableElement.height / 2 || d < FIXED_BINDING_DISTANCE ? ([point[0], -1 * i[1]] as Point) : ([point[0], i[1]] as Point); @@ -781,7 +792,18 @@ export const bindPointToSnapToElementOutline = ( return i; } - const d = distanceToBindableElement(bindableElement, i, elementsMap); + const d = distanceToBindableElement( + { + ...bindableElement, + x: Math.round(bindableElement.x), + y: Math.round(bindableElement.y), + width: Math.round(bindableElement.width), + height: Math.round(bindableElement.height), + }, + [Math.round(i[0]), Math.round(i[1])], + new Map(), + ); + return d >= bindableElement.width / 2 || d < FIXED_BINDING_DISTANCE ? ([-1 * i[0], point[1]] as Point) : ([i[0], point[1]] as Point);