[core] TileJSON conversion clamps bounds longitude to [-180,180], per spec

This commit is contained in:
Asheem Mamoowala
2018-03-08 12:18:59 -08:00
parent c54035afb1
commit 7df451def6
2 changed files with 12 additions and 0 deletions

View File

@@ -100,6 +100,8 @@ public:
error = { "bounds left longitude should be less than right longitude" };
return {};
}
*left = util::max(-180.0, *left);
*right = util::min(180.0, *right);
result.bounds = LatLngBounds::hull({ *bottom, *left }, { *top, *right });
}

View File

@@ -62,6 +62,16 @@ TEST(Tileset, ValidWorldBounds) {
EXPECT_EQ(converted->bounds, LatLngBounds::hull({90, -180}, {-90, 180}));
}
TEST(Tileset, BoundsAreClamped) {
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-181.0000005,-90,180.00000000000006,90]
})JSON", error);
EXPECT_TRUE((bool) converted);
EXPECT_EQ(converted->bounds, LatLngBounds::hull({90, -180}, {-90, 180}));
}
TEST(Tileset, FullConversion) {
Error error;
Tileset converted = *convertJSON<Tileset>(R"JSON({