Skip to content

Commit 3fd28ce

Browse files
Update scaling math to land on 100% consistently.
1 parent 32df3bd commit 3fd28ce

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasStageModule.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type CanvasStageModuleConfig = {
3131
const DEFAULT_CONFIG: CanvasStageModuleConfig = {
3232
MIN_SCALE: 0.1,
3333
MAX_SCALE: 20,
34-
SCALE_FACTOR: 0.999,
34+
SCALE_FACTOR: 0.9995,
3535
FIT_LAYERS_TO_STAGE_PADDING_PX: 48,
3636
};
3737

@@ -230,7 +230,24 @@ export class CanvasStageModule extends CanvasModuleBase {
230230
* Constrains a scale to be within the valid range
231231
*/
232232
constrainScale = (scale: number): number => {
233-
return clamp(Math.round(scale * 100) / 100, this.config.MIN_SCALE, this.config.MAX_SCALE);
233+
// Round to 2 decimal places to avoid floating point precision issues
234+
const rounded = Math.round(scale * 100) / 100;
235+
const clamped = clamp(rounded, this.config.MIN_SCALE, this.config.MAX_SCALE);
236+
237+
// Snap to 100% (scale = 1.0) with a more generous tolerance
238+
if (Math.abs(clamped - 1) < 0.05) {
239+
return 1;
240+
}
241+
242+
// Snap to other common zoom levels for better UX
243+
const commonScales = [0.25, 0.5, 0.75, 1.5, 2, 3, 4, 5];
244+
for (const commonScale of commonScales) {
245+
if (Math.abs(clamped - commonScale) < 0.03) {
246+
return commonScale;
247+
}
248+
}
249+
250+
return clamped;
234251
};
235252

236253
/**

0 commit comments

Comments
 (0)