From 63a340f8cfe2ac9c93b2a3185822e9cb0bf26e39 Mon Sep 17 00:00:00 2001 From: Asturur Date: Mon, 24 Apr 2017 01:58:25 +0200 Subject: [PATCH 1/2] reduce angle calculation error --- src/canvas.class.js | 21 ++++++++++++--------- src/mixins/object_geometry.mixin.js | 4 ++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index a8179c4d5b7..14e821e5442 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -976,12 +976,7 @@ angle = radiansToDegrees(curAngle - lastAngle + t.theta), hasRoated = true; - // normalize angle to positive value - if (angle < 0) { - angle = 360 + angle; - } - angle %= 360; if (t.target.snapAngle > 0) { var snapAngle = t.target.snapAngle, @@ -995,13 +990,21 @@ else if (Math.abs(angle - rightAngleLocked) < snapThreshold) { angle = rightAngleLocked; } + } - if (t.target.angle === angle) { - hasRoated = false; - } + // normalize angle to positive value + if (angle < 0) { + angle = 360 + angle; + } + angle %= 360; + + if (t.target.angle === angle) { + hasRoated = false; + } + else { + t.target.angle = angle; } - t.target.angle = angle; return hasRoated; }, diff --git a/src/mixins/object_geometry.mixin.js b/src/mixins/object_geometry.mixin.js index 152d8d7b5d8..52ebd87d2aa 100644 --- a/src/mixins/object_geometry.mixin.js +++ b/src/mixins/object_geometry.mixin.js @@ -450,6 +450,10 @@ _calcRotateMatrix: function() { if (this.angle) { var theta = degreesToRadians(this.angle), cos = Math.cos(theta), sin = Math.sin(theta); + // trying to keep rounding error small, ugly but it works. + if (cos === 6.123233995736766e-17 || cos === -1.8369701987210297e-16) { + cos = 0; + } return [cos, sin, -sin, cos, 0, 0]; } return fabric.iMatrix.concat(); From 6a0e7dcd0feb033afd08f18b55fd4bbfc217b938 Mon Sep 17 00:00:00 2001 From: Asturur Date: Mon, 24 Apr 2017 02:08:23 +0200 Subject: [PATCH 2/2] reduce angle calculation error --- src/canvas.class.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index 14e821e5442..5adaa13f51f 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -976,8 +976,6 @@ angle = radiansToDegrees(curAngle - lastAngle + t.theta), hasRoated = true; - - if (t.target.snapAngle > 0) { var snapAngle = t.target.snapAngle, snapThreshold = t.target.snapThreshold || snapAngle,