add Point contains method

This commit is contained in:
Vladimir Agafonkin 2013-02-22 17:28:55 +02:00
parent f0a75c9d08
commit 9c2e7cfbd4
2 changed files with 18 additions and 0 deletions

View File

@ -66,6 +66,19 @@ describe("Point", function() {
});
});
describe('#contains', function () {
it('returns true if the point is bigger in absolute dimensions than the passed one', function () {
var p1 = new L.Point(50, 30),
p2 = new L.Point(-40, 20),
p3 = new L.Point(60, -20),
p4 = new L.Point(-40, -40);
expect(p1.contains(p2)).toBe(true);
expect(p1.contains(p3)).toBe(false);
expect(p1.contains(p4)).toBe(false);
});
});
describe('#toString', function () {
it('formats a string out of point coordinates', function () {
expect(new L.Point(50, 30) + '').toEqual('Point(50, 30)');

View File

@ -89,6 +89,11 @@ L.Point.prototype = {
point.y === this.y;
},
contains: function (point) {
return Math.abs(point.x) <= Math.abs(this.x) &&
Math.abs(point.y) <= Math.abs(this.y);
},
toString: function () {
return 'Point(' +
L.Util.formatNum(this.x) + ', ' +