Make Tile plugin validate its parameters, fixes #2109

This commit is contained in:
Daniel J. Hofmann
2016-03-18 15:30:28 +01:00
committed by Patrick Niklaus
parent c087a11659
commit f16a865420
2 changed files with 14 additions and 2 deletions
+12 -2
View File
@@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ENGINE_API_TILE_PARAMETERS_HPP
#define ENGINE_API_TILE_PARAMETERS_HPP
#include <cmath>
namespace osrm
{
namespace engine
@@ -41,8 +43,16 @@ struct TileParameters final
unsigned y;
unsigned z;
// FIXME check if x and y work with z
bool IsValid() { return z < 20; };
bool IsValid() const
{
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Zoom_levels
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#X_and_Y
const auto valid_x = x <= static_cast<unsigned>(std::pow(2., z)) - 1;
const auto valid_y = y <= static_cast<unsigned>(std::pow(2., z)) - 1;
const auto valid_z = z < 20;
return valid_x && valid_y && valid_z;
};
};
}
}