Skip to content

Commit

Permalink
feat: 修复三角形和矩形绘制逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Heng committed Jul 27, 2023
1 parent 549037d commit a45e1e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/tools/rect-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/tools/triangle-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a45e1e3

Please sign in to comment.