summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/possibly_evaluated_property_value.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/possibly_evaluated_property_value.hpp')
-rw-r--r--src/mbgl/renderer/possibly_evaluated_property_value.hpp56
1 files changed, 56 insertions, 0 deletions
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 <mbgl/style/property_expression.hpp>
+#include <mbgl/renderer/cross_faded_property_evaluator.hpp>
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/variant.hpp>
@@ -57,6 +58,61 @@ public:
bool useIntegerZoom;
};
+template <class T>
+class PossiblyEvaluatedPropertyValue<Faded<T>> {
+private:
+ using Value = variant<
+ Faded<T>,
+ style::PropertyExpression<T>>;
+
+ Value value;
+
+public:
+ PossiblyEvaluatedPropertyValue() = default;
+ PossiblyEvaluatedPropertyValue(Value v, bool useIntegerZoom_ = false)
+ : value(std::move(v)),
+ useIntegerZoom(useIntegerZoom_) {}
+
+ bool isConstant() const {
+ return value.template is<Faded<T>>();
+ }
+
+ optional<Faded<T>> constant() const {
+ return value.match(
+ [&] (const Faded<T>& t) { return optional<Faded<T>>(t); },
+ [&] (const auto&) { return optional<Faded<T>>(); });
+ }
+
+ Faded<T> constantOr(const Faded<T>& t) const {
+ return constant().value_or(t);
+ }
+
+ template <class... Ts>
+ auto match(Ts&&... ts) const {
+ return value.match(std::forward<Ts>(ts)...);
+ }
+
+ template <class Feature>
+ Faded<T> evaluate(const Feature& feature, float zoom, T defaultValue) const {
+ return this->match(
+ [&] (const Faded<T>& constant_) { return constant_; },
+ [&] (const style::PropertyExpression<T>& 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<T> {min, max};
+ } else {
+ const T evaluated = expression.evaluate(feature, defaultValue);
+ return Faded<T> {evaluated, evaluated};
+ }
+ }
+ );
+ }
+
+ bool useIntegerZoom;
+};
+
+
namespace util {
template <typename T>