From 1a543da5a018d1a99b51bfe5d7d90edff0502a11 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 31 Aug 2023 18:33:29 +0800 Subject: Fix a fatal bug in geometry. --- FrontEnd/src/utilities/geometry.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'FrontEnd/src/utilities/geometry.ts') diff --git a/FrontEnd/src/utilities/geometry.ts b/FrontEnd/src/utilities/geometry.ts index 12dd4bbb..60a8d3d4 100644 --- a/FrontEnd/src/utilities/geometry.ts +++ b/FrontEnd/src/utilities/geometry.ts @@ -49,7 +49,7 @@ export class Rect { } set right(value: number) { - this.width = this.left + value; + this.width = value - this.left; } get bottom(): number { @@ -57,7 +57,7 @@ export class Rect { } set bottom(value: number) { - this.height = this.top + value; + this.height = value - this.top; } get ratio(): number { @@ -218,15 +218,16 @@ export function adjustRectToContainer( : clamp(rect.top, container.top - rect.height, container.bottom); } else if (mode === "resize") { const noFlip = options?.resizeNoFlip; - rect.right = clamp( + const newRight = clamp( rect.right, - noFlip ? 0 : container.left, - container.right, + rect.width > 0 && noFlip ? rect.left : container.left, + rect.width < 0 && noFlip ? rect.left : container.right, ); + rect.right = newRight; rect.bottom = clamp( rect.bottom, - noFlip ? 0 : container.top, - container.bottom, + rect.height > 0 && noFlip ? rect.top : container.top, + rect.height < 0 && noFlip ? rect.top : container.bottom, ); } else { rect.left = clamp(rect.left, container.left, container.right); -- cgit v1.2.3