diff options
Diffstat (limited to 'src/mbgl/util/grid_index.cpp')
-rw-r--r-- | src/mbgl/util/grid_index.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp index f6b59b1bac..f33e889ddb 100644 --- a/src/mbgl/util/grid_index.cpp +++ b/src/mbgl/util/grid_index.cpp @@ -9,14 +9,16 @@ namespace mbgl { template <class T> -GridIndex<T>::GridIndex(const float width_, const float height_, const int16_t cellSize_) : +GridIndex<T>::GridIndex(const float width_, const float height_, const uint32_t cellSize_) : width(width_), height(height_), - xCellCount(std::ceil(width_ / cellSize_)), - yCellCount(std::ceil(height_ / cellSize_)), - xScale(xCellCount / width_), - yScale(yCellCount / height_) + xCellCount(std::ceil(width / cellSize_)), + yCellCount(std::ceil(height / cellSize_)), + xScale(xCellCount / width), + yScale(yCellCount / height) { + assert(width > 0.0f); + assert(height > 0.0f); boxCells.resize(xCellCount * yCellCount); circleCells.resize(xCellCount * yCellCount); } @@ -30,7 +32,7 @@ void GridIndex<T>::insert(T&& t, const BBox& bbox) { auto cx2 = convertToXCellCoord(bbox.max.x); auto cy2 = convertToYCellCoord(bbox.max.y); - int16_t x, y, cellIndex; + std::size_t x, y, cellIndex; for (x = cx1; x <= cx2; ++x) { for (y = cy1; y <= cy2; ++y) { cellIndex = xCellCount * y + x; @@ -50,7 +52,7 @@ void GridIndex<T>::insert(T&& t, const BCircle& bcircle) { auto cx2 = convertToXCellCoord(bcircle.center.x + bcircle.radius); auto cy2 = convertToYCellCoord(bcircle.center.y + bcircle.radius); - int16_t x, y, cellIndex; + std::size_t x, y, cellIndex; for (x = cx1; x <= cx2; ++x) { for (y = cy1; y <= cy2; ++y) { cellIndex = xCellCount * y + x; @@ -151,7 +153,7 @@ void GridIndex<T>::query(const BBox& queryBBox, std::function<bool (const T&, co auto cx2 = convertToXCellCoord(queryBBox.max.x); auto cy2 = convertToYCellCoord(queryBBox.max.y); - int16_t x, y, cellIndex; + std::size_t x, y, cellIndex; for (x = cx1; x <= cx2; ++x) { for (y = cy1; y <= cy2; ++y) { cellIndex = xCellCount * y + x; @@ -214,7 +216,7 @@ void GridIndex<T>::query(const BCircle& queryBCircle, std::function<bool (const auto cx2 = convertToXCellCoord(queryBCircle.center.x + queryBCircle.radius); auto cy2 = convertToYCellCoord(queryBCircle.center.y + queryBCircle.radius); - int16_t x, y, cellIndex; + std::size_t x, y, cellIndex; for (x = cx1; x <= cx2; ++x) { for (y = cy1; y <= cy2; ++y) { cellIndex = xCellCount * y + x; @@ -252,12 +254,12 @@ void GridIndex<T>::query(const BCircle& queryBCircle, std::function<bool (const } template <class T> -int16_t GridIndex<T>::convertToXCellCoord(const float x) const { +std::size_t GridIndex<T>::convertToXCellCoord(const float x) const { return util::max(0.0, util::min(xCellCount - 1.0, std::floor(x * xScale))); } template <class T> -int16_t GridIndex<T>::convertToYCellCoord(const float y) const { +std::size_t GridIndex<T>::convertToYCellCoord(const float y) const { return util::max(0.0, util::min(yCellCount - 1.0, std::floor(y * yScale))); } |