From cbefaf0dd1709057c0a3ddde251cc537d0560d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 27 Nov 2013 00:03:03 +0100 Subject: [PATCH] Fix handling of internally cached _angle in Point. Closes #344. --- src/basic/Point.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/basic/Point.js b/src/basic/Point.js index c555a9d8..0a4bef8a 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -541,6 +541,10 @@ var Point = Base.extend(/** @lends Point# */{ }, setAngle: function(angle) { + // We store a reference to _angle internally so we still preserve it + // when the vector's length is set to zero, and then anything else. + // Note that we cannot rely on it if x and y are something else than 0, + // since updating x / y does not automatically change _angle! angle = this._angle = angle * Math.PI / 180; if (!this.isZero()) { var length = this.getLength(); @@ -573,9 +577,13 @@ var Point = Base.extend(/** @lends Point# */{ getAngleInRadians: function(/* point */) { // Hide parameters from Bootstrap so it injects bean too if (arguments[0] === undefined) { - if (this._angle == null) - this._angle = Math.atan2(this.y, this.x); - return this._angle; + return this.isZero() + // Return the preseved angle in case the vector has no + // length, and update the internal _angle in case the + // vector has a length. See #setAngle() for more + // explanations. + ? this._angle || 0 + : this._angle = Math.atan2(this.y, this.x); } else { var point = Point.read(arguments), div = this.getLength() * point.getLength();