mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-16 16:45:22 +00:00
Feat(Bounds): add new methods for 2 missing corners (#5488)
* Feat(Bounds): add getTopLeft & getBottomRight methods as suggested in #5475, for consistency with `LatLngBounds` methods which already provide methods for the 4 possible corners. Also include the docstrings. * Docs(Bounds): add comments to identify corners in BoundsSpec. * Test(Bounds): add tests for existing corner methods namely getBottomLeft and getTopRight. Checked that expecting different values make the tests fail. * Test(Bounds): add spec for 2 new corner methods namely getTopLeft and getBottomRight. Closes #5475 together with previous PR #5487. * Refactor(Bounds): return this.min(max) instead of new Point as TopLeft corner is tha same as this.min (BottomRight same as this.max). * Docs(Bounds): add links to this.min(max) to make it clearer that these methods are just shorthands to already available properties. Furthermore, it implies that they output those properties directly, making a clue for the app developer that if he/she wants to modify them, they should be cloned before doing so in order to prevent unintentional behaviour.
This commit is contained in:
@ -3,12 +3,12 @@ describe('Bounds', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
a = new L.Bounds(
|
||||
new L.Point(14, 12),
|
||||
new L.Point(30, 40));
|
||||
new L.Point(14, 12), // left, top
|
||||
new L.Point(30, 40)); // right, bottom
|
||||
b = new L.Bounds([
|
||||
new L.Point(20, 12),
|
||||
new L.Point(14, 20),
|
||||
new L.Point(30, 40)
|
||||
new L.Point(20, 12), // center, top
|
||||
new L.Point(14, 20), // left, middle
|
||||
new L.Point(30, 40) // right, bottom
|
||||
]);
|
||||
c = new L.Bounds();
|
||||
});
|
||||
@ -78,6 +78,30 @@ describe('Bounds', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getBottomLeft', function () {
|
||||
it('returns the proper bounds bottom-left value', function () {
|
||||
expect(a.getBottomLeft()).to.eql(new L.Point(14, 40)); // left, bottom
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTopRight', function () {
|
||||
it('returns the proper bounds top-right value', function () {
|
||||
expect(a.getTopRight()).to.eql(new L.Point(30, 12)); // right, top
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTopLeft', function () {
|
||||
it('returns the proper bounds top-left value', function () {
|
||||
expect(a.getTopLeft()).to.eql(new L.Point(14, 12)); // left, top
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getBottomRight', function () {
|
||||
it('returns the proper bounds bottom-right value', function () {
|
||||
expect(a.getBottomRight()).to.eql(new L.Point(30, 40)); // left, bottom
|
||||
});
|
||||
});
|
||||
|
||||
describe('L.bounds factory', function () {
|
||||
it('creates bounds from array of number arrays', function () {
|
||||
var bounds = L.bounds([[14, 12], [30, 40]]);
|
||||
|
Reference in New Issue
Block a user