Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Tile cover LOD: lod covers single level tile cover
Browse files Browse the repository at this point in the history
Unit test verifies that, with different camera parameters combinations LOD tile cover covers all tiles returned by single level tileCover.
  • Loading branch information
astojilj committed Aug 5, 2019
1 parent b128895 commit 667a08f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mbgl/util/tile_cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ std::vector<UnwrappedTileID> tileCoverWithLOD(const TransformState& state, int32

const auto offset = state.getCenterOffset();
constexpr double zoomDiff = 1.0;
// Explanation on 0.55: mathematically, it is 0.5 used in calculation of
// the next LOD. 0.55 is chosen to avoid using LOD for less than 60 degrees
// pitch.
constexpr double coefLOD[] = {
0.55 * zoomDiff / (zoomDiff + 1),
0.55 * (zoomDiff + 1) / (zoomDiff + 2),
Expand Down
29 changes: 29 additions & 0 deletions test/util/tile_cover.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,35 @@ TEST(TileCover, PitchWithLargerResultSet) {
}), (std::vector<UnwrappedTileID> { cover.begin(), cover.begin() + 16}) );
}

TEST(TileCover, TileCoverLODCoversSingleLevelTileCover) {
Transform transform;
transform.resize({ 512, 768 });

std::vector<EdgeInsets> padding = { EdgeInsets { 0, 100, 0, 0 }, EdgeInsets { 800, 0, 0, 0 } };
std::vector<int32_t> zoom = { 14, 22 };
std::vector<double> bearing = { 2, 45, -22.5 };
std::vector<double> pitch = { 0, 30, 90 };

for (auto pad : padding) {
for (auto z : zoom) {
for (auto bear : bearing) {
for (auto p : pitch) {
transform.jumpTo(CameraOptions().withCenter(LatLng { 0.1, -0.1 })
.withPadding(pad).withZoom(z).withBearing(bear).withPitch(p));
auto singleLevelCover = util::tileCover(transform.getState(), z);
auto lodTileCover = util::tileCoverWithLOD(transform.getState(), z, z / 10 * 10);
for (auto tile: singleLevelCover) {
EXPECT_NE(lodTileCover.cend(), std::find_if(lodTileCover.cbegin(), lodTileCover.cend(),
[&tile] (auto parent) { return tile == parent || tile.isChildOf(parent); })) << "for padding: ["
<< pad.top() << ", " << pad.left() << ", 0, 0] zoom:" << z << " bearing:"
<< bear << " and pitch:" << p;
}
}
}
}
}
}

TEST(TileCover, WorldZ1) {
EXPECT_EQ((std::vector<UnwrappedTileID>{
{ 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 },
Expand Down

0 comments on commit 667a08f

Please sign in to comment.