From aeadafd7b1624990905a2a325b79e24d381530e0 Mon Sep 17 00:00:00 2001 From: viliusle Date: Tue, 1 Dec 2020 14:58:32 +0200 Subject: [PATCH] line improvements, better accuracy, ability to draw multiline without gaps --- src/js/tools/line.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/js/tools/line.js b/src/js/tools/line.js index 85498ce..d40f7c1 100644 --- a/src/js/tools/line.js +++ b/src/js/tools/line.js @@ -93,9 +93,9 @@ class Line_class extends Base_tools_class { if (e.ctrlKey == true || e.metaKey) { //one direction only if (Math.abs(width) < Math.abs(height)) - width = 1; + width = 0; else - height = 1; + height = 0; } //more data @@ -123,9 +123,9 @@ class Line_class extends Base_tools_class { if (e.ctrlKey == true || e.metaKey) { //one direction only if (Math.abs(width) < Math.abs(height)) - width = 1; + width = 0; else - height = 1; + height = 0; } //more data @@ -148,14 +148,14 @@ class Line_class extends Base_tools_class { ctx.lineWidth = params.size; ctx.lineCap = 'round'; - var width = layer.x + layer.width - 1; - var height = layer.y + layer.height - 1; + var width = layer.x + layer.width; + var height = layer.y + layer.height; if (type == 'Simple') { //draw line ctx.beginPath(); - ctx.moveTo(layer.x + 0.5, layer.y + 0.5); - ctx.lineTo(width + 0.5, height + 0.5); + ctx.moveTo(layer.x, layer.y); + ctx.lineTo(width, height); ctx.stroke(); } else if (type == 'Arrow') { @@ -163,8 +163,8 @@ class Line_class extends Base_tools_class { if (headlen < 15) headlen = 15; this.arrow(ctx, - layer.x + 0.5, layer.y + 0.5, - width + 0.5, height + 0.5, + layer.x, layer.y, + width, height, headlen); } else if (type == 'Curve') {