From f3e709460f5e6850e57782e1f022f11aa6ff0c67 Mon Sep 17 00:00:00 2001 From: acer Date: Fri, 4 Dec 2020 22:28:29 -0500 Subject: [PATCH] Rectangle sizing --- src/js/tools/rectangle.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/js/tools/rectangle.js b/src/js/tools/rectangle.js index 5ca5478..748f5e0 100644 --- a/src/js/tools/rectangle.js +++ b/src/js/tools/rectangle.js @@ -72,8 +72,8 @@ class Rectangle_class extends Base_tools_class { params: this.clone(this.getParams()), status: 'draft', render_function: [this.name, 'render'], - x: mouse.x, - y: mouse.y, + x: Math.round(mouse.x), + y: Math.round(mouse.y), is_vector: true, }; this.Base_layers.insert(this.layer); @@ -89,8 +89,8 @@ class Rectangle_class extends Base_tools_class { return; } - var width = mouse.x - this.layer.x; - var height = mouse.y - this.layer.y; + var width = Math.round(mouse.x) - this.layer.x; + var height = Math.round(mouse.y) - this.layer.y; if (params.square == true) { if (Math.abs(width) < Math.abs(height)) { @@ -122,8 +122,8 @@ class Rectangle_class extends Base_tools_class { return; } - var width = mouse.x - this.layer.x; - var height = mouse.y - this.layer.y; + var width = Math.round(mouse.x) - this.layer.x; + var height = Math.round(mouse.y) - this.layer.y; if (params.square == true) { if (Math.abs(width) < Math.abs(height)) { @@ -245,11 +245,13 @@ class Rectangle_class extends Base_tools_class { radius = Math.min(radius, width / 2, height / 2); radius = Math.floor(radius); - //make it nicer - x = x + 0.5; - y = y + 0.5; - width--; - height--; + // Odd dimensions must draw offset half a pixel + if (width % 2 == 1) { + x -= 0.5; + } + if (height % 2 == 1) { + y -= 0.5; + } radius = {tl: radius, tr: radius, br: radius, bl: radius};