diff --git a/src/basic/Point.js b/src/basic/Point.js index a2494c46..5fea58d6 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -149,33 +149,18 @@ var Point = this.Point = Base.extend({ }, setLength: function(length) { + // Whenever setting x/y, use #set() instead of direct assignment, + // so LinkedPoint does not report changes twice. if (this.isZero()) { - if (this._angle != null) { - var a = this._angle; - // Use #set() instead of direct assignment, so LinkedPoint - // can optimise - this.set( - Math.cos(a) * length, - Math.sin(a) * length - ); - } else { - // Assume angle = 0 - this.x = length; - // y is already 0 - } + var angle = this._angle || 0; + this.set(Math.cos(angle) * length, Math.sin(angle) * length); } else { var scale = length / this.getLength(); - if (scale == 0) { - // Calculate angle now, so it will be preserved even when - // x and y are 0 + // Force calculation of angle now, so it will be preserved even when + // x and y are 0 + if (scale == 0) this.getAngle(); - } - // Use #set() instead of direct assignment, so LinkedPoint - // can optimise - this.set( - this.x * scale, - this.y * scale - ); + this.set(this.x * scale, this.y * scale); } return this; },