diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-30 15:56:35 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-31 13:26:27 -0700 |
commit | d7a55a4be1300d79da0c63aefdf5d48d0c45a404 (patch) | |
tree | e50f42cdf87fa59c0f71d15892652c0e3424703a /src/mbgl/style | |
parent | 939526bac4aff734be4e6382b64c43214eb0bc9b (diff) | |
download | qtlocation-mapboxgl-d7a55a4be1300d79da0c63aefdf5d48d0c45a404.tar.gz |
[core] Introduce a fully-evaluated tuple type for layout properties
Diffstat (limited to 'src/mbgl/style')
-rw-r--r-- | src/mbgl/style/layers/symbol_layer_impl.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer_impl.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/layout_property.hpp | 66 |
3 files changed, 58 insertions, 16 deletions
diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index ff59b14d65..e4557c953f 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -68,7 +68,7 @@ TextPaintProperties::Evaluated SymbolLayer::Impl::textPaintProperties() const { } -SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { +SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated& layout_) const { return SymbolPropertyValues { layout_.get<IconRotationAlignment>(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment layout_.get<IconRotationAlignment>(), @@ -83,7 +83,7 @@ SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutPro }; } -SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { +SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated& layout_) const { return SymbolPropertyValues { layout_.get<TextPitchAlignment>(), layout_.get<TextRotationAlignment>(), diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index 1e9f05e4c7..0c4b74e833 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -72,8 +72,8 @@ public: IconPaintProperties::Evaluated iconPaintProperties() const; TextPaintProperties::Evaluated textPaintProperties() const; - SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::Evaluated&) const; - SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::Evaluated&) const; + SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated&) const; + SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated&) const; SymbolLayoutProperties layout; SymbolPaintProperties paint; 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)... }; } |