From a45e1e32cf5f8dcf3aca60835e2905fac0a7dde9 Mon Sep 17 00:00:00 2001 From: Yan Heng Date: Thu, 27 Jul 2023 16:37:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E4=B8=89=E8=A7=92?= =?UTF-8?q?=E5=BD=A2=E5=92=8C=E7=9F=A9=E5=BD=A2=E7=BB=98=E5=88=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/tools/rect-tool.ts | 10 +++++++--- packages/core/src/tools/triangle-tool.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/core/src/tools/rect-tool.ts b/packages/core/src/tools/rect-tool.ts index c7b5540a..5275f9bb 100644 --- a/packages/core/src/tools/rect-tool.ts +++ b/packages/core/src/tools/rect-tool.ts @@ -30,9 +30,13 @@ class RectTool implements Tool { if (!this.rectangle) { return; } - const width = app.pointer.x - this.startPointer.x; - const height = app.pointer.y - this.startPointer.y; - this.rectangle.set({ width, height }); + + const width = Math.abs(app.pointer.x - this.startPointer.x); + const height = Math.abs(app.pointer.y - this.startPointer.y); + const left = Math.min(this.startPointer.x, app.pointer.x); + const top = Math.min(this.startPointer.y, app.pointer.y); + + this.rectangle.set({ left, top, width, height }); app.render(); } diff --git a/packages/core/src/tools/triangle-tool.ts b/packages/core/src/tools/triangle-tool.ts index dd6daaab..2965fa96 100644 --- a/packages/core/src/tools/triangle-tool.ts +++ b/packages/core/src/tools/triangle-tool.ts @@ -32,8 +32,12 @@ class TriangleTool implements Tool { } const width = Math.abs(app.pointer.x - this.startPointer.x); const height = Math.abs(app.pointer.y - this.startPointer.y); - this.triangle.set({ width, height }); - app.render(); // Call render after updating the triangle + + const left = Math.min(this.startPointer.x, app.pointer.x); + const top = Math.min(this.startPointer.y, app.pointer.y); + + this.triangle.set({ width, height, left, top }); + app.render(); } public onMouseUp({ app }: AppMouseEvent): void {