new Point methods

This commit is contained in:
mourner 2010-09-17 19:04:41 +03:00
parent 64a40b3880
commit a2d2fed2db
2 changed files with 16 additions and 0 deletions

View File

@ -40,4 +40,6 @@ describe("Point", function() {
expect(new L.Point(50, 30).multiplyBy(2)).toEqual(new L.Point(100, 60));
});
});
describe('#distanceTo', noSpecs);
});

View File

@ -22,5 +22,19 @@ L.Point.prototype = {
multiplyBy: function(num) {
return new L.Point(this.x * num, this.y * num);
},
distanceTo: function(point) {
var x = point.x - this.x,
y = point.y - this.y;
return Math.sqrt(x*x + y*y);
},
round: function() {
return new L.Point(Math.round(this.x), Math.round(this.y));
},
toString: function() {
return 'Point(' + this.x + ',' + this.y + ')';
}
};