diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-06-16 13:43:53 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-08-08 15:52:41 +0300 |
commit | b218d7d0b63545ecb55bec95f9a5d06bf64e32cc (patch) | |
tree | 3b883e74c804eeda336f5605b78ea776df817e3d | |
parent | 3952ff5c343844d76f75ede0afc8ddad55748a0d (diff) | |
download | qtlocation-mapboxgl-b218d7d0b63545ecb55bec95f9a5d06bf64e32cc.tar.gz |
[core] tileCover zoom is uint8_t
-rw-r--r-- | src/mbgl/renderer/tile_pyramid.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/util/tile_cover.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/util/tile_cover.hpp | 12 |
3 files changed, 23 insertions, 20 deletions
diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index 89c4aa0007..4f5a89f4d5 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -93,15 +93,15 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer handleWrapJump(parameters.transformState.getLatLng().longitude()); // Determine the overzooming/underzooming amounts and required tiles. - int32_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize); - int32_t tileZoom = overscaledZoom; - int32_t panZoom = zoomRange.max; + uint8_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize); + uint8_t tileZoom = overscaledZoom; + uint8_t panZoom = zoomRange.max; std::vector<UnwrappedTileID> idealTiles; std::vector<UnwrappedTileID> panTiles; if (overscaledZoom >= zoomRange.min) { - int32_t idealZoom = std::min<int32_t>(zoomRange.max, overscaledZoom); + uint8_t idealZoom = std::min(zoomRange.max, overscaledZoom); // Make sure we're not reparsing overzoomed raster tiles. @@ -114,7 +114,10 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer // Request lower zoom level tiles (if configured to do so) in an attempt // to show something on the screen faster at the cost of a little of bandwidth. if (parameters.prefetchZoomDelta) { - panZoom = std::max<int32_t>(tileZoom - parameters.prefetchZoomDelta, zoomRange.min); + panZoom = util::clamp( + util::min(uint8_t(tileZoom - parameters.prefetchZoomDelta), tileZoom), + zoomRange.min, + util::min(uint8_t(zoomRange.max - parameters.prefetchZoomDelta), zoomRange.max)); } if (panZoom < idealZoom) { @@ -151,7 +154,7 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer // tiles are used from the cache, but not created. optional<util::TileRange> tileRange = {}; if (bounds) { - tileRange = util::TileRange::fromLatLngBounds(*bounds, zoomRange.min, std::min(tileZoom, (int32_t)zoomRange.max)); + tileRange = util::TileRange::fromLatLngBounds(*bounds, zoomRange.min, std::min(tileZoom, zoomRange.max)); } auto createTileFn = [&](const OverscaledTileID& tileID) -> Tile* { if (tileRange && !tileRange->contains(tileID.canonical)) { diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp index 3f39e53d40..64d1fb374e 100644 --- a/src/mbgl/util/tile_cover.cpp +++ b/src/mbgl/util/tile_cover.cpp @@ -83,7 +83,7 @@ std::vector<UnwrappedTileID> tileCover(const Point<double>& tl, const Point<double>& br, const Point<double>& bl, const Point<double>& c, - int32_t z) { + uint8_t z) { const int32_t tiles = 1 << z; struct ID { @@ -129,7 +129,7 @@ std::vector<UnwrappedTileID> tileCover(const Point<double>& tl, } // namespace -int32_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) { +uint8_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) { zoom += ::log2(util::tileSize / size); if (type == style::SourceType::Raster || type == style::SourceType::Video) { return ::round(zoom); @@ -138,7 +138,7 @@ int32_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) { } } -std::vector<UnwrappedTileID> tileCover(const LatLngBounds& bounds_, int32_t z) { +std::vector<UnwrappedTileID> tileCover(const LatLngBounds& bounds_, uint8_t z) { if (bounds_.isEmpty() || bounds_.south() > util::LATITUDE_MAX || bounds_.north() < -util::LATITUDE_MAX) { @@ -158,7 +158,7 @@ std::vector<UnwrappedTileID> tileCover(const LatLngBounds& bounds_, int32_t z) { z); } -std::vector<UnwrappedTileID> tileCover(const TransformState& state, int32_t z) { +std::vector<UnwrappedTileID> tileCover(const TransformState& state, uint8_t z) { assert(state.valid()); const double w = state.getSize().width; @@ -172,7 +172,7 @@ std::vector<UnwrappedTileID> tileCover(const TransformState& state, int32_t z) { z); } -std::vector<UnwrappedTileID> tileCover(const Geometry<double>& geometry, int32_t z) { +std::vector<UnwrappedTileID> tileCover(const Geometry<double>& geometry, uint8_t z) { std::vector<UnwrappedTileID> result; TileCover tc(geometry, z, true); while (tc.hasNext()) { @@ -182,7 +182,7 @@ std::vector<UnwrappedTileID> tileCover(const Geometry<double>& geometry, int32_t return result; } -// Taken from https://github.com/mapbox/sphericalmercator#xyzbbox-zoom-tms_style-srs +// Taken from https://github.com/mapbox/sphericalmercator#xyzbbox-z-tms_style-srs // Computes the projected tiles for the lower left and upper right points of the bounds // and uses that to compute the tile cover count uint64_t tileCount(const LatLngBounds& bounds, uint8_t zoom){ @@ -212,7 +212,7 @@ uint64_t tileCount(const Geometry<double>& geometry, uint8_t z) { return tileCount; } -TileCover::TileCover(const LatLngBounds&bounds_, int32_t z) { +TileCover::TileCover(const LatLngBounds&bounds_, uint8_t z) { LatLngBounds bounds = LatLngBounds::hull( { std::max(bounds_.south(), -util::LATITUDE_MAX), bounds_.west() }, { std::min(bounds_.north(), util::LATITUDE_MAX), bounds_.east() }); @@ -232,7 +232,7 @@ TileCover::TileCover(const LatLngBounds&bounds_, int32_t z) { impl = std::make_unique<TileCover::Impl>(z, p, false); } -TileCover::TileCover(const Geometry<double>& geom, int32_t z, bool project/* = true*/) +TileCover::TileCover(const Geometry<double>& geom, uint8_t z, bool project/* = true*/) : impl( std::make_unique<TileCover::Impl>(z, geom, project)) { } diff --git a/src/mbgl/util/tile_cover.hpp b/src/mbgl/util/tile_cover.hpp index c953d764d2..552f252960 100644 --- a/src/mbgl/util/tile_cover.hpp +++ b/src/mbgl/util/tile_cover.hpp @@ -18,9 +18,9 @@ namespace util { // Helper class to stream tile-cover results per row class TileCover { public: - TileCover(const LatLngBounds&, int32_t z); + TileCover(const LatLngBounds&, uint8_t z); // When project == true, projects the geometry points to tile coordinates - TileCover(const Geometry<double>&, int32_t z, bool project = true); + TileCover(const Geometry<double>&, uint8_t z, bool project = true); ~TileCover(); optional<UnwrappedTileID> next(); @@ -31,11 +31,11 @@ private: std::unique_ptr<Impl> impl; }; -int32_t coveringZoomLevel(double z, style::SourceType type, uint16_t tileSize); +uint8_t coveringZoomLevel(double z, style::SourceType type, uint16_t tileSize); -std::vector<UnwrappedTileID> tileCover(const TransformState&, int32_t z); -std::vector<UnwrappedTileID> tileCover(const LatLngBounds&, int32_t z); -std::vector<UnwrappedTileID> tileCover(const Geometry<double>&, int32_t z); +std::vector<UnwrappedTileID> tileCover(const TransformState&, uint8_t z); +std::vector<UnwrappedTileID> tileCover(const LatLngBounds&, uint8_t z); +std::vector<UnwrappedTileID> tileCover(const Geometry<double>&, uint8_t z); // Compute only the count of tiles needed for tileCover uint64_t tileCount(const LatLngBounds&, uint8_t z); |