add margin to LatLngBounds.equals method (#5071)
* add margin to LatLngBounds equals method * add tests
This commit is contained in:
parent
53e90945aa
commit
ad75456fa5
@ -75,6 +75,14 @@ describe('LatLngBounds', function () {
|
||||
expect(a.equals([[14, 13], [30, 40]])).to.eql(false);
|
||||
expect(a.equals(null)).to.eql(false);
|
||||
});
|
||||
|
||||
it("returns true if compared objects are equal within a certain margin", function () {
|
||||
expect(a.equals([[15, 11], [29, 41]], 1)).to.eql(true);
|
||||
});
|
||||
|
||||
it("returns false if compared objects are not equal within a certain margin", function () {
|
||||
expect(a.equals([[15, 11], [29, 41]], 0.5)).to.eql(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValid', function () {
|
||||
|
@ -211,15 +211,15 @@ LatLngBounds.prototype = {
|
||||
return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');
|
||||
},
|
||||
|
||||
// @method equals(otherBounds: LatLngBounds): Boolean
|
||||
// Returns `true` if the rectangle is equivalent (within a small margin of error) to the given bounds.
|
||||
equals: function (bounds) {
|
||||
// @method equals(otherBounds: LatLngBounds, maxMargin?: Number): Boolean
|
||||
// Returns `true` if the rectangle is equivalent (within a small margin of error) to the given bounds. The margin of error can be overriden by setting `maxMargin` to a small number.
|
||||
equals: function (bounds, maxMargin) {
|
||||
if (!bounds) { return false; }
|
||||
|
||||
bounds = toLatLngBounds(bounds);
|
||||
|
||||
return this._southWest.equals(bounds.getSouthWest()) &&
|
||||
this._northEast.equals(bounds.getNorthEast());
|
||||
return this._southWest.equals(bounds.getSouthWest(), maxMargin) &&
|
||||
this._northEast.equals(bounds.getNorthEast(), maxMargin);
|
||||
},
|
||||
|
||||
// @method isValid(): Boolean
|
||||
|
Loading…
Reference in New Issue
Block a user