From 7df451def6c37bd842b13954b91fe8f303ecec9f Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Thu, 8 Mar 2018 12:18:59 -0800 Subject: [core] TileJSON conversion clamps bounds longitude to [-180,180], per spec --- include/mbgl/style/conversion/tileset.hpp | 2 ++ test/style/conversion/tileset.test.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/mbgl/style/conversion/tileset.hpp b/include/mbgl/style/conversion/tileset.hpp index 6ec46aa7b6..16322b58ee 100644 --- a/include/mbgl/style/conversion/tileset.hpp +++ b/include/mbgl/style/conversion/tileset.hpp @@ -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 }); } 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 converted = convertJSON(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(R"JSON({ -- cgit v1.2.1