Point fixes

This commit is contained in:
mourner 2010-09-13 14:58:03 +03:00
parent fafe763826
commit 59a1736b3e
2 changed files with 20 additions and 6 deletions

View File

@ -15,9 +15,23 @@ describe("Point", function() {
}); });
}); });
describe('#subtract', noSpecs); describe('#subtract', function() {
it('should subtract the given point from this one', function() {
var a = new L.Point(50, 30),
b = new L.Point(20, 10);
expect(a.subtract(b)).toEqual(new L.Point(30, 20));
});
});
describe('#add', noSpecs); describe('#add', function() {
it('should add the given point to this one', function() {
expect(new L.Point(50, 30).add(new L.Point(20, 10))).toEqual(new L.Point(70, 40));
});
});
describe('#divideBy', noSpecs); describe('#divideBy', function() {
it('should divide this point by the given amount', function() {
expect(new L.Point(50, 30).divideBy(5)).toEqual(new L.Point(10, 6));
});
});
}); });

View File

@ -9,14 +9,14 @@ L.Point = function(/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
L.Point.prototype = { L.Point.prototype = {
add: function(point) { add: function(point) {
return L.Point(this.x + point.x, this.y + point.y); return new L.Point(this.x + point.x, this.y + point.y);
}, },
subtract: function(point) { subtract: function(point) {
return L.Point(this.x - point.x, this.y - point.y); return new L.Point(this.x - point.x, this.y - point.y);
}, },
divideBy: function(num, round) { divideBy: function(num, round) {
return L.Point(this.x/2, this.y/2, round); return new L.Point(this.x/num, this.y/num, round);
} }
}; };