summaryrefslogtreecommitdiff
path: root/src/mbgl/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util')
-rw-r--r--src/mbgl/util/grid_index.cpp24
-rw-r--r--src/mbgl/util/grid_index.hpp5
2 files changed, 19 insertions, 10 deletions
diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp
index afd469501d..f6b59b1bac 100644
--- a/src/mbgl/util/grid_index.cpp
+++ b/src/mbgl/util/grid_index.cpp
@@ -82,21 +82,29 @@ std::vector<std::pair<T, typename GridIndex<T>::BBox>> GridIndex<T>::queryWithBo
}
template <class T>
-bool GridIndex<T>::hitTest(const BBox& queryBBox) const {
+bool GridIndex<T>::hitTest(const BBox& queryBBox, optional<std::function<bool(const T&)>> predicate) const {
bool hit = false;
- query(queryBBox, [&](const T&, const BBox&) -> bool {
- hit = true;
- return true;
+ query(queryBBox, [&](const T& t, const BBox&) -> bool {
+ if (!predicate || (*predicate)(t)) {
+ hit = true;
+ return true;
+ } else {
+ return false;
+ }
});
return hit;
}
template <class T>
-bool GridIndex<T>::hitTest(const BCircle& queryBCircle) const {
+bool GridIndex<T>::hitTest(const BCircle& queryBCircle, optional<std::function<bool(const T&)>> predicate) const {
bool hit = false;
- query(queryBCircle, [&](const T&, const BBox&) -> bool {
- hit = true;
- return true;
+ query(queryBCircle, [&](const T& t, const BBox&) -> bool {
+ if (!predicate || (*predicate)(t)) {
+ hit = true;
+ return true;
+ } else {
+ return false;
+ }
});
return hit;
}
diff --git a/src/mbgl/util/grid_index.hpp b/src/mbgl/util/grid_index.hpp
index 6ef2966bee..4c2d7dccc8 100644
--- a/src/mbgl/util/grid_index.hpp
+++ b/src/mbgl/util/grid_index.hpp
@@ -2,6 +2,7 @@
#include <mapbox/geometry/point.hpp>
#include <mapbox/geometry/box.hpp>
+#include <mbgl/util/optional.hpp>
#include <cstdint>
#include <cstddef>
@@ -67,8 +68,8 @@ public:
std::vector<T> query(const BBox&) const;
std::vector<std::pair<T,BBox>> queryWithBoxes(const BBox&) const;
- bool hitTest(const BBox&) const;
- bool hitTest(const BCircle&) const;
+ bool hitTest(const BBox&, optional<std::function<bool(const T&)>> predicate = nullopt) const;
+ bool hitTest(const BCircle&, optional<std::function<bool(const T&)>> predicate = nullopt) const;
bool empty() const;