[core] Prepare Filter and FilterEvaluator for extraction (#5366)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user