From 7106605bbd38f9475cfcf4c1c040013862edf665 Mon Sep 17 00:00:00 2001 From: StickmanRed <100049599+StickmanRed@users.noreply.github.com> Date: Fri, 21 Aug 2026 14:39:28 -0700 Subject: [PATCH] Fix diagonal line snapping and angle --- engine/src/tools/Line.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/engine/src/tools/Line.js b/engine/src/tools/Line.js index df378f8c5..f9daacff7 100644 --- a/engine/src/tools/Line.js +++ b/engine/src/tools/Line.js @@ -160,15 +160,16 @@ Wick.Tools.Line = class extends Wick.Tool { const dy = Math.abs(this.startPoint.y - e.point.y); const dx = Math.abs(this.startPoint.x - e.point.x); - // diagnol - if (dy && dx && (dy / dx) > 0.5 && (dx / dy) > 0.5) { + // diagnol (tan(22.5) = 0.41421356237309503) + if (dy && dx && (dy / dx) > 0.41421356237309503 && (dx / dy) > 0.41421356237309503) { const diff = { x: this.endPoint.x - this.startPoint.x, y: this.endPoint.y - this.startPoint.y } + const length = (Math.abs(diff.y) + Math.abs(diff.x)) / 2 this.endPoint = { - x: this.startPoint.x + (dy + dx) / 2 * diff.x / Math.abs(diff.x), - y: this.startPoint.y + (dy + dx) / 2 * diff.y / Math.abs(diff.y) + x: this.startPoint.x + length * diff.x / Math.abs(diff.x), + y: this.startPoint.y + length * diff.y / Math.abs(diff.y) } } else if (dy > dx) // straight vertical this.endPoint.x = this.startPoint.x; @@ -298,4 +299,4 @@ Wick.Tools.Line = class extends Wick.Tool { } -}; \ No newline at end of file +};