mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Fixes bounding box being able to escape canvas
This commit is contained in:
@ -111,7 +111,12 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
|
|
||||||
const handleOnDragMove = useCallback(
|
const handleOnDragMove = useCallback(
|
||||||
(e: KonvaEventObject<DragEvent>) => {
|
(e: KonvaEventObject<DragEvent>) => {
|
||||||
dispatch(setBoundingBoxCoordinate({ x: Math.floor(e.target.x()), y: Math.floor(e.target.y()) }));
|
dispatch(
|
||||||
|
setBoundingBoxCoordinate({
|
||||||
|
x: Math.floor(e.target.x()),
|
||||||
|
y: Math.floor(e.target.y()),
|
||||||
|
})
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
@ -125,12 +130,12 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
const maxX = imageToInpaint.width - boundingBoxDimensions.width;
|
const maxX = imageToInpaint.width - boundingBoxDimensions.width;
|
||||||
const maxY = imageToInpaint.height - boundingBoxDimensions.height;
|
const maxY = imageToInpaint.height - boundingBoxDimensions.height;
|
||||||
|
|
||||||
const clampedX = _.clamp(x, 0, maxX);
|
const clampedX = Math.floor(_.clamp(x, 0, maxX * stageScale));
|
||||||
const clampedY = _.clamp(y, 0, maxY);
|
const clampedY = Math.floor(_.clamp(y, 0, maxY * stageScale));
|
||||||
|
|
||||||
return { x: clampedX, y: clampedY };
|
return { x: clampedX, y: clampedY };
|
||||||
},
|
},
|
||||||
[boundingBoxCoordinate, boundingBoxDimensions, imageToInpaint]
|
[boundingBoxCoordinate, boundingBoxDimensions, imageToInpaint, stageScale]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOnTransform = useCallback(() => {
|
const handleOnTransform = useCallback(() => {
|
||||||
@ -242,7 +247,7 @@ const InpaintingBoundingBoxPreview = () => {
|
|||||||
if (
|
if (
|
||||||
newBoundBox.width + newBoundBox.x > imageToInpaint.width * stageScale ||
|
newBoundBox.width + newBoundBox.x > imageToInpaint.width * stageScale ||
|
||||||
newBoundBox.height + newBoundBox.y >
|
newBoundBox.height + newBoundBox.y >
|
||||||
imageToInpaint.height * stageScale ||
|
imageToInpaint.height * stageScale ||
|
||||||
newBoundBox.x < 0 ||
|
newBoundBox.x < 0 ||
|
||||||
newBoundBox.y < 0
|
newBoundBox.y < 0
|
||||||
) {
|
) {
|
||||||
|
Reference in New Issue
Block a user