summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-03-08 12:35:33 -0800
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-03-08 13:42:57 -0800
commitab86e0fefeea07c8c4cc200059c7084319537c65 (patch)
tree788f452be9b62ea8d8c9d6d04d5e41d776fdcb71
parent6179110b6bfe8ee0880a055a31c12a88f9bd9b20 (diff)
downloadqtlocation-mapboxgl-upstream/boba-tilejson-clamp-bounds.tar.gz
[core] TileJSON conversion clamps bounds longitude to [-180,180], per specupstream/boba-tilejson-clamp-bounds
-rw-r--r--src/mbgl/style/conversion/tileset.cpp2
-rw-r--r--test/style/conversion/tileset.test.cpp10
2 files changed, 12 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/tileset.cpp b/src/mbgl/style/conversion/tileset.cpp
index 6d89cef944..a2c4aa80b3 100644
--- a/src/mbgl/style/conversion/tileset.cpp
+++ b/src/mbgl/style/conversion/tileset.cpp
@@ -103,6 +103,8 @@ optional<Tileset> Converter<Tileset>::operator()(const Convertible& value, Error
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 });
}
diff --git a/test/style/conversion/tileset.test.cpp b/test/style/conversion/tileset.test.cpp
index 9487277cca..f10aa0e318 100644
--- a/test/style/conversion/tileset.test.cpp
+++ b/test/style/conversion/tileset.test.cpp
@@ -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({