forked from maplibre/maplibre-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from windycom/kubapelc/tilebounds-antimeridian-fix
TileBounds supports ranges that cross the antimeridian
- Loading branch information
Showing
2 changed files
with
85 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {TileBounds} from './tile_bounds'; | ||
import {CanonicalTileID} from './tile_id'; | ||
|
||
describe('TileBounds', () => { | ||
test('default', () => { | ||
const bounds = new TileBounds([-180, -90, 180, 90]); | ||
expect(bounds.contains(new CanonicalTileID(2, 0, 0))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 1, 1))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 2, 2))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 3, 3))).toBe(true); | ||
}); | ||
|
||
describe('latitude', () => { | ||
test('is clamped', () => { | ||
const bounds = new TileBounds([-180, -900, 180, 900]); | ||
expect(bounds.contains(new CanonicalTileID(2, 0, 0))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 1, 1))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 2, 2))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 3, 3))).toBe(true); | ||
}); | ||
|
||
test('limits extent', () => { | ||
const bounds = new TileBounds([-180, -45, 180, 45]); | ||
expect(bounds.contains(new CanonicalTileID(2, 0, 0))).toBe(false); | ||
expect(bounds.contains(new CanonicalTileID(2, 1, 1))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 2, 2))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 3, 3))).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('longitude with wrapping', () => { | ||
test('half range', () => { | ||
const bounds = new TileBounds([0, -90, 180, 90]); | ||
expect(bounds.contains(new CanonicalTileID(2, 0, 0))).toBe(false); | ||
expect(bounds.contains(new CanonicalTileID(2, 1, 1))).toBe(false); | ||
expect(bounds.contains(new CanonicalTileID(2, 2, 2))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 3, 3))).toBe(true); | ||
}); | ||
|
||
test('wrapped positive', () => { | ||
const bounds = new TileBounds([0, -90, 270, 90]); | ||
expect(bounds.contains(new CanonicalTileID(2, 0, 0))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 1, 1))).toBe(false); | ||
expect(bounds.contains(new CanonicalTileID(2, 2, 2))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 3, 3))).toBe(true); | ||
}); | ||
|
||
test('wrapped negative', () => { | ||
const bounds = new TileBounds([-270, -90, 0, 90]); | ||
expect(bounds.contains(new CanonicalTileID(2, 0, 0))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 1, 1))).toBe(true); | ||
expect(bounds.contains(new CanonicalTileID(2, 2, 2))).toBe(false); | ||
expect(bounds.contains(new CanonicalTileID(2, 3, 3))).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters