From d8411f26d24b14b829ecab7617b403ad0c872ed8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 6 Apr 2015 12:17:18 -0700 Subject: [PATCH] =?UTF-8?q?Tile::ID=20=E2=87=A2=20TileID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows making both Tile and TileID private. --- include/mbgl/map/map.hpp | 2 +- include/mbgl/map/tile.hpp | 90 ---------------- include/mbgl/map/transform_state.hpp | 7 +- src/mbgl/map/annotation.cpp | 25 ++--- {include => src}/mbgl/map/annotation.hpp | 10 +- src/mbgl/map/live_tile_data.cpp | 2 +- src/mbgl/map/live_tile_data.hpp | 2 +- src/mbgl/map/map.cpp | 2 +- src/mbgl/map/raster_tile_data.cpp | 2 +- src/mbgl/map/raster_tile_data.hpp | 3 +- src/mbgl/map/source.cpp | 45 ++++---- src/mbgl/map/source.hpp | 27 ++--- src/mbgl/map/tile.cpp | 56 +--------- src/mbgl/map/tile.hpp | 43 ++++++++ src/mbgl/map/tile_data.cpp | 2 +- src/mbgl/map/tile_data.hpp | 6 +- src/mbgl/map/tile_id.cpp | 52 ++++++++++ src/mbgl/map/tile_id.hpp | 55 ++++++++++ src/mbgl/map/transform_state.cpp | 3 +- src/mbgl/map/vector_tile_data.cpp | 2 +- src/mbgl/map/vector_tile_data.hpp | 3 +- src/mbgl/renderer/bucket.hpp | 8 +- src/mbgl/renderer/debug_bucket.cpp | 2 +- src/mbgl/renderer/debug_bucket.hpp | 2 +- src/mbgl/renderer/fill_bucket.cpp | 2 +- src/mbgl/renderer/fill_bucket.hpp | 2 +- src/mbgl/renderer/line_bucket.cpp | 2 +- src/mbgl/renderer/line_bucket.hpp | 2 +- src/mbgl/renderer/painter.cpp | 3 +- src/mbgl/renderer/painter.hpp | 15 +-- src/mbgl/renderer/painter_clipping.cpp | 1 + src/mbgl/renderer/painter_debug.cpp | 1 + src/mbgl/renderer/painter_fill.cpp | 2 +- src/mbgl/renderer/painter_line.cpp | 2 +- src/mbgl/renderer/painter_raster.cpp | 2 +- src/mbgl/renderer/painter_symbol.cpp | 4 +- src/mbgl/renderer/raster_bucket.cpp | 2 +- src/mbgl/renderer/raster_bucket.hpp | 2 +- src/mbgl/renderer/symbol_bucket.cpp | 2 +- src/mbgl/renderer/symbol_bucket.hpp | 2 +- src/mbgl/util/clip_ids.cpp | 4 +- src/mbgl/util/clip_ids.hpp | 9 +- test/miscellaneous/clip_ids.cpp | 127 ++++++++++++----------- test/miscellaneous/tile.cpp | 74 ++++++------- 44 files changed, 367 insertions(+), 344 deletions(-) delete mode 100644 include/mbgl/map/tile.hpp rename {include => src}/mbgl/map/annotation.hpp (76%) create mode 100644 src/mbgl/map/tile.hpp create mode 100644 src/mbgl/map/tile_id.cpp create mode 100644 src/mbgl/map/tile_id.hpp diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index f8e082f69..129d463b2 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -192,7 +192,7 @@ private: void processTasks(); - void updateAnnotationTiles(const std::vector&); + void updateAnnotationTiles(const std::vector&); enum class Mode : uint8_t { None, // we're not doing any processing diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp deleted file mode 100644 index 146ebe6ad..000000000 --- a/include/mbgl/map/tile.hpp +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef MBGL_MAP_TILE -#define MBGL_MAP_TILE - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace mbgl { - -class TileData; -struct box; - -struct ClipID { - inline ClipID() {} - inline ClipID(const std::string &mask_, const std::string &reference_) : mask(mask_), reference(reference_) {} - - std::bitset<8> mask; - std::bitset<8> reference; - - inline bool operator==(const ClipID &other) const { - return mask == other.mask && reference == other.reference; - } -}; - -class Tile : private util::noncopyable { -public: - struct ID { - const int16_t w = 0; - const int8_t z = 0; - const int32_t x = 0, y = 0; - - inline explicit ID(int8_t z_, int32_t x_, int32_t y_) - : w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_) {} - - inline uint64_t to_uint64() const { - return ((std::pow(2, z) * y + x) * 32) + z; - } - - struct Hash { - std::size_t operator()(ID const& i) const { - return std::hash()(i.to_uint64()); - } - }; - - inline bool operator==(const ID& rhs) const { - return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y; - } - - inline bool operator!=(const ID& rhs) const { - return !operator==(rhs); - } - - inline bool operator<(const ID &rhs) const { - if (w != rhs.w) return w < rhs.w; - if (z != rhs.z) return z < rhs.z; - if (x != rhs.x) return x < rhs.x; - return y < rhs.y; - } - - ID parent(int8_t z) const; - ID normalized() const; - std::forward_list children(int32_t z) const; - bool isChildOf(const Tile::ID &id) const; - operator std::string() const; - }; - - static std::forward_list cover(int8_t z, const box& bounds); - -public: - explicit Tile(const ID& id); - -public: - const Tile::ID id; - ClipID clip; - mat4 matrix; - util::ptr data; -}; - -} - -#endif diff --git a/include/mbgl/map/transform_state.hpp b/include/mbgl/map/transform_state.hpp index c1a324a89..f6a00a4a3 100644 --- a/include/mbgl/map/transform_state.hpp +++ b/include/mbgl/map/transform_state.hpp @@ -1,8 +1,6 @@ #ifndef MBGL_MAP_TRANSFORM_STATE #define MBGL_MAP_TRANSFORM_STATE -#include - #include #include #include @@ -13,12 +11,15 @@ namespace mbgl { +class TileID; +struct box; + class TransformState { friend class Transform; public: // Matrix - void matrixFor(mat4& matrix, const Tile::ID& id) const; + void matrixFor(mat4& matrix, const TileID& id) const; box cornersToBox(uint32_t z) const; // Dimensions diff --git a/src/mbgl/map/annotation.cpp b/src/mbgl/map/annotation.cpp index fa26af785..b921c08f7 100644 --- a/src/mbgl/map/annotation.cpp +++ b/src/mbgl/map/annotation.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -29,7 +30,7 @@ private: private: const AnnotationType type = AnnotationType::Point; const AnnotationSegments geometry; - std::unordered_map, Tile::ID::Hash> tileFeatures; + std::unordered_map, TileID::Hash> tileFeatures; const LatLngBounds bounds; }; @@ -82,7 +83,7 @@ vec2 AnnotationManager::projectPoint(const LatLng& point) { return { x, y }; } -std::pair, AnnotationIDs> AnnotationManager::addPointAnnotations( +std::pair, AnnotationIDs> AnnotationManager::addPointAnnotations( const std::vector& points, const std::vector& symbols, const Map& map) { std::lock_guard lock(mtx); @@ -97,7 +98,7 @@ std::pair, AnnotationIDs> AnnotationManager::addPointAnnot std::vector annotationIDs; annotationIDs.reserve(points.size()); - std::vector affectedTiles; + std::vector affectedTiles; for (size_t i = 0; i < points.size(); ++i) { const uint32_t annotationID = nextID(); @@ -121,7 +122,7 @@ std::pair, AnnotationIDs> AnnotationManager::addPointAnnot for (int8_t z = maxZoom; z >= 0; z--) { affectedTiles.emplace_back(z, x, y); - Tile::ID tileID = affectedTiles.back(); + TileID tileID = affectedTiles.back(); // calculate tile coordinate const Coordinate coordinate(extent * (p.x * z2 - x), extent * (p.y * z2 - y)); @@ -180,10 +181,10 @@ std::pair, AnnotationIDs> AnnotationManager::addPointAnnot return std::make_pair(affectedTiles, annotationIDs); } -std::vector AnnotationManager::removeAnnotations(const AnnotationIDs& ids, const Map& map) { +std::vector AnnotationManager::removeAnnotations(const AnnotationIDs& ids, const Map& map) { std::lock_guard lock(mtx); - std::vector affectedTiles; + std::vector affectedTiles; std::vector z2s; uint8_t zoomCount = map.getMaxZoom() + 1; @@ -208,7 +209,7 @@ std::vector AnnotationManager::removeAnnotations(const AnnotationIDs& p = projectPoint(latLng); x = z2s[z] * p.x; y = z2s[z] * p.y; - Tile::ID tid(z, x, y); + TileID tid(z, x, y); // erase annotation from tile's list auto& tileAnnotations = tiles[tid].first; tileAnnotations.erase(annotationID); @@ -225,7 +226,7 @@ std::vector AnnotationManager::removeAnnotations(const AnnotationIDs& } } - // Tile::IDs for tiles that need refreshed. + // TileIDs for tiles that need refreshed. return affectedTiles; } @@ -239,13 +240,13 @@ std::vector AnnotationManager::getAnnotationsInBounds(const LatLngBoun const vec2 nePoint = projectPoint(queryBounds.ne); // tiles number y from top down - const Tile::ID nwTile(z, swPoint.x * z2, nePoint.y * z2); - const Tile::ID seTile(z, nePoint.x * z2, swPoint.y * z2); + const TileID nwTile(z, swPoint.x * z2, nePoint.y * z2); + const TileID seTile(z, nePoint.x * z2, swPoint.y * z2); std::vector matchingAnnotations; for (auto& tile : tiles) { - Tile::ID id = tile.first; + TileID id = tile.first; if (id.z == z) { if (id.x >= nwTile.x && id.x <= seTile.x && id.y >= nwTile.y && id.y <= seTile.y) { if (id.x > nwTile.x && id.x < seTile.x && id.y > nwTile.y && id.y < seTile.y) { @@ -292,7 +293,7 @@ LatLngBounds AnnotationManager::getBoundsForAnnotations(const AnnotationIDs& ids return bounds; } -const LiveTile* AnnotationManager::getTile(Tile::ID const& id) { +const LiveTile* AnnotationManager::getTile(const TileID& id) { std::lock_guard lock(mtx); const auto tile_it = tiles.find(id); diff --git a/include/mbgl/map/annotation.hpp b/src/mbgl/map/annotation.hpp similarity index 76% rename from include/mbgl/map/annotation.hpp rename to src/mbgl/map/annotation.hpp index efd91d908..f1596dbdf 100644 --- a/include/mbgl/map/annotation.hpp +++ b/src/mbgl/map/annotation.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_MAP_ANNOTATIONS #define MBGL_MAP_ANNOTATIONS -#include +#include #include #include #include @@ -28,13 +28,13 @@ public: ~AnnotationManager(); void setDefaultPointAnnotationSymbol(const std::string& symbol); - std::pair, AnnotationIDs> addPointAnnotations( + std::pair, AnnotationIDs> addPointAnnotations( const std::vector&, const std::vector& symbols, const Map&); - std::vector removeAnnotations(const AnnotationIDs&, const Map&); + std::vector removeAnnotations(const AnnotationIDs&, const Map&); AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const Map&) const; LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const; - const LiveTile* getTile(Tile::ID const& id); + const LiveTile* getTile(const TileID& id); static const std::string layerID; @@ -46,7 +46,7 @@ private: mutable std::mutex mtx; std::string defaultPointAnnotationSymbol; std::unordered_map> annotations; - std::unordered_map, std::unique_ptr>, Tile::ID::Hash> tiles; + std::unordered_map, std::unique_ptr>, TileID::Hash> tiles; uint32_t nextID_ = 0; }; diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp index 71b5a2e1b..6456e5153 100644 --- a/src/mbgl/map/live_tile_data.cpp +++ b/src/mbgl/map/live_tile_data.cpp @@ -8,7 +8,7 @@ using namespace mbgl; -LiveTileData::LiveTileData(Tile::ID const& id_, +LiveTileData::LiveTileData(const TileID& id_, AnnotationManager& annotationManager_, float mapMaxZoom, util::ptr