summaryrefslogtreecommitdiff
path: root/include/mbgl/style/function/composite_function.hpp
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-01-31 15:44:18 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-02 09:44:42 -0800
commit8a5bff8ee630673c6ebc496322eab94a41ae9353 (patch)
tree8bb6428cd9c3d591c237d77f94d4b0e56efb0ee0 /include/mbgl/style/function/composite_function.hpp
parent141e995806576364d185626176c1b993fc519291 (diff)
downloadqtlocation-mapboxgl-8a5bff8ee630673c6ebc496322eab94a41ae9353.tar.gz
[core] default value support in categorical function conversion
Diffstat (limited to 'include/mbgl/style/function/composite_function.hpp')
-rw-r--r--include/mbgl/style/function/composite_function.hpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp
index 169a455435..f42a5f06f4 100644
--- a/include/mbgl/style/function/composite_function.hpp
+++ b/include/mbgl/style/function/composite_function.hpp
@@ -43,9 +43,10 @@ public:
std::map<float, IntervalStops<T>>,
std::map<float, CategoricalStops<T>>>>;
- CompositeFunction(std::string property_, Stops stops_)
+ CompositeFunction(std::string property_, Stops stops_, optional<T> defaultValue_ = {})
: property(std::move(property_)),
- stops(std::move(stops_)) {
+ stops(std::move(stops_)),
+ defaultValue(std::move(defaultValue_)) {
}
std::tuple<Range<float>, Range<InnerStops>>
@@ -73,13 +74,17 @@ public:
}
Range<T> evaluate(Range<InnerStops> coveringStops,
- const GeometryTileFeature& feature) const {
+ const GeometryTileFeature& feature,
+ T finalDefaultValue) const {
optional<Value> v = feature.getValue(property);
if (!v) {
- return { T(), T() };
+ return {
+ defaultValue.value_or(finalDefaultValue),
+ defaultValue.value_or(finalDefaultValue)
+ };
}
auto eval = [&] (const auto& s) {
- return s.evaluate(*v);
+ return s.evaluate(*v).value_or(defaultValue.value_or(finalDefaultValue));
};
return Range<T> {
coveringStops.min.match(eval),
@@ -87,9 +92,9 @@ public:
};
}
- T evaluate(float zoom, const GeometryTileFeature& feature) const {
+ T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const {
std::tuple<Range<float>, Range<InnerStops>> ranges = coveringRanges(zoom);
- Range<T> resultRange = evaluate(std::get<1>(ranges), feature);
+ Range<T> resultRange = evaluate(std::get<1>(ranges), feature, finalDefaultValue);
return util::interpolate(
resultRange.min,
resultRange.max,
@@ -98,11 +103,13 @@ public:
friend bool operator==(const CompositeFunction& lhs,
const CompositeFunction& rhs) {
- return lhs.property == rhs.property && lhs.stops == rhs.stops;
+ return std::tie(lhs.property, lhs.stops, lhs.defaultValue)
+ == std::tie(rhs.property, rhs.stops, rhs.defaultValue);
}
std::string property;
Stops stops;
+ optional<T> defaultValue;
};
} // namespace style