diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-15 14:55:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-15 14:55:45 -0700 |
commit | a0b298211908036da269e7dcc2c78025476e2bf2 (patch) | |
tree | 3ef9df845e52290f8d6df918728c8eae92abd340 /src | |
parent | 199ea2a82a74cf2f7b63078e2dd4b8274c061851 (diff) | |
download | qtlocation-mapboxgl-a0b298211908036da269e7dcc2c78025476e2bf2.tar.gz |
[core] Prepare Filter and FilterEvaluator for extraction (#5366)
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/renderer/symbol_bucket.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/bucket_parameters.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/style/filter_evaluator.hpp | 163 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile_data.hpp | 7 |
4 files changed, 2 insertions, 177 deletions
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index e34aedb47e..496745dda1 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -119,9 +119,7 @@ void SymbolBucket::parseFeatures(const GeometryTileLayer& layer, const Filter& f const GLsizei featureCount = static_cast<GLsizei>(layer.featureCount()); for (GLsizei i = 0; i < featureCount; i++) { auto feature = layer.getFeature(i); - - FilterEvaluator evaluator(*feature); - if (!Filter::visit(filter, evaluator)) + if (!filter(feature->getType(), [&] (const auto& key) { return feature->getValue(key); })) continue; SymbolFeature ft; diff --git a/src/mbgl/style/bucket_parameters.cpp b/src/mbgl/style/bucket_parameters.cpp index 1a928dcecc..5bb08af873 100644 --- a/src/mbgl/style/bucket_parameters.cpp +++ b/src/mbgl/style/bucket_parameters.cpp @@ -10,11 +10,8 @@ void BucketParameters::eachFilteredFeature(const Filter& filter, auto name = layer.getName(); for (std::size_t i = 0; !cancelled() && i < layer.featureCount(); i++) { auto feature = layer.getFeature(i); - - FilterEvaluator evaluator(*feature); - if (!Filter::visit(filter, evaluator)) + if (!filter(feature->getType(), [&] (const auto& key) { return feature->getValue(key); })) continue; - function(*feature, i, name); } } diff --git a/src/mbgl/style/filter_evaluator.hpp b/src/mbgl/style/filter_evaluator.hpp deleted file mode 100644 index 9d5919ced1..0000000000 --- a/src/mbgl/style/filter_evaluator.hpp +++ /dev/null @@ -1,163 +0,0 @@ -#pragma once - -#include <mbgl/style/filter.hpp> -#include <mbgl/tile/geometry_tile_data.hpp> - -#include <type_traits> - -namespace mbgl { -namespace style { - -class FilterEvaluator { -public: - FilterEvaluator(const GeometryTileFeature& feature_) - : feature(feature_) {} - - bool operator()(const NullFilter&) const { - return true; - } - - bool operator()(const EqualsFilter& filter) const { - optional<Value> actual = getValue(filter.key); - return actual && equal(*actual, filter.value); - } - - bool operator()(const NotEqualsFilter& filter) const { - optional<Value> actual = getValue(filter.key); - return !actual || !equal(*actual, filter.value); - } - - bool operator()(const LessThanFilter& filter) const { - optional<Value> actual = getValue(filter.key); - return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ < rhs_; }); - } - - bool operator()(const LessThanEqualsFilter& filter) const { - optional<Value> actual = getValue(filter.key); - return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ <= rhs_; }); - } - - bool operator()(const GreaterThanFilter& filter) const { - optional<Value> actual = getValue(filter.key); - return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ > rhs_; }); - } - - bool operator()(const GreaterThanEqualsFilter& filter) const { - optional<Value> actual = getValue(filter.key); - return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ >= rhs_; }); - } - - bool operator()(const InFilter& filter) const { - optional<Value> actual = getValue(filter.key); - if (!actual) - return false; - for (const auto& v: filter.values) { - if (equal(*actual, v)) { - return true; - } - } - return false; - } - - bool operator()(const NotInFilter& filter) const { - optional<Value> actual = getValue(filter.key); - if (!actual) - return true; - for (const auto& v: filter.values) { - if (equal(*actual, v)) { - return false; - } - } - return true; - } - - bool operator()(const AnyFilter& filter) const { - for (const auto& f: filter.filters) { - if (Filter::visit(f, *this)) { - return true; - } - } - return false; - } - - bool operator()(const AllFilter& filter) const { - for (const auto& f: filter.filters) { - if (!Filter::visit(f, *this)) { - return false; - } - } - return true; - } - - bool operator()(const NoneFilter& filter) const { - for (const auto& f: filter.filters) { - if (Filter::visit(f, *this)) { - return false; - } - } - return true; - } - - bool operator()(const HasFilter& filter) const { - return bool(getValue(filter.key)); - } - - bool operator()(const NotHasFilter& filter) const { - return !getValue(filter.key); - } - -private: - optional<Value> getValue(const std::string& key) const { - return key == "$type" - ? optional<Value>(uint64_t(feature.getType())) - : feature.getValue(key); - } - - template <class Op> - struct Comparator { - const Op& op; - - template <class T> - bool operator()(const T& lhs, const T& rhs) const { - return op(lhs, rhs); - } - - template <class T0, class T1> - auto operator()(const T0& lhs, const T1& rhs) const - -> typename std::enable_if_t<std::is_arithmetic<T0>::value && !std::is_same<T0, bool>::value && - std::is_arithmetic<T1>::value && !std::is_same<T1, bool>::value, bool> { - return op(double(lhs), double(rhs)); - } - - template <class T0, class T1> - auto operator()(const T0&, const T1&) const - -> typename std::enable_if_t<!std::is_arithmetic<T0>::value || std::is_same<T0, bool>::value || - !std::is_arithmetic<T1>::value || std::is_same<T1, bool>::value, bool> { - return false; - } - - bool operator()(const std::vector<Value>&, - const std::vector<Value>&) const { - return false; - } - - bool operator()(const std::unordered_map<std::string, Value>&, - const std::unordered_map<std::string, Value>&) const { - return false; - } - }; - - template <class Op> - bool compare(const Value& lhs, const Value& rhs, const Op& op) const { - return Value::binary_visit(lhs, rhs, Comparator<Op> { op }); - } - - bool equal(const Value& lhs, const Value& rhs) const { - return compare(lhs, rhs, [] (const auto& lhs_, const auto& rhs_) { return lhs_ == rhs_; }); - } - - const GeometryTileFeature& feature; -}; - -} // namespace style -} // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile_data.hpp b/src/mbgl/tile/geometry_tile_data.hpp index 753ba6b8a2..1dc22e0c55 100644 --- a/src/mbgl/tile/geometry_tile_data.hpp +++ b/src/mbgl/tile/geometry_tile_data.hpp @@ -17,13 +17,6 @@ namespace mbgl { -enum class FeatureType : uint8_t { - Unknown = 0, - Point = 1, - LineString = 2, - Polygon = 3 -}; - class CanonicalTileID; // Normalized vector tile coordinates. |