add Point contains method
This commit is contained in:
parent
f0a75c9d08
commit
9c2e7cfbd4
@ -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)');
|
||||
|
@ -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) + ', ' +
|
||||
|
Loading…
Reference in New Issue
Block a user