Point add/subtract/divideBy

This commit is contained in:
mourner 2010-09-10 16:54:03 +03:00
parent a9677fca55
commit a8d55d0d47
2 changed files with 20 additions and 0 deletions

View File

@ -14,4 +14,10 @@ describe("Point", function() {
expect(p.y).toEqual(3);
});
});
describe('#subtract', noSpecs);
describe('#add', noSpecs);
describe('#divideBy', noSpecs);
});

View File

@ -6,3 +6,17 @@ L.Point = function(/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
this.x = (round ? Math.round(x) : x);
this.y = (round ? Math.round(y) : y);
};
L.Point.prototype = {
add: function(point) {
return L.Point(this.x + point.x, this.y + point.y);
},
subtract: function(point) {
return L.Point(this.x - point.x, this.y - point.y);
},
divideBy: function(num, round) {
return L.Point(this.x/2, this.y/2, round);
}
};