[core] Fix code style issues
This commit is contained in:
@@ -165,7 +165,7 @@ public:
|
||||
void removeCustomLayer(const std::string& id);
|
||||
|
||||
// Feature queries
|
||||
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const optional<std::vector<std::string>>& layerIDs = {});
|
||||
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const optional<std::vector<std::string>>& layerIDs = {});
|
||||
std::vector<Feature> queryRenderedFeatures(const std::array<ScreenCoordinate, 2>&, const optional<std::vector<std::string>>& layerIDs = {});
|
||||
|
||||
// Memory
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
public:
|
||||
FeatureIndex();
|
||||
|
||||
void insert(const GeometryCollection&, std::size_t index, const std::string& sourceLayerName, const std::string& bucketName);
|
||||
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;
|
||||
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);
|
||||
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 addBucketLayerName(const std::string& bucketName, const std::string& layerName);
|
||||
|
||||
void setCollisionTile(std::unique_ptr<CollisionTile>);
|
||||
void setCollisionTile(std::unique_ptr<CollisionTile>);
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
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;
|
||||
std::unique_ptr<CollisionTile> collisionTile;
|
||||
GridIndex<IndexedSubfeature> grid;
|
||||
unsigned int sortIndex = 0;
|
||||
|
||||
std::unordered_map<std::string, std::vector<std::string>> bucketLayerIDs;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user