summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mbgl/geometry/feature_index.cpp50
-rw-r--r--src/mbgl/text/collision_tile.cpp6
-rw-r--r--src/mbgl/text/collision_tile.hpp2
-rw-r--r--src/mbgl/util/grid_index.cpp26
-rw-r--r--src/mbgl/util/grid_index.hpp20
5 files changed, 34 insertions, 70 deletions
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp
index 164431199e..fff2fbd075 100644
--- a/src/mbgl/geometry/feature_index.cpp
+++ b/src/mbgl/geometry/feature_index.cpp
@@ -7,6 +7,8 @@
#include <mbgl/util/math.hpp>
#include <mbgl/math/minmax.hpp>
+#include <mapbox/geometry/envelope.hpp>
+
#include <cassert>
#include <string>
@@ -21,23 +23,8 @@ void FeatureIndex::insert(const GeometryCollection& geometries,
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 (const auto& p : ring) {
- const float x = p.x;
- const float y = p.y;
- minX = util::min(minX, x);
- minY = util::min(minY, y);
- maxX = util::max(maxX, x);
- maxY = util::max(maxY, y);
- }
-
- grid.insert(
- IndexedSubfeature { index, sourceLayerName, bucketName, sortIndex++ },
- { int32_t(minX), int32_t(minY), int32_t(maxX), int32_t(maxY) });
+ grid.insert(IndexedSubfeature { index, sourceLayerName, bucketName, sortIndex++ },
+ mapbox::geometry::envelope<GeometryCoordinates, int16_t>(ring));
}
}
@@ -72,30 +59,11 @@ void FeatureIndex::query(
const GeometryTile& geometryTile,
const Style& style) const {
- const float pixelsToTileUnits = util::EXTENT / tileSize / scale;
-
- float additionalRadius = style.getQueryRadius() * pixelsToTileUnits;
+ mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope<GeometryCollection, int16_t>(queryGeometry);
- 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 (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);
- maxY = util::max<float>(maxY, p.y);
- }
- }
-
- std::vector<IndexedSubfeature> features = grid.query({
- int(minX - additionalRadius),
- int(minY - additionalRadius),
- int(maxX + additionalRadius),
- int(maxY + additionalRadius)
- });
+ const float pixelsToTileUnits = util::EXTENT / tileSize / scale;
+ const int16_t additionalRadius = std::min<int16_t>(util::EXTENT, std::ceil(style.getQueryRadius() * pixelsToTileUnits));
+ std::vector<IndexedSubfeature> features = grid.query({ box.min - additionalRadius, box.max + additionalRadius });
std::sort(features.begin(), features.end(), topDown);
size_t previousSortIndex = std::numeric_limits<size_t>::max();
@@ -110,7 +78,7 @@ void FeatureIndex::query(
// query symbol features
assert(collisionTile);
- std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(minX, minY, maxX, maxY, scale);
+ std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(box, scale);
std::sort(symbolFeatures.begin(), symbolFeatures.end(), topDownSymbols);
for (const auto& symbolFeature : symbolFeatures) {
addFeature(result, symbolFeature, queryGeometry, filterLayerIDs, geometryTile, style, bearing, pixelsToTileUnits);
diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp
index a7741d259a..e7824cde3c 100644
--- a/src/mbgl/text/collision_tile.cpp
+++ b/src/mbgl/text/collision_tile.cpp
@@ -153,13 +153,13 @@ Box CollisionTile::getTreeBox(const Point<float>& anchor, const CollisionBox& bo
};
}
-std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float minX, const float minY, const float maxX, const float maxY, const float scale) {
+std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const mapbox::geometry::box<int16_t>& box, const float scale) {
std::vector<IndexedSubfeature> result;
std::unordered_map<std::string, std::set<std::size_t>> sourceLayerFeatures;
- auto anchor = util::matrixMultiply(rotationMatrix, Point<float>(minX, minY));
- CollisionBox queryBox(anchor, 0, 0, maxX - minX, maxY - minY, scale);
+ auto anchor = util::matrixMultiply(rotationMatrix, convertPoint<float>(box.min));
+ CollisionBox queryBox(anchor, 0, 0, box.max.x - box.min.x, box.max.y - box.min.y, scale);
auto predicates = bgi::intersects(getTreeBox(anchor, queryBox));
auto fn = [&] (const Tree& tree_) {
diff --git a/src/mbgl/text/collision_tile.hpp b/src/mbgl/text/collision_tile.hpp
index 61d5af3134..0be2dabdbf 100644
--- a/src/mbgl/text/collision_tile.hpp
+++ b/src/mbgl/text/collision_tile.hpp
@@ -42,7 +42,7 @@ public:
float placeFeature(const CollisionFeature&, const bool allowOverlap, const bool avoidEdges);
void insertFeature(CollisionFeature&, const float minPlacementScale, const bool ignorePlacement);
- std::vector<IndexedSubfeature> queryRenderedSymbols(const float minX, const float minY, const float maxX, const float maxY, const float scale);
+ std::vector<IndexedSubfeature> queryRenderedSymbols(const mapbox::geometry::box<int16_t>&, const float scale);
const PlacementConfig config;
diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp
index 8a2ee90213..4877a90e72 100644
--- a/src/mbgl/util/grid_index.cpp
+++ b/src/mbgl/util/grid_index.cpp
@@ -20,13 +20,13 @@ GridIndex<T>::GridIndex(int32_t extent_, int32_t n_, int32_t padding_) :
};
template <class T>
-void GridIndex<T>::insert(T&& t, BBox&& bbox) {
+void GridIndex<T>::insert(T&& t, const BBox& bbox) {
size_t uid = elements.size();
- auto cx1 = convertToCellCoord(bbox.x1);
- auto cy1 = convertToCellCoord(bbox.y1);
- auto cx2 = convertToCellCoord(bbox.x2);
- auto cy2 = convertToCellCoord(bbox.y2);
+ auto cx1 = convertToCellCoord(bbox.min.x);
+ auto cy1 = convertToCellCoord(bbox.min.y);
+ 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++) {
@@ -43,10 +43,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const {
std::vector<T> result;
std::unordered_set<size_t> seenUids;
- auto cx1 = convertToCellCoord(queryBBox.x1);
- auto cy1 = convertToCellCoord(queryBBox.y1);
- auto cx2 = convertToCellCoord(queryBBox.x2);
- auto cy2 = convertToCellCoord(queryBBox.y2);
+ auto cx1 = convertToCellCoord(queryBBox.min.x);
+ auto cy1 = convertToCellCoord(queryBBox.min.y);
+ 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++) {
@@ -57,10 +57,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const {
auto& pair = elements.at(uid);
auto& bbox = pair.second;
- if (queryBBox.x1 <= bbox.x2 &&
- queryBBox.y1 <= bbox.y2 &&
- queryBBox.x2 >= bbox.x1 &&
- queryBBox.y2 >= bbox.y1) {
+ if (queryBBox.min.x <= bbox.max.x &&
+ queryBBox.min.y <= bbox.max.y &&
+ queryBBox.max.x >= bbox.min.x &&
+ queryBBox.max.y >= bbox.min.y) {
result.push_back(pair.first);
}
diff --git a/src/mbgl/util/grid_index.hpp b/src/mbgl/util/grid_index.hpp
index c886e7ff48..656a4bdbd8 100644
--- a/src/mbgl/util/grid_index.hpp
+++ b/src/mbgl/util/grid_index.hpp
@@ -1,5 +1,8 @@
#pragma once
+#include <mapbox/geometry/point.hpp>
+#include <mapbox/geometry/box.hpp>
+
#include <cstdint>
#include <cstddef>
#include <vector>
@@ -8,22 +11,15 @@ namespace mbgl {
template <class T>
class GridIndex {
- public:
-
+public:
GridIndex(int32_t extent_, int32_t n_, int32_t padding_);
- struct BBox {
- int32_t x1;
- int32_t y1;
- int32_t x2;
- int32_t y2;
- };
-
- void insert(T&& t, BBox&& bbox);
- std::vector<T> query(const BBox& bbox) const;
+ using BBox = mapbox::geometry::box<int16_t>;
- private:
+ void insert(T&& t, const BBox&);
+ std::vector<T> query(const BBox&) const;
+private:
int32_t convertToCellCoord(int32_t x) const;
const int32_t extent;