diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-13 18:14:12 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-20 11:56:30 -0700 |
commit | c8edbb0500cbf4baf1d5fdb0e63679539e166585 (patch) | |
tree | 750f3b72b9e3b1c91ddbc0541cfc64d7d80ffe71 /src/mbgl/renderer | |
parent | 6d7072162b764c2432c010cd463a5a2c0093d606 (diff) | |
download | qtlocation-mapboxgl-c8edbb0500cbf4baf1d5fdb0e63679539e166585.tar.gz |
[core] Replace {Source,Camera,Composite}Function with PropertyExpression
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r-- | src/mbgl/renderer/cross_faded_property_evaluator.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/renderer/cross_faded_property_evaluator.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/data_driven_property_evaluator.hpp | 19 | ||||
-rw-r--r-- | src/mbgl/renderer/paint_property_binder.hpp | 33 | ||||
-rw-r--r-- | src/mbgl/renderer/possibly_evaluated_property_value.hpp | 23 | ||||
-rw-r--r-- | src/mbgl/renderer/property_evaluator.hpp | 2 |
6 files changed, 40 insertions, 47 deletions
diff --git a/src/mbgl/renderer/cross_faded_property_evaluator.cpp b/src/mbgl/renderer/cross_faded_property_evaluator.cpp index 4dff9dbf12..9a7af8636c 100644 --- a/src/mbgl/renderer/cross_faded_property_evaluator.cpp +++ b/src/mbgl/renderer/cross_faded_property_evaluator.cpp @@ -16,10 +16,10 @@ Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const T& constant) const { } template <typename T> -Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const style::CameraFunction<T>& function) const { - return calculate(function.evaluate(parameters.z - 1.0f), - function.evaluate(parameters.z), - function.evaluate(parameters.z + 1.0f)); +Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const style::PropertyExpression<T>& expression) const { + return calculate(expression.evaluate(parameters.z - 1.0f), + expression.evaluate(parameters.z), + expression.evaluate(parameters.z + 1.0f)); } template <typename T> diff --git a/src/mbgl/renderer/cross_faded_property_evaluator.hpp b/src/mbgl/renderer/cross_faded_property_evaluator.hpp index 40ecba5d93..1d17c5eb2f 100644 --- a/src/mbgl/renderer/cross_faded_property_evaluator.hpp +++ b/src/mbgl/renderer/cross_faded_property_evaluator.hpp @@ -27,7 +27,7 @@ public: Faded<T> operator()(const style::Undefined&) const; Faded<T> operator()(const T& constant) const; - Faded<T> operator()(const style::CameraFunction<T>&) const; + Faded<T> operator()(const style::PropertyExpression<T>&) const; private: Faded<T> calculate(const T& min, const T& mid, const T& max) const; diff --git a/src/mbgl/renderer/data_driven_property_evaluator.hpp b/src/mbgl/renderer/data_driven_property_evaluator.hpp index 79ecd0d495..f9452cc572 100644 --- a/src/mbgl/renderer/data_driven_property_evaluator.hpp +++ b/src/mbgl/renderer/data_driven_property_evaluator.hpp @@ -23,21 +23,18 @@ public: return ResultType(constant); } - ResultType operator()(const style::CameraFunction<T>& function) const { - if (!parameters.useIntegerZoom) { - return ResultType(function.evaluate(parameters.z)); + ResultType operator()(const style::PropertyExpression<T>& expression) const { + if (!expression.isFeatureConstant()) { + auto returnExpression = expression; + returnExpression.useIntegerZoom = parameters.useIntegerZoom; + return ResultType(returnExpression); + } else if (!parameters.useIntegerZoom) { + return ResultType(expression.evaluate(parameters.z)); } else { - return ResultType(function.evaluate(floor(parameters.z))); + return ResultType(expression.evaluate(floor(parameters.z))); } } - template <class Function> - ResultType operator()(const Function& function) const { - auto returnFunction = function; - returnFunction.useIntegerZoom = parameters.useIntegerZoom; - return ResultType(returnFunction); - } - private: const PropertyEvaluationParameters& parameters; T defaultValue; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 3a49882f12..aade672ae7 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -130,13 +130,13 @@ public: using Attribute = ZoomInterpolatedAttributeType<A>; using AttributeBinding = typename Attribute::Binding; - SourceFunctionPaintPropertyBinder(style::SourceFunction<T> function_, T defaultValue_) - : function(std::move(function_)), + SourceFunctionPaintPropertyBinder(style::PropertyExpression<T> expression_, T defaultValue_) + : expression(std::move(expression_)), defaultValue(std::move(defaultValue_)) { } void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) override { - auto evaluated = function.evaluate(feature, defaultValue); + auto evaluated = expression.evaluate(feature, defaultValue); this->statistics.add(evaluated); auto value = attributeValue(evaluated); for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) { @@ -170,7 +170,7 @@ public: } private: - style::SourceFunction<T> function; + style::PropertyExpression<T> expression; T defaultValue; gl::VertexVector<BaseVertex> vertexVector; optional<gl::VertexBuffer<BaseVertex>> vertexBuffer; @@ -187,14 +187,14 @@ public: using AttributeBinding = typename Attribute::Binding; using Vertex = gl::detail::Vertex<Attribute>; - CompositeFunctionPaintPropertyBinder(style::CompositeFunction<T> function_, float zoom, T defaultValue_) - : function(std::move(function_)), + CompositeFunctionPaintPropertyBinder(style::PropertyExpression<T> expression_, float zoom, T defaultValue_) + : expression(std::move(expression_)), defaultValue(std::move(defaultValue_)), zoomRange({zoom, zoom + 1}) { } void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) override { - Range<T> range = function.evaluate(zoomRange, feature, defaultValue); + Range<T> range = expression.evaluate(zoomRange, feature, defaultValue); this->statistics.add(range.min); this->statistics.add(range.max); AttributeValue value = zoomInterpolatedAttributeValue( @@ -218,10 +218,10 @@ public: } float interpolationFactor(float currentZoom) const override { - if (function.useIntegerZoom) { - return function.interpolationFactor(zoomRange, std::floor(currentZoom)); + if (expression.useIntegerZoom) { + return expression.interpolationFactor(zoomRange, std::floor(currentZoom)); } else { - return function.interpolationFactor(zoomRange, currentZoom); + return expression.interpolationFactor(zoomRange, currentZoom); } } @@ -235,7 +235,7 @@ public: } private: - style::CompositeFunction<T> function; + style::PropertyExpression<T> expression; T defaultValue; Range<float> zoomRange; gl::VertexVector<Vertex> vertexVector; @@ -249,11 +249,12 @@ PaintPropertyBinder<T, A>::create(const PossiblyEvaluatedPropertyValue<T>& value [&] (const T& constant) -> std::unique_ptr<PaintPropertyBinder<T, A>> { return std::make_unique<ConstantPaintPropertyBinder<T, A>>(constant); }, - [&] (const style::SourceFunction<T>& function) { - return std::make_unique<SourceFunctionPaintPropertyBinder<T, A>>(function, defaultValue); - }, - [&] (const style::CompositeFunction<T>& function) { - return std::make_unique<CompositeFunctionPaintPropertyBinder<T, A>>(function, zoom, defaultValue); + [&] (const style::PropertyExpression<T>& expression) -> std::unique_ptr<PaintPropertyBinder<T, A>> { + if (expression.isZoomConstant()) { + return std::make_unique<SourceFunctionPaintPropertyBinder<T, A>>(expression, defaultValue); + } else { + return std::make_unique<CompositeFunctionPaintPropertyBinder<T, A>>(expression, zoom, defaultValue); + } } ); } diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index e662d5dfb1..f2d265f2f7 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -1,7 +1,6 @@ #pragma once -#include <mbgl/style/function/source_function.hpp> -#include <mbgl/style/function/composite_function.hpp> +#include <mbgl/style/property_expression.hpp> #include <mbgl/util/interpolate.hpp> #include <mbgl/util/variant.hpp> @@ -12,8 +11,7 @@ class PossiblyEvaluatedPropertyValue { private: using Value = variant< T, - style::SourceFunction<T>, - style::CompositeFunction<T>>; + style::PropertyExpression<T>>; Value value; @@ -45,17 +43,14 @@ public: 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) { - if (useIntegerZoom) { - return function.evaluate(floor(zoom), feature, defaultValue); - } else { - return function.evaluate(zoom, feature, defaultValue); - } + [&] (const T& constant_) { return constant_; }, + [&] (const style::PropertyExpression<T>& expression) { + if (useIntegerZoom) { + return expression.evaluate(floor(zoom), feature, defaultValue); + } else { + return expression.evaluate(zoom, feature, defaultValue); } + } ); } diff --git a/src/mbgl/renderer/property_evaluator.hpp b/src/mbgl/renderer/property_evaluator.hpp index 3ac0573920..03e0f5a002 100644 --- a/src/mbgl/renderer/property_evaluator.hpp +++ b/src/mbgl/renderer/property_evaluator.hpp @@ -16,7 +16,7 @@ public: T operator()(const style::Undefined&) const { return defaultValue; } T operator()(const T& constant) const { return constant; } - T operator()(const style::CameraFunction<T>& fn) const { return fn.evaluate(parameters.z); } + T operator()(const style::PropertyExpression<T>& fn) const { return fn.evaluate(parameters.z); } private: const PropertyEvaluationParameters& parameters; |