From 8d8f93fd00a1c69173e7f597ffd5d64d752eb639 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:41:07 +1100 Subject: [PATCH] Fixes bug where bounding box could escape bounds of canvas --- .../components/InpaintingBoundingBoxPreview.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frontend/src/features/tabs/Inpainting/components/InpaintingBoundingBoxPreview.tsx b/frontend/src/features/tabs/Inpainting/components/InpaintingBoundingBoxPreview.tsx index e585a810f5..2281e41cd8 100644 --- a/frontend/src/features/tabs/Inpainting/components/InpaintingBoundingBoxPreview.tsx +++ b/frontend/src/features/tabs/Inpainting/components/InpaintingBoundingBoxPreview.tsx @@ -173,6 +173,8 @@ const InpaintingBoundingBoxPreview = () => { transformerRef.current.getLayer()?.batchDraw(); }, []); + const scaledStep = 64 * stageScale; + return ( <> { * not its width and height. We need to un-scale the width and height before * setting the values. */ - console.log(isMovingBoundingBox) if (!shapeRef.current) return; const rect = shapeRef.current; @@ -263,9 +264,6 @@ const InpaintingBoundingBoxPreview = () => { * stage is scaled, our actual desired step is actually 64 * the stage scale. */ - // Get the scaled step - const scaledStep = 64 * stageScale; - // Difference of the old coords from the nearest multiple the scaled step const offsetX = oldPos.x % scaledStep; const offsetY = oldPos.y % scaledStep; @@ -311,12 +309,13 @@ const InpaintingBoundingBoxPreview = () => { * Unlike anchorDragBoundFunc, it does get a width and height, so * the logic to constrain the size of the bounding box is very simple. */ - if (!imageToInpaint) return oldBoundBox; if ( - newBoundBox.width + newBoundBox.x > imageToInpaint.width || - newBoundBox.height + newBoundBox.y > imageToInpaint.height || + newBoundBox.width + newBoundBox.x > + imageToInpaint.width * stageScale || + newBoundBox.height + newBoundBox.y > + imageToInpaint.height * stageScale || newBoundBox.x < 0 || newBoundBox.y < 0 ) {