summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/feature_index.cpp74
-rw-r--r--src/mbgl/geometry/feature_index.hpp98
-rw-r--r--src/mbgl/source/source.cpp13
-rw-r--r--src/mbgl/source/source.hpp2
-rw-r--r--src/mbgl/style/style.cpp13
-rw-r--r--src/mbgl/style/style.hpp2
6 files changed, 103 insertions, 99 deletions
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp
index aeedea3a74..164431199e 100644
--- a/src/mbgl/geometry/feature_index.cpp
+++ b/src/mbgl/geometry/feature_index.cpp
@@ -10,20 +10,23 @@
#include <cassert>
#include <string>
-using namespace mbgl;
+namespace mbgl {
-FeatureIndex::FeatureIndex() : grid(util::EXTENT, 16, 0) {}
-
-void FeatureIndex::insert(const GeometryCollection& geometries, std::size_t index,
- const std::string& sourceLayerName, const std::string& bucketName) {
-
- for (auto& ring : geometries) {
+FeatureIndex::FeatureIndex()
+ : grid(util::EXTENT, 16, 0) {
+}
+void FeatureIndex::insert(const GeometryCollection& geometries,
+ std::size_t index,
+ const std::string& sourceLayerName,
+ const std::string& bucketName) {
+ for (const auto& ring : geometries) {
float minX = std::numeric_limits<float>::infinity();
float minY = std::numeric_limits<float>::infinity();
float maxX = -std::numeric_limits<float>::infinity();
float maxY = -std::numeric_limits<float>::infinity();
- for (auto& p : ring) {
+
+ for (const auto& p : ring) {
const float x = p.x;
const float y = p.y;
minX = util::min(minX, x);
@@ -38,23 +41,24 @@ void FeatureIndex::insert(const GeometryCollection& geometries, std::size_t inde
}
}
-bool vectorContains(const std::vector<std::string>& vector, const std::string& s) {
+static bool vectorContains(const std::vector<std::string>& vector, const std::string& s) {
return std::find(vector.begin(), vector.end(), s) != vector.end();
}
-bool vectorsIntersect(const std::vector<std::string>& vectorA, const std::vector<std::string>& vectorB) {
- for (auto& a : vectorA) {
- if (vectorContains(vectorB, a)) return true;;
+static bool vectorsIntersect(const std::vector<std::string>& vectorA, const std::vector<std::string>& vectorB) {
+ for (const auto& a : vectorA) {
+ if (vectorContains(vectorB, a)) {
+ return true;
+ }
}
return false;
}
-
-bool topDown(const IndexedSubfeature& a, const IndexedSubfeature& b) {
+static bool topDown(const IndexedSubfeature& a, const IndexedSubfeature& b) {
return a.sortIndex > b.sortIndex;
}
-bool topDownSymbols(const IndexedSubfeature& a, const IndexedSubfeature& b) {
+static bool topDownSymbols(const IndexedSubfeature& a, const IndexedSubfeature& b) {
return a.sortIndex < b.sortIndex;
}
@@ -77,8 +81,8 @@ void FeatureIndex::query(
float maxX = -std::numeric_limits<float>::infinity();
float maxY = -std::numeric_limits<float>::infinity();
- for (auto& ring : queryGeometry) {
- for (auto& p : ring) {
+ for (const auto& ring : queryGeometry) {
+ for (const auto& p : ring) {
minX = util::min<float>(minX, p.x);
minY = util::min<float>(minY, p.y);
maxX = util::max<float>(maxX, p.x);
@@ -95,7 +99,7 @@ void FeatureIndex::query(
std::sort(features.begin(), features.end(), topDown);
size_t previousSortIndex = std::numeric_limits<size_t>::max();
- for (auto& indexedFeature : features) {
+ for (const auto& indexedFeature : features) {
// If this feature is the same as the previous feature, skip it.
if (indexedFeature.sortIndex == previousSortIndex) continue;
@@ -108,7 +112,7 @@ void FeatureIndex::query(
assert(collisionTile);
std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(minX, minY, maxX, maxY, scale);
std::sort(symbolFeatures.begin(), symbolFeatures.end(), topDownSymbols);
- for (auto& symbolFeature : symbolFeatures) {
+ for (const auto& symbolFeature : symbolFeatures) {
addFeature(result, symbolFeature, queryGeometry, filterLayerIDs, geometryTile, style, bearing, pixelsToTileUnits);
}
}
@@ -124,20 +128,25 @@ void FeatureIndex::addFeature(
const float pixelsToTileUnits) const {
auto& layerIDs = bucketLayerIDs.at(indexedFeature.bucketName);
-
- if (filterLayerIDs && !vectorsIntersect(layerIDs, *filterLayerIDs)) return;
+ if (filterLayerIDs && !vectorsIntersect(layerIDs, *filterLayerIDs)) {
+ return;
+ }
auto sourceLayer = geometryTile.getLayer(indexedFeature.sourceLayerName);
assert(sourceLayer);
+
auto geometryTileFeature = sourceLayer->getFeature(indexedFeature.index);
assert(geometryTileFeature);
- for (auto& layerID : layerIDs) {
-
- if (filterLayerIDs && !vectorContains(*filterLayerIDs, layerID)) continue;
+ for (const auto& layerID : layerIDs) {
+ if (filterLayerIDs && !vectorContains(*filterLayerIDs, layerID)) {
+ continue;
+ }
auto styleLayer = style.getLayer(layerID);
- if (!styleLayer) continue;
+ if (!styleLayer) {
+ continue;
+ }
if (!styleLayer->is<SymbolLayer>()) {
auto geometries = geometryTileFeature->getGeometries();
@@ -162,20 +171,20 @@ optional<GeometryCollection> FeatureIndex::translateQueryGeometry(
const TranslateAnchorType anchorType,
const float bearing,
const float pixelsToTileUnits) {
-
- if (translate[0] == 0 && translate[1] == 0) return {};
+ if (translate[0] == 0 && translate[1] == 0) {
+ return {};
+ }
GeometryCoordinate translateVec(translate[0] * pixelsToTileUnits, translate[1] * pixelsToTileUnits);
-
if (anchorType == TranslateAnchorType::Viewport) {
translateVec = util::rotate(translateVec, -bearing);
}
GeometryCollection translated;
- for (auto& ring : queryGeometry) {
+ for (const auto& ring : queryGeometry) {
translated.emplace_back();
auto& translatedRing = translated.back();
- for (auto& p : ring) {
+ for (const auto& p : ring) {
translatedRing.push_back(p - translateVec);
}
}
@@ -183,10 +192,11 @@ optional<GeometryCollection> FeatureIndex::translateQueryGeometry(
}
void FeatureIndex::addBucketLayerName(const std::string& bucketName, const std::string& layerID) {
- auto& layerIDs = bucketLayerIDs[bucketName];
- layerIDs.push_back(layerID);
+ bucketLayerIDs[bucketName].push_back(layerID);
}
void FeatureIndex::setCollisionTile(std::unique_ptr<CollisionTile> collisionTile_) {
collisionTile = std::move(collisionTile_);
}
+
+} // namespace mbgl
diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp
index a3cb16ee76..0cb9a891d7 100644
--- a/src/mbgl/geometry/feature_index.hpp
+++ b/src/mbgl/geometry/feature_index.hpp
@@ -16,59 +16,57 @@ class CollisionTile;
enum class TranslateAnchorType : bool;
class IndexedSubfeature {
- public:
- IndexedSubfeature() = delete;
- std::size_t index;
- std::string sourceLayerName;
- std::string bucketName;
- size_t sortIndex;
+public:
+ IndexedSubfeature() = delete;
+ std::size_t index;
+ std::string sourceLayerName;
+ std::string bucketName;
+ size_t sortIndex;
};
class FeatureIndex {
- public:
- FeatureIndex();
-
- void insert(const GeometryCollection&, std::size_t index, const std::string& sourceLayerName, const std::string& bucketName);
-
- void query(
- std::unordered_map<std::string, std::vector<Feature>>& result,
- const GeometryCollection& queryGeometry,
- const float bearing,
- const double tileSize,
- const double scale,
- const optional<std::vector<std::string>>& layerIDs,
- const GeometryTile& geometryTile,
- const Style&) const;
-
- static optional<GeometryCollection> translateQueryGeometry(
- const GeometryCollection& queryGeometry,
- const std::array<float, 2>& translate,
- const TranslateAnchorType,
- const float bearing,
- const float pixelsToTileUnits);
-
- void addBucketLayerName(const std::string &bucketName, const std::string &layerName);
-
- void setCollisionTile(std::unique_ptr<CollisionTile>);
-
- private:
-
- void addFeature(
- std::unordered_map<std::string, std::vector<Feature>>& result,
- const IndexedSubfeature &indexedFeature,
- const GeometryCollection& queryGeometry,
- const optional<std::vector<std::string>>& filterLayerIDs,
- const GeometryTile& geometryTile,
- const Style& style,
- const float bearing,
- const float pixelsToTileUnits) const;
-
- std::unique_ptr<CollisionTile> collisionTile;
- GridIndex<IndexedSubfeature> grid;
- unsigned int sortIndex = 0;
-
- std::unordered_map<std::string,std::vector<std::string>> bucketLayerIDs;
-
+public:
+ FeatureIndex();
+
+ void insert(const GeometryCollection&, std::size_t index, const std::string& sourceLayerName, const std::string& bucketName);
+
+ void query(
+ std::unordered_map<std::string, std::vector<Feature>>& result,
+ const GeometryCollection& queryGeometry,
+ const float bearing,
+ const double tileSize,
+ const double scale,
+ const optional<std::vector<std::string>>& layerIDs,
+ const GeometryTile&,
+ const Style&) const;
+
+ static optional<GeometryCollection> translateQueryGeometry(
+ const GeometryCollection& queryGeometry,
+ const std::array<float, 2>& translate,
+ const TranslateAnchorType,
+ const float bearing,
+ const float pixelsToTileUnits);
+
+ void addBucketLayerName(const std::string& bucketName, const std::string& layerName);
+
+ void setCollisionTile(std::unique_ptr<CollisionTile>);
+
+private:
+ void addFeature(
+ std::unordered_map<std::string, std::vector<Feature>>& result,
+ const IndexedSubfeature&,
+ const GeometryCollection& queryGeometry,
+ const optional<std::vector<std::string>>& filterLayerIDs,
+ const GeometryTile&,
+ const Style&,
+ const float bearing,
+ const float pixelsToTileUnits) const;
+
+ std::unique_ptr<CollisionTile> collisionTile;
+ GridIndex<IndexedSubfeature> grid;
+ unsigned int sortIndex = 0;
+
+ std::unordered_map<std::string, std::vector<std::string>> bucketLayerIDs;
};
}
diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp
index 167a1d2714..91d4d6f738 100644
--- a/src/mbgl/source/source.cpp
+++ b/src/mbgl/source/source.cpp
@@ -346,7 +346,7 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
- const optional<std::vector<std::string>>& layerIDs) {
+ const optional<std::vector<std::string>>& layerIDs) const {
std::unordered_map<std::string, std::vector<Feature>> result;
@@ -356,7 +356,7 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
double maxY = -std::numeric_limits<double>::infinity();
double z = queryGeometry[0].z;
- for (auto& c : queryGeometry) {
+ for (const auto& c : queryGeometry) {
minX = util::min(minX, c.x);
minY = util::min(minY, c.y);
maxX = util::max(maxX, c.x);
@@ -365,8 +365,8 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
std::map<CanonicalTileID, TileQuery> tileQueries;
- for (auto& tilePtr : tiles) {
- auto& tile = tilePtr.second;
+ for (const auto& tilePtr : tiles) {
+ const auto& tile = tilePtr.second;
auto tileSpaceBoundsMin = coordinateToTilePoint(tile.id.canonical, { minX, minY, z });
auto tileSpaceBoundsMax = coordinateToTilePoint(tile.id.canonical, { maxX, maxY, z });
@@ -376,7 +376,7 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
GeometryCoordinates tileSpaceQueryGeometry;
- for (auto& c : queryGeometry) {
+ for (const auto& c : queryGeometry) {
tileSpaceQueryGeometry.push_back(coordinateToTilePoint(tile.id.canonical, c));
}
@@ -394,8 +394,7 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
}
}
-
- for (auto& it : tileQueries) {
+ for (const auto& it : tileQueries) {
auto& tileQuery = std::get<1>(it);
tileQuery.tileData.queryRenderedFeatures(result, tileQuery.queryGeometry, bearing, tileQuery.tileSize, tileQuery.scale, layerIDs);
}
diff --git a/src/mbgl/source/source.hpp b/src/mbgl/source/source.hpp
index 8fa61bbd3f..e751879297 100644
--- a/src/mbgl/source/source.hpp
+++ b/src/mbgl/source/source.hpp
@@ -85,7 +85,7 @@ public:
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
- const optional<std::vector<std::string>>& layerIDs);
+ const optional<std::vector<std::string>>& layerIDs) const;
void setCacheSize(size_t);
void onLowMemory();
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 1a6f3626a7..07147e4a4a 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -321,23 +321,20 @@ std::vector<Feature> Style::queryRenderedFeatures(
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
- const optional<std::vector<std::string>>& layerIDs) {
+ const optional<std::vector<std::string>>& layerIDs) const {
std::vector<std::unordered_map<std::string, std::vector<Feature>>> sourceResults;
for (const auto& source : sources) {
sourceResults.emplace_back(source->queryRenderedFeatures(queryGeometry, zoom, bearing, layerIDs));
}
std::vector<Feature> features;
- auto featuresInserter = std::back_inserter(features);
// Combine all results based on the style layer order.
- for (auto& layerPtr : layers) {
- auto& layerID = layerPtr->id;
- for (auto& sourceResult : sourceResults) {
- auto it = sourceResult.find(layerID);
+ for (const auto& layer : layers) {
+ for (const auto& sourceResult : sourceResults) {
+ auto it = sourceResult.find(layer->id);
if (it != sourceResult.end()) {
- auto& layerFeatures = it->second;
- std::move(layerFeatures.begin(), layerFeatures.end(), featuresInserter);
+ std::move(it->second.begin(), it->second.end(), std::back_inserter(features));
}
}
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 76da484cab..0c0b2293b7 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -113,7 +113,7 @@ public:
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
- const optional<std::vector<std::string>>& layerIDs);
+ const optional<std::vector<std::string>>& layerIDs) const;
float getQueryRadius() const;