Fix handling of internally cached _angle in Point.

Closes #344.
This commit is contained in:
Jürg Lehni 2013-11-27 00:03:03 +01:00
parent ca3993fe8e
commit cbefaf0dd1

View file

@ -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();