Implemented isValid() function for Bounds and LatLngBounds. Fixes issue #966. Added specification.
This commit is contained in:
parent
c18dd9b38f
commit
f8d6e7052e
@ -1 +1,23 @@
|
|||||||
describe('LatLngBounds', noSpecs);
|
describe('LatLngBounds', function() {
|
||||||
|
var a, c;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
a = new L.Bounds(
|
||||||
|
new L.Point(14, 12),
|
||||||
|
new L.Point(30, 40));
|
||||||
|
c = new L.Bounds();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#isValid', function() {
|
||||||
|
it('should return true if properly set up', function() {
|
||||||
|
expect(a.isValid()).toBeTruthy();
|
||||||
|
});
|
||||||
|
it('should return false if is invalid', function() {
|
||||||
|
expect(c.isValid()).toBeFalsy();
|
||||||
|
});
|
||||||
|
it('should be valid if extended', function() {
|
||||||
|
c.extend([0, 0]);
|
||||||
|
expect(c.isValid()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,15 +1,16 @@
|
|||||||
describe('Bounds', function() {
|
describe('Bounds', function() {
|
||||||
var a, b;
|
var a, b, c;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
a = new L.Bounds(
|
a = new L.Bounds(
|
||||||
new L.Point(14, 12),
|
new L.Point(14, 12),
|
||||||
new L.Point(30, 40));
|
new L.Point(30, 40));
|
||||||
b = new L.Bounds([
|
b = new L.Bounds([
|
||||||
new L.Point(20, 12),
|
new L.Point(20, 12),
|
||||||
new L.Point(14, 20),
|
new L.Point(14, 20),
|
||||||
new L.Point(30, 40)
|
new L.Point(30, 40)
|
||||||
]);
|
]);
|
||||||
|
c = new L.Bounds();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
@ -42,12 +43,25 @@ describe('Bounds', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#contains', function() {
|
describe('#contains', function() {
|
||||||
it('should contains other bounds or point', function() {
|
it('should contains other bounds or point', function() {
|
||||||
a.extend(new L.Point(50, 10));
|
a.extend(new L.Point(50, 10));
|
||||||
expect(a.contains(b)).toBeTruthy();
|
expect(a.contains(b)).toBeTruthy();
|
||||||
expect(b.contains(a)).toBeFalsy();
|
expect(b.contains(a)).toBeFalsy();
|
||||||
expect(a.contains(new L.Point(24, 25))).toBeTruthy();
|
expect(a.contains(new L.Point(24, 25))).toBeTruthy();
|
||||||
expect(a.contains(new L.Point(54, 65))).toBeFalsy();
|
expect(a.contains(new L.Point(54, 65))).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#isValid', function() {
|
||||||
|
it('should return true if properly set up', function() {
|
||||||
|
expect(a.isValid()).toBeTruthy();
|
||||||
|
});
|
||||||
|
it('should return false if is invalid', function() {
|
||||||
|
expect(c.isValid()).toBeFalsy();
|
||||||
|
});
|
||||||
|
it('should be valid if extended', function() {
|
||||||
|
c.extend([0, 0]);
|
||||||
|
expect(c.isValid()).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -122,6 +122,10 @@ L.LatLngBounds = L.Class.extend({
|
|||||||
|
|
||||||
return this._southWest.equals(bounds.getSouthWest()) &&
|
return this._southWest.equals(bounds.getSouthWest()) &&
|
||||||
this._northEast.equals(bounds.getNorthEast());
|
this._northEast.equals(bounds.getNorthEast());
|
||||||
|
},
|
||||||
|
|
||||||
|
isValid: function () {
|
||||||
|
return !!(this._southWest && this._northEast);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -78,8 +78,11 @@ L.Bounds = L.Class.extend({
|
|||||||
yIntersects = (max2.y >= min.y) && (min2.y <= max.y);
|
yIntersects = (max2.y >= min.y) && (min2.y <= max.y);
|
||||||
|
|
||||||
return xIntersects && yIntersects;
|
return xIntersects && yIntersects;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
isValid: function () {
|
||||||
|
return !!(this.min && this.max);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
L.bounds = function (a, b) { // (Bounds) or (Point, Point) or (Point[])
|
L.bounds = function (a, b) { // (Bounds) or (Point, Point) or (Point[])
|
||||||
|
Loading…
Reference in New Issue
Block a user