summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layout_property.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-30 15:56:35 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-31 13:26:27 -0700
commitd7a55a4be1300d79da0c63aefdf5d48d0c45a404 (patch)
treee50f42cdf87fa59c0f71d15892652c0e3424703a /src/mbgl/style/layout_property.hpp
parent939526bac4aff734be4e6382b64c43214eb0bc9b (diff)
downloadqtlocation-mapboxgl-d7a55a4be1300d79da0c63aefdf5d48d0c45a404.tar.gz
[core] Introduce a fully-evaluated tuple type for layout properties
Diffstat (limited to 'src/mbgl/style/layout_property.hpp')
-rw-r--r--src/mbgl/style/layout_property.hpp66
1 files changed, 54 insertions, 12 deletions
diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp
index 25cff4b92d..624ff2bdc5 100644
--- a/src/mbgl/style/layout_property.hpp
+++ b/src/mbgl/style/layout_property.hpp
@@ -16,7 +16,7 @@ class LayoutProperty {
public:
using UnevaluatedType = PropertyValue<T>;
using EvaluatorType = PropertyEvaluator<T>;
- using EvaluatedType = T;
+ using PossiblyEvaluatedType = T;
using Type = T;
};
@@ -25,7 +25,7 @@ class DataDrivenLayoutProperty {
public:
using UnevaluatedType = DataDrivenPropertyValue<T>;
using EvaluatorType = DataDrivenPropertyEvaluator<T>;
- using EvaluatedType = PossiblyEvaluatedPropertyValue<T>;
+ using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<T>;
using Type = T;
};
@@ -33,23 +33,65 @@ template <class... Ps>
class LayoutProperties {
public:
using Properties = TypeList<Ps...>;
- using EvaluatedTypes = TypeList<typename Ps::EvaluatedType...>;
- using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
template <class TypeList>
using Tuple = IndexedTuple<Properties, TypeList>;
+ /*
+ For layout properties we implement a two step evaluation process: if you have a zoom level,
+ you can evaluate a set of unevaluated property values, producing a set of possibly evaluated
+ values, where non-data-driven property values have been fully evaluated, and data-driven values
+ have not.
+
+ Once you also have a particular feature, you can evaluate that set of possibly evaluated values
+ fully, producing a set of fully evaluated values.
+
+ This is in theory maximally efficient in terms of avoiding repeated evaluation of camera
+ functions, though it's more of a historical accident that a purposeful optimization.
+ */
+
+ using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
+ using PossiblyEvaluatedTypes = TypeList<typename Ps::PossiblyEvaluatedType...>;
+ using EvaluatedTypes = TypeList<typename Ps::Type...>;
+
class Evaluated : public Tuple<EvaluatedTypes> {
public:
using Tuple<EvaluatedTypes>::Tuple;
+ };
+
+ class PossiblyEvaluated : public Tuple<PossiblyEvaluatedTypes> {
+ public:
+ using Tuple<PossiblyEvaluatedTypes>::Tuple;
+
+ template <class T>
+ static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) {
+ return t;
+ }
+
+ template <class T>
+ static T evaluate(float z, const GeometryTileFeature& feature,
+ const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) {
+ return v.match(
+ [&] (const T& t) {
+ return t;
+ },
+ [&] (const SourceFunction<T>& t) {
+ return t.evaluate(feature, defaultValue);
+ },
+ [&] (const CompositeFunction<T>& t) {
+ return t.evaluate(z, feature, defaultValue);
+ });
+ }
template <class P>
- typename P::Type evaluate(float z, const GeometryTileFeature& feature) const {
- using T = typename P::Type;
- return this->template get<P>().match(
- [&] (const T& t) { return t; },
- [&] (const SourceFunction<T>& t) { return t.evaluate(feature, P::defaultValue()); },
- [&] (const CompositeFunction<T>& t) { return t.evaluate(z, feature, P::defaultValue()); });
+ auto evaluate(float z, const GeometryTileFeature& feature) const {
+ return evaluate(z, feature, this->template get<P>(), P::defaultValue());
+ }
+
+ Evaluated evaluate(float z, const GeometryTileFeature& feature) const {
+ return Evaluated {
+ evaluate<Ps>(z, feature)...
+ };
}
};
@@ -65,8 +107,8 @@ public:
.evaluate(Evaluator(parameters, P::defaultValue()));
}
- Evaluated evaluate(const PropertyEvaluationParameters& parameters) const {
- return Evaluated {
+ PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const {
+ return PossiblyEvaluated {
evaluate<Ps>(parameters)...
};
}