mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Fixes bug where bounding box could escape bounds of canvas
This commit is contained in:
parent
20a3875f32
commit
8d8f93fd00
@ -173,6 +173,8 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
transformerRef.current.getLayer()?.batchDraw();
|
transformerRef.current.getLayer()?.batchDraw();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const scaledStep = 64 * stageScale;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Rect
|
<Rect
|
||||||
@ -199,7 +201,6 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
* not its width and height. We need to un-scale the width and height before
|
* not its width and height. We need to un-scale the width and height before
|
||||||
* setting the values.
|
* setting the values.
|
||||||
*/
|
*/
|
||||||
console.log(isMovingBoundingBox)
|
|
||||||
if (!shapeRef.current) return;
|
if (!shapeRef.current) return;
|
||||||
|
|
||||||
const rect = shapeRef.current;
|
const rect = shapeRef.current;
|
||||||
@ -263,9 +264,6 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
* stage is scaled, our actual desired step is actually 64 * the stage scale.
|
* 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
|
// Difference of the old coords from the nearest multiple the scaled step
|
||||||
const offsetX = oldPos.x % scaledStep;
|
const offsetX = oldPos.x % scaledStep;
|
||||||
const offsetY = oldPos.y % scaledStep;
|
const offsetY = oldPos.y % scaledStep;
|
||||||
@ -311,12 +309,13 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
* Unlike anchorDragBoundFunc, it does get a width and height, so
|
* Unlike anchorDragBoundFunc, it does get a width and height, so
|
||||||
* the logic to constrain the size of the bounding box is very simple.
|
* the logic to constrain the size of the bounding box is very simple.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!imageToInpaint) return oldBoundBox;
|
if (!imageToInpaint) return oldBoundBox;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
newBoundBox.width + newBoundBox.x > imageToInpaint.width ||
|
newBoundBox.width + newBoundBox.x >
|
||||||
newBoundBox.height + newBoundBox.y > imageToInpaint.height ||
|
imageToInpaint.width * stageScale ||
|
||||||
|
newBoundBox.height + newBoundBox.y >
|
||||||
|
imageToInpaint.height * stageScale ||
|
||||||
newBoundBox.x < 0 ||
|
newBoundBox.x < 0 ||
|
||||||
newBoundBox.y < 0
|
newBoundBox.y < 0
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user