diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-06-30 13:55:14 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-07-26 16:35:29 +0300 |
commit | 427773d31a5b1ad156b923aaf44ea9d2015f5be9 (patch) | |
tree | 83a4b1ab178cc92a63e9a4461923c8c822e90a5c /src | |
parent | 4e61b2e506f31682d67708832d409d38a7cb6ac0 (diff) | |
download | qtlocation-mapboxgl-427773d31a5b1ad156b923aaf44ea9d2015f5be9.tar.gz |
[core] Micro-optimizations in geometry code
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/style/source_impl.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/util/grid_index.cpp | 17 |
3 files changed, 23 insertions, 10 deletions
diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 4223f2b50d..95363ca699 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -207,6 +207,11 @@ static Point<int16_t> coordinateToTilePoint(const UnwrappedTileID& tileID, const } std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRenderedFeatures(const QueryParameters& parameters) const { + std::unordered_map<std::string, std::vector<Feature>> result; + if (renderTiles.empty()) { + return result; + } + LineString<double> queryGeometry; for (const auto& p : parameters.geometry) { @@ -214,9 +219,11 @@ std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRendere parameters.transformState, 0, { p.x, parameters.transformState.getHeight() - p.y }).p); } - mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry); + if (queryGeometry.empty()) { + return result; + } - std::unordered_map<std::string, std::vector<Feature>> result; + mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry); for (const auto& tilePtr : renderTiles) { const RenderTile& tile = tilePtr.second; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 9073894cc2..aae0e38d51 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -337,6 +337,7 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions) const { } std::vector<Feature> Style::queryRenderedFeatures(const QueryParameters& parameters) const { + std::vector<Feature> result; std::unordered_map<std::string, std::vector<Feature>> resultsByLayer; for (const auto& source : sources) { @@ -344,7 +345,9 @@ std::vector<Feature> Style::queryRenderedFeatures(const QueryParameters& paramet std::move(sourceResults.begin(), sourceResults.end(), std::inserter(resultsByLayer, resultsByLayer.begin())); } - std::vector<Feature> result; + if (resultsByLayer.empty()) { + return result; + } // Combine all results based on the style layer order. for (const auto& layer : layers) { diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp index cf1fcd68c9..b3afd3fdc8 100644 --- a/src/mbgl/util/grid_index.cpp +++ b/src/mbgl/util/grid_index.cpp @@ -1,5 +1,6 @@ #include <mbgl/util/grid_index.hpp> #include <mbgl/geometry/feature_index.hpp> +#include <mbgl/math/minmax.hpp> #include <unordered_set> @@ -28,9 +29,10 @@ void GridIndex<T>::insert(T&& t, const BBox& bbox) { auto cx2 = convertToCellCoord(bbox.max.x); auto cy2 = convertToCellCoord(bbox.max.y); - for (int32_t x = cx1; x <= cx2; x++) { - for (int32_t y = cy1; y <= cy2; y++) { - auto cellIndex = d * y + x; + int32_t x, y, cellIndex; + for (x = cx1; x <= cx2; ++x) { + for (y = cy1; y <= cy2; ++y) { + cellIndex = d * y + x; cells[cellIndex].push_back(uid); } } @@ -48,9 +50,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const { auto cx2 = convertToCellCoord(queryBBox.max.x); auto cy2 = convertToCellCoord(queryBBox.max.y); - for (int32_t x = cx1; x <= cx2; x++) { - for (int32_t y = cy1; y <= cy2; y++) { - auto cellIndex = d * y + x; + int32_t x, y, cellIndex; + for (x = cx1; x <= cx2; ++x) { + for (y = cy1; y <= cy2; ++y) { + cellIndex = d * y + x; for (auto uid : cells[cellIndex]) { if (seenUids.count(uid) == 0) { seenUids.insert(uid); @@ -75,7 +78,7 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const { template <class T> int32_t GridIndex<T>::convertToCellCoord(int32_t x) const { - return std::max(0.0, std::min(d - 1.0, std::floor(x * scale) + padding)); + return util::max(0.0, util::min(d - 1.0, std::floor(x * scale) + padding)); } template class GridIndex<IndexedSubfeature>; |