Improve Point#normalize().

This commit is contained in:
Jürg Lehni 2011-05-01 23:32:37 +01:00
parent 2cdb15f2d6
commit 77c19601ff

View file

@ -166,14 +166,14 @@ var Point = this.Point = Base.extend({
}, },
normalize: function(length) { normalize: function(length) {
if (length === null) if (length === undefined)
length = 1; length = 1;
var len = this.getLength(); var current = this.getLength(),
var scale = len != 0 ? length / len : 0; scale = current != 0 ? length / current : 0,
var res = Point.create(this.x * scale, this.y * scale); point = Point.create(this.x * scale, this.y * scale);
// Preserve angle. // Preserve angle.
res._angle = this._angle; point._angle = this._angle;
return res; return point;
}, },
getQuadrant: function() { getQuadrant: function() {