Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Letting LngLatBounds.extend accepts LngLatLike and LngLatBoundsLike as well. #9293

Merged
merged 5 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/geo/lng_lat_bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class LngLatBounds {
}

/**
* Extend the bounds to include a given LngLat or LngLatBounds.
* Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
*
* @param {LngLat|LngLatBounds} obj object to extend to
* @param {LngLatLike|LngLatBoundsLike} obj object to extend to
sgolbabaei marked this conversation as resolved.
Show resolved Hide resolved
* @returns {LngLatBounds} `this`
*/
extend(obj: LngLat | LngLatBounds) {
extend(obj: LngLatLike | LngLatBoundsLike) {
const sw = this._sw,
ne = this._ne;
let sw2, ne2;
Expand All @@ -83,7 +83,9 @@ class LngLatBounds {

} else {
if (Array.isArray(obj)) {
if (obj.every(Array.isArray)) {
// obj is LngLatBounds object if every element in the Obj array is also an array or
// if the LngLatBoundLike is defiend as a array of 4 numbers
sgolbabaei marked this conversation as resolved.
Show resolved Hide resolved
if (obj.length > 2 || obj.every(Array.isArray)) {
return this.extend(LngLatBounds.convert(obj));
} else {
return this.extend(LngLat.convert(obj));
Expand Down
9 changes: 9 additions & 0 deletions test/unit/geo/lng_lat_bounds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ test('LngLatBounds', (t) => {
t.test('#extend with bounds', (t) => {
const bounds1 = new LngLatBounds([0, 0], [10, 10]);
const bounds2 = new LngLatBounds([-10, -10], [10, 10]);

bounds1.extend(bounds2);

t.equal(bounds1.getSouth(), -10);
Expand All @@ -81,6 +82,14 @@ test('LngLatBounds', (t) => {
t.equal(bounds1.getNorth(), 15);
t.equal(bounds1.getEast(), 15);

const bounds4 = new LngLatBounds([-20, -20, 20, 20]);
sgolbabaei marked this conversation as resolved.
Show resolved Hide resolved
bounds1.extend(bounds4);

t.equal(bounds1.getSouth(), -20);
t.equal(bounds1.getWest(), -20);
t.equal(bounds1.getNorth(), 20);
t.equal(bounds1.getEast(), 20);

t.end();
});

Expand Down