mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
Fix aspect ratio lock when resizing with Shift key
Simplifies and corrects the logic for maintaining the original aspect ratio when resizing objects with the Shift key pressed. Ensures consistent behavior regardless of handle or direction.
This commit is contained in:
19
js/Canvas.js
19
js/Canvas.js
@@ -890,23 +890,12 @@ export class Canvas {
|
||||
|
||||
if (isShiftPressed) {
|
||||
const originalAspectRatio = o.width / o.height;
|
||||
if (handle.length === 2) {
|
||||
const newAspectRatio = Math.abs(newWidth / newHeight);
|
||||
|
||||
const potentialWidth = Math.abs(newWidth);
|
||||
const potentialHeight = Math.abs(newHeight);
|
||||
|
||||
if (potentialWidth / originalAspectRatio > potentialHeight) {
|
||||
newHeight = newWidth / originalAspectRatio;
|
||||
} else {
|
||||
newWidth = newHeight * originalAspectRatio;
|
||||
}
|
||||
if (Math.abs(newWidth) > Math.abs(newHeight) * originalAspectRatio) {
|
||||
newHeight = (Math.sign(newHeight) || 1) * Math.abs(newWidth) / originalAspectRatio;
|
||||
} else {
|
||||
|
||||
if (signX !== 0) {
|
||||
newHeight = newWidth / originalAspectRatio;
|
||||
} else {
|
||||
newWidth = newHeight * originalAspectRatio;
|
||||
}
|
||||
newWidth = (Math.sign(newWidth) || 1) * Math.abs(newHeight) * originalAspectRatio;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user