Skip to content

Commit 236c065

Browse files
psychedelicioushipsterusername
authored andcommitted
fix(ui): respect grid size when fitting layer to box
1 parent 1f5d744 commit 236c065

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityTransformer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export class CanvasEntityTransformer extends CanvasModuleBase {
432432
return;
433433
}
434434
const { rect } = this.manager.stateApi.getBbox();
435+
const gridSize = this.manager.stateApi.getGridSize();
435436
const width = this.konva.proxyRect.width();
436437
const height = this.konva.proxyRect.height();
437438
const scaleX = rect.width / width;
@@ -445,8 +446,8 @@ export class CanvasEntityTransformer extends CanvasModuleBase {
445446
const offsetY = (rect.height - height * scale) / 2;
446447

447448
this.konva.proxyRect.setAttrs({
448-
x: clamp(Math.round(rect.x + offsetX), rect.x, rect.x + rect.width),
449-
y: clamp(Math.round(rect.y + offsetY), rect.y, rect.y + rect.height),
449+
x: clamp(roundToMultiple(rect.x + offsetX, gridSize), rect.x, rect.x + rect.width),
450+
y: clamp(roundToMultiple(rect.y + offsetY, gridSize), rect.y, rect.y + rect.height),
450451
scaleX: scale,
451452
scaleY: scale,
452453
rotation: 0,
@@ -463,6 +464,7 @@ export class CanvasEntityTransformer extends CanvasModuleBase {
463464
return;
464465
}
465466
const { rect } = this.manager.stateApi.getBbox();
467+
const gridSize = this.manager.stateApi.getGridSize();
466468
const width = this.konva.proxyRect.width();
467469
const height = this.konva.proxyRect.height();
468470
const scaleX = rect.width / width;
@@ -476,8 +478,8 @@ export class CanvasEntityTransformer extends CanvasModuleBase {
476478
const offsetY = (rect.height - height * scale) / 2;
477479

478480
this.konva.proxyRect.setAttrs({
479-
x: Math.round(rect.x + offsetX),
480-
y: Math.round(rect.y + offsetY),
481+
x: roundToMultiple(rect.x + offsetX, gridSize),
482+
y: roundToMultiple(rect.y + offsetY, gridSize),
481483
scaleX: scale,
482484
scaleY: scale,
483485
rotation: 0,

0 commit comments

Comments
 (0)