From 4a5dc37245d23805d13865f5ef9c5f26e539a9ca Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Thu, 14 Jun 2018 14:35:39 -0700 Subject: [core] Implement CrossFadedDataDrivenProperty to add support for feature expressions in `*-pattern` properties --- .../renderer/possibly_evaluated_property_value.hpp | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/mbgl/renderer/possibly_evaluated_property_value.hpp') diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index f2d265f2f7..353df2ab90 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -57,6 +58,61 @@ public: bool useIntegerZoom; }; +template +class PossiblyEvaluatedPropertyValue> { +private: + using Value = variant< + Faded, + style::PropertyExpression>; + + Value value; + +public: + PossiblyEvaluatedPropertyValue() = default; + PossiblyEvaluatedPropertyValue(Value v, bool useIntegerZoom_ = false) + : value(std::move(v)), + useIntegerZoom(useIntegerZoom_) {} + + bool isConstant() const { + return value.template is>(); + } + + optional> constant() const { + return value.match( + [&] (const Faded& t) { return optional>(t); }, + [&] (const auto&) { return optional>(); }); + } + + Faded constantOr(const Faded& t) const { + return constant().value_or(t); + } + + template + auto match(Ts&&... ts) const { + return value.match(std::forward(ts)...); + } + + template + Faded evaluate(const Feature& feature, float zoom, T defaultValue) const { + return this->match( + [&] (const Faded& constant_) { return constant_; }, + [&] (const style::PropertyExpression& expression) { + if (!expression.isZoomConstant()) { + const T min = expression.evaluate(floor(zoom), feature, defaultValue); + const T max = expression.evaluate(floor(zoom) + 1, feature, defaultValue); + return Faded {min, max}; + } else { + const T evaluated = expression.evaluate(feature, defaultValue); + return Faded {evaluated, evaluated}; + } + } + ); + } + + bool useIntegerZoom; +}; + + namespace util { template -- cgit v1.2.1