Point fixes
This commit is contained in:
parent
fafe763826
commit
59a1736b3e
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
@ -9,14 +9,14 @@ L.Point = function(/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
|
||||
|
||||
L.Point.prototype = {
|
||||
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) {
|
||||
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) {
|
||||
return L.Point(this.x/2, this.y/2, round);
|
||||
return new L.Point(this.x/num, this.y/num, round);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user