summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/possibly_evaluated_property_value.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-27 14:33:00 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-03 08:30:17 -0700
commitd5f4d0f05fcb8490984649d78d6c026f87a77f4e (patch)
treedea3b08a7c1d6f29a0f75d37cb2ee54a2429e6b4 /src/mbgl/renderer/possibly_evaluated_property_value.hpp
parent6c7730ee7c2d9e63df526965bb511b2f43ee82b7 (diff)
downloadqtlocation-mapboxgl-d5f4d0f05fcb8490984649d78d6c026f87a77f4e.tar.gz
[core] Move render-related sources out of style directory/namespace
Moves the following to the renderer directory and out of the style namespace: * CascadeParameters * PropertyEvaluationParameters * UpdateParameters * PropertyEvaluator * DataDrivenPropertyEvaluator * CrossFadedPropertyEvaluator * PaintPropertyBinder * PaintProperyStatistics * PossiblyEvaluatedPropertyValue * TransitioningLight * EvaluatedLight
Diffstat (limited to 'src/mbgl/renderer/possibly_evaluated_property_value.hpp')
-rw-r--r--src/mbgl/renderer/possibly_evaluated_property_value.hpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp
new file mode 100644
index 0000000000..a0bcec2bf1
--- /dev/null
+++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp
@@ -0,0 +1,74 @@
+#pragma once
+
+#include <mbgl/style/function/source_function.hpp>
+#include <mbgl/style/function/composite_function.hpp>
+#include <mbgl/util/interpolate.hpp>
+#include <mbgl/util/variant.hpp>
+
+namespace mbgl {
+
+template <class T>
+class PossiblyEvaluatedPropertyValue {
+private:
+ using Value = variant<
+ T,
+ style::SourceFunction<T>,
+ style::CompositeFunction<T>>;
+
+ Value value;
+
+public:
+ PossiblyEvaluatedPropertyValue() = default;
+ PossiblyEvaluatedPropertyValue(Value v) : value(std::move(v)) {}
+
+ bool isConstant() const {
+ return value.template is<T>();
+ }
+
+ optional<T> constant() const {
+ return value.match(
+ [&] (const T& t) { return optional<T>(t); },
+ [&] (const auto&) { return optional<T>(); });
+ }
+
+ T constantOr(const 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>
+ T evaluate(const Feature& feature, float zoom, T defaultValue) const {
+ return this->match(
+ [&] (const T& constant) { return constant; },
+ [&] (const style::SourceFunction<T>& function) {
+ return function.evaluate(feature, defaultValue);
+ },
+ [&] (const style::CompositeFunction<T>& function) {
+ return function.evaluate(zoom, feature, defaultValue);
+ }
+ );
+ }
+};
+
+namespace util {
+
+template <typename T>
+struct Interpolator<PossiblyEvaluatedPropertyValue<T>> {
+ PossiblyEvaluatedPropertyValue<T> operator()(const PossiblyEvaluatedPropertyValue<T>& a,
+ const PossiblyEvaluatedPropertyValue<T>& b,
+ const double t) const {
+ if (a.isConstant() && b.isConstant()) {
+ return { interpolate(*a.constant(), *b.constant(), t) };
+ } else {
+ return { a };
+ }
+ }
+};
+
+} // namespace util
+
+} // namespace mbgl