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 | |
parent | 6d7072162b764c2432c010cd463a5a2c0093d606 (diff) | |
download | qtlocation-mapboxgl-c8edbb0500cbf4baf1d5fdb0e63679539e166585.tar.gz |
[core] Replace {Source,Camera,Composite}Function with PropertyExpression
53 files changed, 702 insertions, 951 deletions
diff --git a/benchmark/function/camera_function.benchmark.cpp b/benchmark/function/camera_function.benchmark.cpp index 26de5701db..52b6bc9f08 100644 --- a/benchmark/function/camera_function.benchmark.cpp +++ b/benchmark/function/camera_function.benchmark.cpp @@ -1,9 +1,9 @@ #include <benchmark/benchmark.h> -#include <mbgl/style/function/source_function.hpp> #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/function.hpp> +#include <mbgl/style/conversion/property_value.hpp> using namespace mbgl; using namespace mbgl::style; @@ -27,7 +27,7 @@ static void Parse_CameraFunction(benchmark::State& state) { state.PauseTiming(); auto doc = createFunctionJSON(stopCount); state.ResumeTiming(); - optional<CameraFunction<float>> result = conversion::convertJSON<CameraFunction<float>>(doc, error); + optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error); if (!result) { state.SkipWithError(error.message.c_str()); } @@ -39,14 +39,14 @@ static void Evaluate_CameraFunction(benchmark::State& state) { size_t stopCount = state.range(0); auto doc = createFunctionJSON(stopCount); conversion::Error error; - optional<CameraFunction<float>> function = conversion::convertJSON<CameraFunction<float>>(doc, error); + optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error); if (!function) { state.SkipWithError(error.message.c_str()); } while(state.KeepRunning()) { float z = 24.0f * static_cast<float>(rand() % 100) / 100; - function->evaluate(z); + function->asExpression().evaluate(z); } state.SetLabel(std::to_string(stopCount).c_str()); diff --git a/benchmark/function/composite_function.benchmark.cpp b/benchmark/function/composite_function.benchmark.cpp index 8442e0aa15..77258669a5 100644 --- a/benchmark/function/composite_function.benchmark.cpp +++ b/benchmark/function/composite_function.benchmark.cpp @@ -2,11 +2,10 @@ #include <mbgl/benchmark/stub_geometry_tile_feature.hpp> -#include <mbgl/style/function/composite_function.hpp> - #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/function.hpp> +#include <mbgl/style/conversion/data_driven_property_value.hpp> using namespace mbgl; using namespace mbgl::style; @@ -34,7 +33,7 @@ static void Parse_CompositeFunction(benchmark::State& state) { state.PauseTiming(); auto doc = createFunctionJSON(stopCount); state.ResumeTiming(); - optional<CompositeFunction<float>> result = conversion::convertJSON<style::CompositeFunction<float>>(doc, error); + optional<DataDrivenPropertyValue<float>> result = conversion::convertJSON<DataDrivenPropertyValue<float>>(doc, error); if (!result) { state.SkipWithError(error.message.c_str()); } @@ -46,14 +45,14 @@ static void Evaluate_CompositeFunction(benchmark::State& state) { size_t stopCount = state.range(0); auto doc = createFunctionJSON(stopCount); conversion::Error error; - optional<CompositeFunction<float>> function = conversion::convertJSON<CompositeFunction<float>>(doc, error); + optional<DataDrivenPropertyValue<float>> function = conversion::convertJSON<DataDrivenPropertyValue<float>>(doc, error); if (!function) { state.SkipWithError(error.message.c_str()); } while(state.KeepRunning()) { float z = 24.0f * static_cast<float>(rand() % 100) / 100; - function->evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f); + function->asExpression().evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f); } state.SetLabel(std::to_string(stopCount).c_str()); diff --git a/benchmark/function/source_function.benchmark.cpp b/benchmark/function/source_function.benchmark.cpp index af361943e3..402c9b89d2 100644 --- a/benchmark/function/source_function.benchmark.cpp +++ b/benchmark/function/source_function.benchmark.cpp @@ -2,11 +2,9 @@ #include <mbgl/benchmark/stub_geometry_tile_feature.hpp> -#include <mbgl/style/function/source_function.hpp> - #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/json.hpp> -#include <mbgl/style/conversion/function.hpp> +#include <mbgl/style/conversion/data_driven_property_value.hpp> using namespace mbgl; using namespace mbgl::style; @@ -30,7 +28,7 @@ static void Parse_SourceFunction(benchmark::State& state) { state.PauseTiming(); auto doc = createFunctionJSON(stopCount); state.ResumeTiming(); - optional<SourceFunction<float>> result = conversion::convertJSON<SourceFunction<float>>(doc, error); + optional<DataDrivenPropertyValue<float>> result = conversion::convertJSON<DataDrivenPropertyValue<float>>(doc, error); if (!result) { state.SkipWithError(error.message.c_str()); } @@ -42,13 +40,13 @@ static void Evaluate_SourceFunction(benchmark::State& state) { size_t stopCount = state.range(0); auto doc = createFunctionJSON(stopCount); conversion::Error error; - optional<SourceFunction<float>> function = conversion::convertJSON<SourceFunction<float>>(doc, error); + optional<DataDrivenPropertyValue<float>> function = conversion::convertJSON<DataDrivenPropertyValue<float>>(doc, error); if (!function) { state.SkipWithError(error.message.c_str()); } while(state.KeepRunning()) { - function->evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f); + function->asExpression().evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f); } state.SetLabel(std::to_string(stopCount).c_str()); diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 204bb78bce..2aae6e4573 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -368,6 +368,7 @@ set(MBGL_CORE_FILES include/mbgl/style/layer_type.hpp include/mbgl/style/light.hpp include/mbgl/style/position.hpp + include/mbgl/style/property_expression.hpp include/mbgl/style/property_value.hpp include/mbgl/style/source.hpp include/mbgl/style/style.hpp @@ -499,9 +500,6 @@ set(MBGL_CORE_FILES src/mbgl/style/expression/value.cpp # style/function - include/mbgl/style/function/camera_function.hpp - include/mbgl/style/function/composite_function.hpp - include/mbgl/style/function/source_function.hpp src/mbgl/style/function/expression.cpp # style/layers diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 5d76ffcade..1961d78dfc 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -68,6 +68,7 @@ set(MBGL_TEST_FILES # style test/style/filter.test.cpp test/style/properties.test.cpp + test/style/property_expression.test.cpp test/style/source.test.cpp test/style/style.test.cpp test/style/style_image.test.cpp @@ -87,11 +88,6 @@ set(MBGL_TEST_FILES test/style/expression/expression.test.cpp test/style/expression/util.test.cpp - # style/function - test/style/function/camera_function.test.cpp - test/style/function/composite_function.test.cpp - test/style/function/source_function.test.cpp - # test test/include/mbgl/test.hpp test/src/mbgl/test/fake_file_source.hpp diff --git a/include/mbgl/style/color_ramp_property_value.hpp b/include/mbgl/style/color_ramp_property_value.hpp index 3e93285d5a..bc5639c899 100644 --- a/include/mbgl/style/color_ramp_property_value.hpp +++ b/include/mbgl/style/color_ramp_property_value.hpp @@ -2,7 +2,7 @@ #include <mbgl/util/variant.hpp> #include <mbgl/style/undefined.hpp> -#include <mbgl/style/function/camera_function.hpp> +#include <mbgl/style/expression/expression.hpp> namespace mbgl { namespace style { diff --git a/include/mbgl/style/conversion/color_ramp_property_value.hpp b/include/mbgl/style/conversion/color_ramp_property_value.hpp index cf5d5e55d9..9394daa050 100644 --- a/include/mbgl/style/conversion/color_ramp_property_value.hpp +++ b/include/mbgl/style/conversion/color_ramp_property_value.hpp @@ -3,11 +3,9 @@ #include <mbgl/style/color_ramp_property_value.hpp> #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/constant.hpp> -#include <mbgl/style/conversion/function.hpp> #include <mbgl/style/expression/value.hpp> #include <mbgl/style/expression/is_constant.hpp> #include <mbgl/style/expression/is_expression.hpp> -#include <mbgl/style/expression/find_zoom_curve.hpp> #include <mbgl/style/expression/parsing_context.hpp> namespace mbgl { diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp index 07ed201c99..363134bd3e 100644 --- a/include/mbgl/style/conversion/data_driven_property_value.hpp +++ b/include/mbgl/style/conversion/data_driven_property_value.hpp @@ -6,74 +6,54 @@ #include <mbgl/style/conversion/function.hpp> #include <mbgl/style/expression/is_expression.hpp> #include <mbgl/style/expression/is_constant.hpp> -#include <mbgl/style/expression/find_zoom_curve.hpp> #include <mbgl/style/expression/literal.hpp> #include <mbgl/style/expression/value.hpp> #include <mbgl/style/expression/parsing_context.hpp> -#include <unordered_set> - - namespace mbgl { namespace style { namespace conversion { template <class T> struct Converter<DataDrivenPropertyValue<T>> { - optional<DataDrivenPropertyValue<T>> operator()(const Convertible& value, Error& error) const { using namespace mbgl::style::expression; - + if (isUndefined(value)) { return DataDrivenPropertyValue<T>(); - } else if (isExpression(value)) { + } + + optional<PropertyExpression<T>> expression; + + if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType<T>()); - ParseResult expression = ctx.parseLayerPropertyExpression(value); - if (!expression) { + ParseResult parsed = ctx.parseLayerPropertyExpression(value); + if (!parsed) { error = { ctx.getCombinedErrors() }; return {}; } - - bool featureConstant = isFeatureConstant(**expression); - bool zoomConstant = isZoomConstant(**expression); - - if (featureConstant && !zoomConstant) { - return DataDrivenPropertyValue<T>(CameraFunction<T>(std::move(*expression))); - } else if (!featureConstant && zoomConstant) { - return DataDrivenPropertyValue<T>(SourceFunction<T>(std::move(*expression))); - } else if (!featureConstant && !zoomConstant) { - return DataDrivenPropertyValue<T>(CompositeFunction<T>(std::move(*expression))); - } else { - auto literal = dynamic_cast<Literal*>(expression->get()); - assert(literal); - optional<T> constant = fromExpressionValue<T>(literal->getValue()); - if (!constant) { - return {}; - } - return DataDrivenPropertyValue<T>(*constant); - } - } else if (!isObject(value)) { + expression = PropertyExpression<T>(std::move(*parsed)); + } else if (isObject(value)) { + expression = convertFunctionToExpression<T>(value, error); + } else { optional<T> constant = convert<T>(value, error); if (!constant) { return {}; } return DataDrivenPropertyValue<T>(*constant); - } else if (!objectMember(value, "property")) { - optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error); - if (!function) { - return {}; - } - return DataDrivenPropertyValue<T>(*function); + } + + if (!expression) { + return {}; + } else if (!(*expression).isFeatureConstant() || !(*expression).isZoomConstant()) { + return { std::move(*expression) }; } else { - optional<CompositeFunction<T>> composite = convert<CompositeFunction<T>>(value, error); - if (composite) { - return DataDrivenPropertyValue<T>(*composite); - } - optional<SourceFunction<T>> source = convert<SourceFunction<T>>(value, error); - if (!source) { + optional<T> constant = fromExpressionValue<T>( + dynamic_cast<const Literal&>((*expression).getExpression()).getValue()); + if (!constant) { return {}; } - return DataDrivenPropertyValue<T>(*source); + return DataDrivenPropertyValue<T>(*constant); } } }; diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 5ddede324b..6bc75d7141 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -1,8 +1,6 @@ #pragma once -#include <mbgl/style/function/camera_function.hpp> -#include <mbgl/style/function/source_function.hpp> -#include <mbgl/style/function/composite_function.hpp> +#include <mbgl/style/property_expression.hpp> #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/constant.hpp> #include <mbgl/style/expression/expression.hpp> @@ -12,66 +10,28 @@ namespace mbgl { namespace style { namespace conversion { -template <class T> -optional<optional<T>> convertDefaultValue(const Convertible& value, Error& error) { - auto defaultValueValue = objectMember(value, "default"); - if (!defaultValueValue) { - return optional<T>(); - } +optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&); - auto defaultValue = convert<T>(*defaultValueValue, error); - if (!defaultValue) { - error = { R"(wrong type for "default": )" + error.message }; +template <class T> +optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error) { + auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error); + if (!expression) { return {}; } - return { *defaultValue }; -} - -optional<std::unique_ptr<expression::Expression>> convertCameraFunctionToExpression(expression::type::Type, const Convertible&, Error&); -optional<std::unique_ptr<expression::Expression>> convertSourceFunctionToExpression(expression::type::Type, const Convertible&, Error&); -optional<std::unique_ptr<expression::Expression>> convertCompositeFunctionToExpression(expression::type::Type, const Convertible&, Error&); + optional<T> defaultValue; -template <class T> -struct Converter<CameraFunction<T>> { - optional<CameraFunction<T>> operator()(const Convertible& value, Error& error) const { - auto expression = convertCameraFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error); - if (!expression) { - return {}; - } - return CameraFunction<T>(std::move(*expression), false); - } -}; - -template <class T> -struct Converter<SourceFunction<T>> { - optional<SourceFunction<T>> operator()(const Convertible& value, Error& error) const { - auto expression = convertSourceFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error); - if (!expression) { - return {}; - } - auto defaultValue = convertDefaultValue<T>(value, error); + auto defaultValueValue = objectMember(value, "default"); + if (defaultValueValue) { + defaultValue = convert<T>(*defaultValueValue, error); if (!defaultValue) { + error = { R"(wrong type for "default": )" + error.message }; return {}; } - return SourceFunction<T>(std::move(*expression), *defaultValue); } -}; -template <class T> -struct Converter<CompositeFunction<T>> { - optional<CompositeFunction<T>> operator()(const Convertible& value, Error& error) const { - auto expression = convertCompositeFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error); - if (!expression) { - return {}; - } - auto defaultValue = convertDefaultValue<T>(value, error); - if (!defaultValue) { - return {}; - } - return CompositeFunction<T>(std::move(*expression), *defaultValue); - } -}; + return PropertyExpression<T>(std::move(*expression), defaultValue); +} } // namespace conversion } // namespace style diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp index e52c63d023..2256cfffb4 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -7,7 +7,6 @@ #include <mbgl/style/expression/value.hpp> #include <mbgl/style/expression/is_constant.hpp> #include <mbgl/style/expression/is_expression.hpp> -#include <mbgl/style/expression/find_zoom_curve.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/literal.hpp> @@ -22,34 +21,20 @@ struct Converter<PropertyValue<T>> { if (isUndefined(value)) { return PropertyValue<T>(); - } else if (isExpression(value)) { + } + + optional<PropertyExpression<T>> expression; + + if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType<T>()); - ParseResult expression = ctx.parseLayerPropertyExpression(value); - if (!expression) { + ParseResult parsed = ctx.parseLayerPropertyExpression(value); + if (!parsed) { error = { ctx.getCombinedErrors() }; return {}; } - - if (!isFeatureConstant(**expression)) { - error = { "property expressions not supported" }; - return {}; - } else if (!isZoomConstant(**expression)) { - return { CameraFunction<T>(std::move(*expression)) }; - } else { - auto literal = dynamic_cast<Literal*>(expression->get()); - assert(literal); - optional<T> constant = fromExpressionValue<T>(literal->getValue()); - if (!constant) { - return {}; - } - return PropertyValue<T>(*constant); - } + expression = PropertyExpression<T>(std::move(*parsed)); } else if (isObject(value)) { - optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error); - if (!function) { - return {}; - } - return { *function }; + expression = convertFunctionToExpression<T>(value, error); } else { optional<T> constant = convert<T>(value, error); if (!constant) { @@ -57,6 +42,22 @@ struct Converter<PropertyValue<T>> { } return { *constant }; } + + if (!expression) { + return {}; + } else if (!(*expression).isFeatureConstant()) { + error = { "data expressions not supported" }; + return {}; + } else if (!(*expression).isZoomConstant()) { + return { std::move(*expression) }; + } else { + optional<T> constant = fromExpressionValue<T>( + dynamic_cast<const Literal&>((*expression).getExpression()).getValue()); + if (!constant) { + return {}; + } + return PropertyValue<T>(*constant); + } } }; diff --git a/include/mbgl/style/data_driven_property_value.hpp b/include/mbgl/style/data_driven_property_value.hpp index 0a1fce29c7..a95eaa4ea8 100644 --- a/include/mbgl/style/data_driven_property_value.hpp +++ b/include/mbgl/style/data_driven_property_value.hpp @@ -2,9 +2,7 @@ #include <mbgl/util/variant.hpp> #include <mbgl/style/undefined.hpp> -#include <mbgl/style/function/camera_function.hpp> -#include <mbgl/style/function/source_function.hpp> -#include <mbgl/style/function/composite_function.hpp> +#include <mbgl/style/property_expression.hpp> namespace mbgl { namespace style { @@ -15,9 +13,7 @@ private: using Value = variant< Undefined, T, - CameraFunction<T>, - SourceFunction<T>, - CompositeFunction<T>>; + PropertyExpression<T>>; Value value; @@ -33,32 +29,40 @@ private: public: DataDrivenPropertyValue() = default; - DataDrivenPropertyValue( T v) : value(std::move(v)) {} - DataDrivenPropertyValue( CameraFunction<T> v) : value(std::move(v)) {} - DataDrivenPropertyValue( SourceFunction<T> v) : value(std::move(v)) {} - DataDrivenPropertyValue(CompositeFunction<T> v) : value(std::move(v)) {} + DataDrivenPropertyValue( T v) : value(std::move(v)) {} + DataDrivenPropertyValue(PropertyExpression<T> v) : value(std::move(v)) {} bool isUndefined() const { return value.template is<Undefined>(); } bool isDataDriven() const { - return value.template is<SourceFunction<T>>() || value.template is<CompositeFunction<T>>(); + return value.match( + [] (const Undefined&) { return false; }, + [] (const T&) { return false; }, + [] (const PropertyExpression<T>& fn) { return !fn.isFeatureConstant(); } + ); } - + bool isZoomConstant() const { - return !value.template is<CameraFunction<T>>() && !value.template is<CompositeFunction<T>>(); + return value.match( + [] (const Undefined&) { return true; }, + [] (const T&) { return true; }, + [] (const PropertyExpression<T>& fn) { return fn.isZoomConstant(); } + ); } bool isExpression() const { return value.match( - [] (const Undefined&) { return false; }, - [] (const T&) { return false; }, - [] (const CameraFunction<T>& fn) { return fn.isExpression; }, - [] (const SourceFunction<T>& fn) { return fn.isExpression; }, - [] (const CompositeFunction<T>& fn) { return fn.isExpression; }); + [] (const Undefined&) { return false; }, + [] (const T&) { return false; }, + [] (const PropertyExpression<T>& fn) { return fn.isExpression; } + ); } + const T & asConstant() const { return value.template get< T >(); } + const PropertyExpression<T>& asExpression() const { return value.template get<PropertyExpression<T>>(); } + template <class... Ts> auto match(Ts&&... ts) const { return value.match(std::forward<Ts>(ts)...); diff --git a/include/mbgl/style/expression/find_zoom_curve.hpp b/include/mbgl/style/expression/find_zoom_curve.hpp index 1e19436dd9..6f1419a69f 100644 --- a/include/mbgl/style/expression/find_zoom_curve.hpp +++ b/include/mbgl/style/expression/find_zoom_curve.hpp @@ -13,7 +13,7 @@ namespace expression { optional<variant<const Interpolate*, const Step*, ParsingError>> findZoomCurve(const expression::Expression* e); -variant<const Interpolate*, const Step*> findZoomCurveChecked(const expression::Expression* e); +variant<std::nullptr_t, const Interpolate*, const Step*> findZoomCurveChecked(const expression::Expression* e); } // namespace expression } // namespace style diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp deleted file mode 100644 index 65b7991849..0000000000 --- a/include/mbgl/style/function/camera_function.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -#include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/value.hpp> -#include <mbgl/style/expression/is_constant.hpp> -#include <mbgl/style/expression/interpolate.hpp> -#include <mbgl/style/expression/step.hpp> -#include <mbgl/style/expression/find_zoom_curve.hpp> -#include <mbgl/util/range.hpp> - -namespace mbgl { -namespace style { - -template <class T> -class CameraFunction { -public: - // The second parameter should be used only for conversions from legacy functions. - CameraFunction(std::unique_ptr<expression::Expression> expression_, bool isExpression_ = true) - : isExpression(isExpression_), - expression(std::move(expression_)), - zoomCurve(expression::findZoomCurveChecked(expression.get())) { - assert(!expression::isZoomConstant(*expression)); - assert(expression::isFeatureConstant(*expression)); - } - - T evaluate(float zoom) const { - const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(zoom, nullptr)); - if (result) { - const optional<T> typed = expression::fromExpressionValue<T>(*result); - return typed ? *typed : T(); - } - return T(); - } - - float interpolationFactor(const Range<float>& inputLevels, const float inputValue) const { - return zoomCurve.match( - [&](const expression::Interpolate* z) { - return z->interpolationFactor(Range<double> { inputLevels.min, inputLevels.max }, inputValue); - }, - [&](const expression::Step*) { return 0.0f; } - ); - } - - Range<float> getCoveringStops(const float lower, const float upper) const { - return zoomCurve.match( - [&](auto z) { return z->getCoveringStops(lower, upper); } - ); - } - - std::vector<optional<T>> possibleOutputs() const { - return expression::fromExpressionValues<T>(expression->possibleOutputs()); - } - - friend bool operator==(const CameraFunction& lhs, - const CameraFunction& rhs) { - return *lhs.expression == *rhs.expression; - } - - bool useIntegerZoom = false; - bool isExpression; - - const expression::Expression& getExpression() const { return *expression; } - -private: - std::shared_ptr<const expression::Expression> expression; - const variant<const expression::Interpolate*, const expression::Step*> zoomCurve; -}; - -} // namespace style -} // namespace mbgl diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp deleted file mode 100644 index a83e73a5d0..0000000000 --- a/include/mbgl/style/function/source_function.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/value.hpp> -#include <mbgl/style/expression/is_constant.hpp> - -namespace mbgl { -namespace style { - -template <class T> -class SourceFunction { -public: - // The second parameter should be used only for conversions from legacy functions. - SourceFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {}) - : isExpression(defaultValue_), - expression(std::move(expression_)), - defaultValue(std::move(defaultValue_)) { - assert(expression::isZoomConstant(*expression)); - assert(!expression::isFeatureConstant(*expression)); - } - - template <class Feature> - T evaluate(const Feature& feature, T finalDefaultValue) const { - const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature)); - if (result) { - const optional<T> typed = expression::fromExpressionValue<T>(*result); - return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue; - } - return defaultValue ? *defaultValue : finalDefaultValue; - } - - std::vector<optional<T>> possibleOutputs() const { - return expression::fromExpressionValues<T>(expression->possibleOutputs()); - } - - friend bool operator==(const SourceFunction& lhs, - const SourceFunction& rhs) { - return *lhs.expression == *rhs.expression; - } - - bool useIntegerZoom = false; - bool isExpression; - - const expression::Expression& getExpression() const { return *expression; } - -private: - std::shared_ptr<const expression::Expression> expression; - optional<T> defaultValue; -}; - -} // namespace style -} // namespace mbgl diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/property_expression.hpp index 3b63bd005d..16f154cdf2 100644 --- a/include/mbgl/style/function/composite_function.hpp +++ b/include/mbgl/style/property_expression.hpp @@ -12,29 +12,51 @@ namespace mbgl { namespace style { template <class T> -class CompositeFunction { +class PropertyExpression { public: - // The second parameter should be used only for conversions from legacy functions. - CompositeFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {}) - : isExpression(defaultValue_), + PropertyExpression(std::unique_ptr<expression::Expression> expression_) + : isExpression(true), + expression(std::move(expression_)), + zoomCurve(expression::findZoomCurveChecked(expression.get())) { + } + + // To be used only for conversions from legacy functions. + PropertyExpression(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_) + : isExpression(false), expression(std::move(expression_)), defaultValue(std::move(defaultValue_)), zoomCurve(expression::findZoomCurveChecked(expression.get())) { + } + + bool isZoomConstant() const { return expression::isZoomConstant(*expression); } + bool isFeatureConstant() const { return expression::isFeatureConstant(*expression); } + + T evaluate(float zoom) const { assert(!expression::isZoomConstant(*expression)); - assert(!expression::isFeatureConstant(*expression)); + assert(expression::isFeatureConstant(*expression)); + const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(zoom, nullptr)); + if (result) { + const optional<T> typed = expression::fromExpressionValue<T>(*result); + return typed ? *typed : defaultValue ? *defaultValue : T(); + } + return defaultValue ? *defaultValue : T(); } - // Return the range obtained by evaluating the function at each of the zoom levels in zoomRange template <class Feature> - Range<T> evaluate(const Range<float>& zoomRange, const Feature& feature, T finalDefaultValue) { - return Range<T> { - evaluate(zoomRange.min, feature, finalDefaultValue), - evaluate(zoomRange.max, feature, finalDefaultValue) - }; + T evaluate(const Feature& feature, T finalDefaultValue) const { + assert(expression::isZoomConstant(*expression)); + assert(!expression::isFeatureConstant(*expression)); + const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature)); + if (result) { + const optional<T> typed = expression::fromExpressionValue<T>(*result); + return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue; + } + return defaultValue ? *defaultValue : finalDefaultValue; } template <class Feature> T evaluate(float zoom, const Feature& feature, T finalDefaultValue) const { + assert(!expression::isFeatureConstant(*expression)); const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext({zoom}, &feature)); if (result) { const optional<T> typed = expression::fromExpressionValue<T>(*result); @@ -42,40 +64,61 @@ public: } return defaultValue ? *defaultValue : finalDefaultValue; } - + float interpolationFactor(const Range<float>& inputLevels, const float inputValue) const { return zoomCurve.match( + [](std::nullptr_t) { + assert(false); + return 0.0f; + }, [&](const expression::Interpolate* z) { return z->interpolationFactor(Range<double> { inputLevels.min, inputLevels.max }, inputValue); }, - [&](const expression::Step*) { return 0.0f; } + [&](const expression::Step*) { + return 0.0f; + } ); } - + Range<float> getCoveringStops(const float lower, const float upper) const { return zoomCurve.match( - [&](auto z) { return z->getCoveringStops(lower, upper); } + [](std::nullptr_t) { + assert(false); + return Range<float>(0.0f, 0.0f); + }, + [&](auto z) { + return z->getCoveringStops(lower, upper); + } ); } - std::vector<optional<T>> possibleOutputs() const { - return expression::fromExpressionValues<T>(expression->possibleOutputs()); + // Return the range obtained by evaluating the function at each of the zoom levels in zoomRange + template <class Feature> + Range<T> evaluate(const Range<float>& zoomRange, const Feature& feature, T finalDefaultValue) { + return Range<T> { + evaluate(zoomRange.min, feature, finalDefaultValue), + evaluate(zoomRange.max, feature, finalDefaultValue) + }; } - friend bool operator==(const CompositeFunction& lhs, - const CompositeFunction& rhs) { - return *lhs.expression == *rhs.expression; + std::vector<optional<T>> possibleOutputs() const { + return expression::fromExpressionValues<T>(expression->possibleOutputs()); } const expression::Expression& getExpression() const { return *expression; } bool useIntegerZoom = false; bool isExpression; - + + friend bool operator==(const PropertyExpression& lhs, + const PropertyExpression& rhs) { + return *lhs.expression == *rhs.expression; + } + private: std::shared_ptr<const expression::Expression> expression; optional<T> defaultValue; - const variant<const expression::Interpolate*, const expression::Step*> zoomCurve; + variant<std::nullptr_t, const expression::Interpolate*, const expression::Step*> zoomCurve; }; } // namespace style diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index 02d3a31148..1b0f3d2ab0 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -2,7 +2,7 @@ #include <mbgl/util/variant.hpp> #include <mbgl/style/undefined.hpp> -#include <mbgl/style/function/camera_function.hpp> +#include <mbgl/style/property_expression.hpp> namespace mbgl { namespace style { @@ -10,7 +10,7 @@ namespace style { template <class T> class PropertyValue { private: - using Value = variant<Undefined, T, CameraFunction<T>>; + using Value = variant<Undefined, T, PropertyExpression<T>>; Value value; friend bool operator==(const PropertyValue& lhs, const PropertyValue& rhs) { @@ -22,17 +22,24 @@ private: } public: - PropertyValue() : value() {} - PropertyValue( T constant) : value(constant) {} - PropertyValue(CameraFunction<T> function) : value(function) {} + PropertyValue() + : value() {} + + PropertyValue(T constant) + : value(constant) {} + + PropertyValue(PropertyExpression<T> expression) + : value(expression) { + assert(expression.isFeatureConstant()); + } bool isUndefined() const { return value.which() == 0; } bool isConstant() const { return value.which() == 1; } - bool isCameraFunction() const { return value.which() == 2; } + bool isExpression() const { return value.which() == 2; } bool isDataDriven() const { return false; } - const T & asConstant() const { return value.template get< T >(); } - const CameraFunction<T>& asCameraFunction() const { return value.template get<CameraFunction<T>>(); } + const T & asConstant() const { return value.template get< T >(); } + const PropertyExpression<T>& asExpression() const { return value.template get<PropertyExpression<T>>(); } template <typename Evaluator> auto evaluate(const Evaluator& evaluator, TimePoint = {}) const { diff --git a/platform/android/config.cmake b/platform/android/config.cmake index 88130dc104..21ec6a9e0c 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -129,7 +129,7 @@ add_library(mbgl-android STATIC # Conversion C++ -> Java platform/android/src/conversion/constant.hpp platform/android/src/conversion/conversion.hpp - platform/android/src/style/conversion/function.hpp + platform/android/src/style/conversion/property_expression.hpp platform/android/src/style/conversion/property_value.hpp platform/android/src/style/conversion/types.hpp platform/android/src/style/conversion/types_string_values.hpp diff --git a/platform/android/src/style/conversion/function.hpp b/platform/android/src/style/conversion/function.hpp deleted file mode 100644 index d6669b4508..0000000000 --- a/platform/android/src/style/conversion/function.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include <mbgl/style/property_value.hpp> -#include "../../conversion/conversion.hpp" -#include "../../conversion/constant.hpp" -#include "types.hpp" -#include "../../java/lang.hpp" - -#include <jni/jni.hpp> -#include "../../gson/json_element.hpp" - -#include <tuple> -#include <map> - -namespace mbgl { -namespace android { -namespace conversion { - -template <class T> -struct Converter<jni::Object<android::gson::JsonElement>, mbgl::style::CameraFunction<T>> { - - Result<jni::Object<android::gson::JsonElement>> operator()(jni::JNIEnv& env, const mbgl::style::CameraFunction<T>& value) const { - // Convert expressions - mbgl::Value expressionValue = value.getExpression().serialize(); - return gson::JsonElement::New(env, expressionValue); - } -}; - -template <class T> -struct Converter<jni::Object<android::gson::JsonElement>, mbgl::style::SourceFunction<T>> { - - Result<jni::Object<android::gson::JsonElement>> operator()(jni::JNIEnv& env, const mbgl::style::SourceFunction<T>& value) const { - // Convert expressions - mbgl::Value expressionValue = value.getExpression().serialize(); - return gson::JsonElement::New(env, expressionValue); - } -}; - -template <class T> -struct Converter<jni::Object<android::gson::JsonElement>, mbgl::style::CompositeFunction<T>> { - - Result<jni::Object<android::gson::JsonElement>> operator()(jni::JNIEnv& env, const mbgl::style::CompositeFunction<T>& value) const { - // Convert expressions - mbgl::Value expressionValue = value.getExpression().serialize(); - return gson::JsonElement::New(env, expressionValue); - } -}; - -} // namespace conversion -} // namespace android -} // namespace mbgl diff --git a/platform/android/src/style/conversion/property_expression.hpp b/platform/android/src/style/conversion/property_expression.hpp new file mode 100644 index 0000000000..ae9d4ea41c --- /dev/null +++ b/platform/android/src/style/conversion/property_expression.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <mbgl/style/property_value.hpp> +#include "../../conversion/conversion.hpp" +#include "../../conversion/constant.hpp" +#include "types.hpp" +#include "../../java/lang.hpp" + +#include <jni/jni.hpp> +#include "../../gson/json_element.hpp" + +#include <tuple> +#include <map> + +namespace mbgl { +namespace android { +namespace conversion { + +template <class T> +struct Converter<jni::Object<android::gson::JsonElement>, mbgl::style::PropertyExpression<T>> { + + Result<jni::Object<android::gson::JsonElement>> operator()(jni::JNIEnv& env, const mbgl::style::PropertyExpression<T>& value) const { + // Convert expressions + mbgl::Value expressionValue = value.getExpression().serialize(); + return gson::JsonElement::New(env, expressionValue); + } +}; + +} // namespace conversion +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/conversion/property_value.hpp b/platform/android/src/style/conversion/property_value.hpp index e6fbe42179..feed38b673 100644 --- a/platform/android/src/style/conversion/property_value.hpp +++ b/platform/android/src/style/conversion/property_value.hpp @@ -5,8 +5,8 @@ #include <mbgl/style/property_value.hpp> #include "../../conversion/conversion.hpp" #include "../../conversion/constant.hpp" +#include "property_expression.hpp" #include "types.hpp" -#include "function.hpp" namespace mbgl { namespace android { @@ -30,16 +30,8 @@ public: return *result; } - jni::jobject* operator()(const mbgl::style::CameraFunction<T> &value) const { - return *convert<jni::Object<android::gson::JsonElement>, mbgl::style::CameraFunction<T>>(env, value); - } - - jni::jobject* operator()(const mbgl::style::SourceFunction<T> &value) const { - return *convert<jni::Object<android::gson::JsonElement>, mbgl::style::SourceFunction<T>>(env, value); - } - - jni::jobject* operator()(const mbgl::style::CompositeFunction<T> &value) const { - return *convert<jni::Object<android::gson::JsonElement>, mbgl::style::CompositeFunction<T>>(env, value); + jni::jobject* operator()(const mbgl::style::PropertyExpression<T> &value) const { + return *convert<jni::Object<android::gson::JsonElement>, mbgl::style::PropertyExpression<T>>(env, value); } private: diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 27f9e76632..c1958fc032 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -332,15 +332,7 @@ private: // Private utilities for converting from mbgl to mgl values return [NSExpression expressionForConstantValue:constantValue]; } - NSExpression *operator()(const mbgl::style::CameraFunction<MBGLType> &mbglValue) const { - return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; - } - - NSExpression *operator()(const mbgl::style::SourceFunction<MBGLType> &mbglValue) const { - return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; - } - - NSExpression *operator()(const mbgl::style::CompositeFunction<MBGLType> &mbglValue) const { + NSExpression *operator()(const mbgl::style::PropertyExpression<MBGLType> &mbglValue) const { return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; } }; diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm index 9f805160d1..afd066df82 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm @@ -48,7 +48,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -101,7 +101,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -154,7 +154,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::string>( + propertyValue = mbgl::style::PropertyExpression<std::string>( step(zoom(), literal("Background Pattern"), 18.0, literal("Background Pattern")) ); } diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.mm b/platform/darwin/test/MGLCircleStyleLayerTests.mm index d04e5d7271..7bfccd65ef 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.mm +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -69,7 +69,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -84,7 +84,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -100,7 +100,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -147,7 +147,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -162,7 +162,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -178,7 +178,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -225,7 +225,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -240,7 +240,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -256,7 +256,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -303,7 +303,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::AlignmentType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -347,7 +347,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -362,7 +362,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -378,7 +378,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -425,7 +425,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::CirclePitchScaleType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::CirclePitchScaleType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -469,7 +469,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -484,7 +484,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -500,7 +500,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -547,7 +547,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -562,7 +562,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -578,7 +578,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -625,7 +625,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -640,7 +640,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -656,7 +656,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -709,7 +709,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -753,7 +753,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TranslateAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm index c7a9a0c74e..6427d672e7 100644 --- a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm @@ -69,7 +69,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -84,7 +84,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -100,7 +100,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -147,7 +147,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -162,7 +162,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -178,7 +178,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -225,7 +225,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -240,7 +240,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -256,7 +256,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -303,7 +303,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -356,7 +356,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::string>( + propertyValue = mbgl::style::PropertyExpression<std::string>( step(zoom(), literal("Fill Extrusion Pattern"), 18.0, literal("Fill Extrusion Pattern")) ); } @@ -415,7 +415,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -459,7 +459,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TranslateAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm index 3789133bc6..921b59416b 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -69,7 +69,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(false), 18.0, literal(false)) ); } @@ -113,7 +113,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -128,7 +128,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -144,7 +144,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -191,7 +191,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -206,7 +206,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -222,7 +222,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -269,7 +269,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -284,7 +284,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -300,7 +300,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -347,7 +347,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::string>( + propertyValue = mbgl::style::PropertyExpression<std::string>( step(zoom(), literal("Fill Pattern"), 18.0, literal("Fill Pattern")) ); } @@ -406,7 +406,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -450,7 +450,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TranslateAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/darwin/test/MGLHeatmapStyleLayerTests.mm b/platform/darwin/test/MGLHeatmapStyleLayerTests.mm index c58cac9af0..a51a324cd9 100644 --- a/platform/darwin/test/MGLHeatmapStyleLayerTests.mm +++ b/platform/darwin/test/MGLHeatmapStyleLayerTests.mm @@ -69,7 +69,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -122,7 +122,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -175,7 +175,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -190,7 +190,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -206,7 +206,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -253,7 +253,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -268,7 +268,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -284,7 +284,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } diff --git a/platform/darwin/test/MGLHillshadeStyleLayerTests.mm b/platform/darwin/test/MGLHillshadeStyleLayerTests.mm index d5d470944c..2e8795759f 100644 --- a/platform/darwin/test/MGLHillshadeStyleLayerTests.mm +++ b/platform/darwin/test/MGLHillshadeStyleLayerTests.mm @@ -51,7 +51,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -104,7 +104,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -157,7 +157,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -210,7 +210,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::HillshadeIlluminationAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::HillshadeIlluminationAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -254,7 +254,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -298,7 +298,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm index 3f9a824d38..8ad354ef58 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.mm +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -69,7 +69,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::LineCapType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::LineCapType>( step(zoom(), literal("square"), 18.0, literal("square")) ); } @@ -113,7 +113,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::LineJoinType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::LineJoinType>( step(zoom(), literal("miter"), 18.0, literal("miter")) ); } @@ -151,7 +151,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -195,7 +195,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -239,7 +239,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -254,7 +254,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -270,7 +270,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -317,7 +317,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -332,7 +332,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -348,7 +348,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -395,7 +395,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::vector<float>>( + propertyValue = mbgl::style::PropertyExpression<std::vector<float>>( step(zoom(), literal({1, 2}), 18.0, literal({1, 2})) ); } @@ -439,7 +439,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -454,7 +454,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -470,7 +470,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -517,7 +517,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -532,7 +532,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -548,7 +548,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -595,7 +595,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -610,7 +610,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -626,7 +626,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -673,7 +673,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::string>( + propertyValue = mbgl::style::PropertyExpression<std::string>( step(zoom(), literal("Line Pattern"), 18.0, literal("Line Pattern")) ); } @@ -732,7 +732,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -776,7 +776,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TranslateAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -820,7 +820,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -835,7 +835,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -851,7 +851,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.mm b/platform/darwin/test/MGLRasterStyleLayerTests.mm index 217c585037..9325bb48f5 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.mm +++ b/platform/darwin/test/MGLRasterStyleLayerTests.mm @@ -51,7 +51,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -95,7 +95,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -139,7 +139,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -192,7 +192,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -236,7 +236,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -280,7 +280,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -333,7 +333,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::RasterResamplingType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::RasterResamplingType>( step(zoom(), literal("nearest"), 18.0, literal("nearest")) ); } @@ -377,7 +377,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs index 13cec9820b..44996fa125 100644 --- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs +++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs @@ -86,7 +86,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<<%- mbglType(property) %>>( + propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>( step(zoom(), literal(<%- mbglExpressionTestValue(property, type) %>), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>)) ); } @@ -102,7 +102,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<<%- mbglType(property) %>>( + propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>( interpolate(linear(), number(get("keyName")), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>)) ); } @@ -118,7 +118,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<<%- mbglType(property) %>>( + propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>))) ); } diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index f22ea04f6e..7566617872 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -69,7 +69,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -113,7 +113,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::SymbolAnchorType>( step(zoom(), literal("bottom-right"), 18.0, literal("bottom-right")) ); } @@ -151,7 +151,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -195,7 +195,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::string>( + propertyValue = mbgl::style::PropertyExpression<std::string>( step(zoom(), literal("Icon Image"), 18.0, literal("Icon Image")) ); } @@ -239,7 +239,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -254,7 +254,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 })) ); } @@ -270,7 +270,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 }))) ); } @@ -308,7 +308,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -352,7 +352,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -396,7 +396,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::AlignmentType>( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -440,7 +440,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -455,7 +455,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -471,7 +471,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -509,7 +509,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::AlignmentType>( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -553,7 +553,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -568,7 +568,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -584,7 +584,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -622,7 +622,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::IconTextFitType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::IconTextFitType>( step(zoom(), literal("both"), 18.0, literal("both")) ); } @@ -672,7 +672,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 4>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 4>>( step(zoom(), literal({ 1, 1, 1, 1 }), 18.0, literal({ 1, 1, 1, 1 })) ); } @@ -716,7 +716,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -760,7 +760,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(false), 18.0, literal(false)) ); } @@ -804,7 +804,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -848,7 +848,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -863,7 +863,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -879,7 +879,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -917,7 +917,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -961,7 +961,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolPlacementType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::SymbolPlacementType>( step(zoom(), literal("line"), 18.0, literal("line")) ); } @@ -1005,7 +1005,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1049,7 +1049,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::string>( + propertyValue = mbgl::style::PropertyExpression<std::string>( step(zoom(), literal("Text Field"), 18.0, literal("Text Field")) ); } @@ -1087,7 +1087,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -1131,7 +1131,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::SymbolAnchorType>( step(zoom(), literal("bottom-right"), 18.0, literal("bottom-right")) ); } @@ -1169,7 +1169,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::vector<std::string>>( + propertyValue = mbgl::style::PropertyExpression<std::vector<std::string>>( step(zoom(), literal({ "Text Font", "Tnof Txet" }), 18.0, literal({ "Text Font", "Tnof Txet" })) ); } @@ -1207,7 +1207,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1222,7 +1222,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1238,7 +1238,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1276,7 +1276,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -1320,7 +1320,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TextJustifyType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TextJustifyType>( step(zoom(), literal("right"), 18.0, literal("right")) ); } @@ -1358,7 +1358,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1373,7 +1373,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1389,7 +1389,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1427,7 +1427,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1477,7 +1477,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -1492,7 +1492,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 })) ); } @@ -1508,7 +1508,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 }))) ); } @@ -1546,7 +1546,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<bool>( + propertyValue = mbgl::style::PropertyExpression<bool>( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -1590,7 +1590,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1634,7 +1634,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::AlignmentType>( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -1678,7 +1678,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1693,7 +1693,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1709,7 +1709,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1747,7 +1747,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::AlignmentType>( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -1791,7 +1791,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TextTransformType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TextTransformType>( step(zoom(), literal("lowercase"), 18.0, literal("lowercase")) ); } @@ -1829,7 +1829,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -1844,7 +1844,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -1860,7 +1860,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -1907,7 +1907,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1922,7 +1922,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1938,7 +1938,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1985,7 +1985,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2000,7 +2000,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2016,7 +2016,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -2063,7 +2063,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2078,7 +2078,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2094,7 +2094,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2141,7 +2141,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2156,7 +2156,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2172,7 +2172,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2225,7 +2225,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -2269,7 +2269,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TranslateAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -2313,7 +2313,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2328,7 +2328,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2344,7 +2344,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -2391,7 +2391,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2406,7 +2406,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2422,7 +2422,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2469,7 +2469,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2484,7 +2484,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2500,7 +2500,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + propertyValue = mbgl::style::PropertyExpression<mbgl::Color>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -2547,7 +2547,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2562,7 +2562,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2578,7 +2578,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2625,7 +2625,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2640,7 +2640,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2656,7 +2656,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction<float>( + propertyValue = mbgl::style::PropertyExpression<float>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2709,7 +2709,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + propertyValue = mbgl::style::PropertyExpression<std::array<float, 2>>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -2753,7 +2753,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::TranslateAnchorType>( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 60cc20e05a..d7cabf6244 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -637,14 +637,14 @@ void GLFWView::toggle3DExtrusions(bool visible) { extrusionLayer->setSourceLayer("building"); extrusionLayer->setMinZoom(15.0f); extrusionLayer->setFilter(Filter(eq(get("extrude"), literal("true")))); - extrusionLayer->setFillExtrusionColor(SourceFunction<mbgl::Color>( + extrusionLayer->setFillExtrusionColor(PropertyExpression<mbgl::Color>( interpolate(linear(), number(get("height")), 0.f, toColor("#160e23"), 50.f, toColor("#00615f"), 100.f, toColor("#55e9ff")))); extrusionLayer->setFillExtrusionOpacity(0.6f); - extrusionLayer->setFillExtrusionHeight(SourceFunction<float>(get("height"))); - extrusionLayer->setFillExtrusionBase(SourceFunction<float>(get("min_height"))); + extrusionLayer->setFillExtrusionHeight(PropertyExpression<float>(get("height"))); + extrusionLayer->setFillExtrusionBase(PropertyExpression<float>(get("min_height"))); map->getStyle().addLayer(std::move(extrusionLayer)); } diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp index 84a7a53f1d..8df3b4ae3c 100644 --- a/src/mbgl/programs/symbol_program.cpp +++ b/src/mbgl/programs/symbol_program.cpp @@ -17,14 +17,20 @@ std::unique_ptr<SymbolSizeBinder> SymbolSizeBinder::create(const float tileZoom, const style::DataDrivenPropertyValue<float>& sizeProperty, const float defaultValue) { return sizeProperty.match( - [&] (const style::CompositeFunction<float>& function) -> std::unique_ptr<SymbolSizeBinder> { - return std::make_unique<CompositeFunctionSymbolSizeBinder>(tileZoom, function, defaultValue); - }, - [&] (const style::SourceFunction<float>& function) { - return std::make_unique<SourceFunctionSymbolSizeBinder>(tileZoom, function, defaultValue); + [&] (const Undefined& value) -> std::unique_ptr<SymbolSizeBinder> { + return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, value, defaultValue); }, - [&] (const auto& value) -> std::unique_ptr<SymbolSizeBinder> { + [&] (float value) -> std::unique_ptr<SymbolSizeBinder> { return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, value, defaultValue); + }, + [&] (const style::PropertyExpression<float>& expression) -> std::unique_ptr<SymbolSizeBinder> { + if (expression.isFeatureConstant()) { + return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, expression, defaultValue); + } else if (expression.isZoomConstant()) { + return std::make_unique<SourceFunctionSymbolSizeBinder>(tileZoom, expression, defaultValue); + } else { + return std::make_unique<CompositeFunctionSymbolSizeBinder>(tileZoom, expression, defaultValue); + } } ); } diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 51f9a48f7f..35b5821918 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -143,13 +143,13 @@ public: ConstantSymbolSizeBinder(const float /*tileZoom*/, const style::Undefined&, const float defaultValue) : layoutSize(defaultValue) {} - ConstantSymbolSizeBinder(const float tileZoom, const style::CameraFunction<float>& function_, const float /*defaultValue*/) - : layoutSize(function_.evaluate(tileZoom + 1)), - function(function_) { - const Range<float> zoomLevels = function_.getCoveringStops(tileZoom, tileZoom + 1); + ConstantSymbolSizeBinder(const float tileZoom, const style::PropertyExpression<float>& expression_, const float /*defaultValue*/) + : layoutSize(expression_.evaluate(tileZoom + 1)), + expression(expression_) { + const Range<float> zoomLevels = expression_.getCoveringStops(tileZoom, tileZoom + 1); coveringRanges = std::make_tuple( zoomLevels, - Range<float> { function_.evaluate(zoomLevels.min), function_.evaluate(zoomLevels.max) } + Range<float> { expression_.evaluate(zoomLevels.min), expression_.evaluate(zoomLevels.max) } ); } @@ -157,7 +157,7 @@ public: ZoomEvaluatedSize evaluateForZoom(float currentZoom) const override { float size = layoutSize; - bool isZoomConstant = !(coveringRanges || function); + bool isZoomConstant = !(coveringRanges || expression); if (coveringRanges) { // Even though we could get the exact value of the camera function // at z = currentZoom, we intentionally do not: instead, we interpolate @@ -167,12 +167,12 @@ public: const Range<float>& zoomLevels = std::get<0>(*coveringRanges); const Range<float>& sizeLevels = std::get<1>(*coveringRanges); float t = util::clamp( - function->interpolationFactor(zoomLevels, currentZoom), + expression->interpolationFactor(zoomLevels, currentZoom), 0.0f, 1.0f ); size = sizeLevels.min + t * (sizeLevels.max - sizeLevels.min); - } else if (function) { - size = function->evaluate(currentZoom); + } else if (expression) { + size = expression->evaluate(currentZoom); } const float unused = 0.0f; @@ -181,7 +181,7 @@ public: float layoutSize; optional<std::tuple<Range<float>, Range<float>>> coveringRanges; - optional<style::CameraFunction<float>> function; + optional<style::PropertyExpression<float>> expression; }; class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder { @@ -190,13 +190,13 @@ public: using VertexVector = gl::VertexVector<Vertex>; using VertexBuffer = gl::VertexBuffer<Vertex>; - SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, const style::SourceFunction<float>& function_, const float defaultValue_) - : function(function_), + SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, style::PropertyExpression<float> expression_, const float defaultValue_) + : expression(std::move(expression_)), defaultValue(defaultValue_) { } Range<float> getVertexSizeData(const GeometryTileFeature& feature) override { - const float size = function.evaluate(feature, defaultValue); + const float size = expression.evaluate(feature, defaultValue); return { size, size }; }; @@ -205,30 +205,30 @@ public: return { true, false, unused, unused, unused }; } - style::SourceFunction<float> function; + style::PropertyExpression<float> expression; const float defaultValue; }; class CompositeFunctionSymbolSizeBinder final : public SymbolSizeBinder { public: - CompositeFunctionSymbolSizeBinder(const float tileZoom, const style::CompositeFunction<float>& function_, const float defaultValue_) - : function(function_), + CompositeFunctionSymbolSizeBinder(const float tileZoom, style::PropertyExpression<float> expression_, const float defaultValue_) + : expression(std::move(expression_)), defaultValue(defaultValue_), layoutZoom(tileZoom + 1), - coveringZoomStops(function.getCoveringStops(tileZoom, tileZoom + 1)) + coveringZoomStops(expression.getCoveringStops(tileZoom, tileZoom + 1)) {} Range<float> getVertexSizeData(const GeometryTileFeature& feature) override { return { - function.evaluate(coveringZoomStops.min, feature, defaultValue), - function.evaluate(coveringZoomStops.max, feature, defaultValue) + expression.evaluate(coveringZoomStops.min, feature, defaultValue), + expression.evaluate(coveringZoomStops.max, feature, defaultValue) }; }; ZoomEvaluatedSize evaluateForZoom(float currentZoom) const override { float sizeInterpolationT = util::clamp( - function.interpolationFactor(coveringZoomStops, currentZoom), + expression.interpolationFactor(coveringZoomStops, currentZoom), 0.0f, 1.0f ); @@ -236,7 +236,7 @@ public: return { false, false, sizeInterpolationT, unused, unused }; } - style::CompositeFunction<float> function; + style::PropertyExpression<float> expression; const float defaultValue; float layoutZoom; Range<float> coveringZoomStops; 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; diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 64adf522a1..39e061d75a 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -66,29 +66,6 @@ static bool interpolatable(type::Type type) { ); } -static FunctionType functionType(type::Type type, const Convertible& value) { - auto typeValue = objectMember(value, "type"); - if (!typeValue) { - return interpolatable(type) ? FunctionType::Exponential : FunctionType::Interval; - } - - optional<std::string> string = toString(*typeValue); - if (!string) { - return FunctionType::Invalid; - } - - if (*string == "interval") - return FunctionType::Interval; - if (*string == "exponential" && interpolatable(type)) - return FunctionType::Exponential; - if (*string == "categorical") - return FunctionType::Categorical; - if (*string == "identity") - return FunctionType::Identity; - - return FunctionType::Invalid; -} - static optional<std::unique_ptr<Expression>> convertLiteral(type::Type type, const Convertible& value, Error& error) { return type.match( [&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> { @@ -426,106 +403,16 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(type::Ty return {}; } -optional<std::unique_ptr<Expression>> convertCameraFunctionToExpression(type::Type type, - const Convertible& value, - Error& error) { - if (!isObject(value)) { - error = { "function must be an object" }; - return {}; - } - - switch (functionType(type, value)) { - case FunctionType::Interval: - return convertIntervalFunction(type, value, error, zoom()); - case FunctionType::Exponential: - return convertExponentialFunction(type, value, error, zoom()); - default: - error = { "unsupported function type" }; - return {}; - } -} - -optional<std::unique_ptr<Expression>> convertSourceFunctionToExpression(type::Type type, - const Convertible& value, - Error& error) { - if (!isObject(value)) { - error = { "function must be an object" }; - return {}; - } - - auto propertyValue = objectMember(value, "property"); - if (!propertyValue) { - error = { "function must specify property" }; - return {}; - } - - auto property = toString(*propertyValue); - if (!property) { - error = { "function property must be a string" }; - return {}; - } - - switch (functionType(type, value)) { - case FunctionType::Interval: - return convertIntervalFunction(type, value, error, number(get(literal(*property)))); - case FunctionType::Exponential: - return convertExponentialFunction(type, value, error, number(get(literal(*property)))); - case FunctionType::Categorical: - return convertCategoricalFunction(type, value, error, *property); - case FunctionType::Identity: - return type.match( - [&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> { - return string(get(literal(*property))); - }, - [&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> { - return number(get(literal(*property))); - }, - [&] (const type::BooleanType&) -> optional<std::unique_ptr<Expression>> { - return boolean(get(literal(*property))); - }, - [&] (const type::ColorType&) -> optional<std::unique_ptr<Expression>> { - return toColor(get(literal(*property))); - }, - [&] (const type::Array& array) -> optional<std::unique_ptr<Expression>> { - return std::unique_ptr<Expression>( - std::make_unique<ArrayAssertion>(array, get(literal(*property)))); - }, - [&] (const auto&) -> optional<std::unique_ptr<Expression>> { - assert(false); // No properties use this type. - return {}; - } - ); - default: - error = { "unsupported function type" }; - return {}; - } -} - -template <class T> +template <class T, class Fn> optional<std::unique_ptr<Expression>> composite(type::Type type, const Convertible& value, Error& error, - std::unique_ptr<Expression> (*makeInnerExpression) (type::Type type, - double base, - const std::string& property, - std::map<T, std::unique_ptr<Expression>>)) { - auto propertyValue = objectMember(value, "property"); - if (!propertyValue) { - error = { "function must specify property" }; - return {}; - } - + const Fn& makeInnerExpression) { auto base = convertBase(value, error); if (!base) { return {}; } - auto propertyString = toString(*propertyValue); - if (!propertyString) { - error = { "function property must be a string" }; - return {}; - } - auto stopsValue = objectMember(value, "stops"); // Checked by caller. @@ -587,7 +474,7 @@ optional<std::unique_ptr<Expression>> composite(type::Type type, std::map<double, std::unique_ptr<Expression>> stops; for (auto& e : map) { - stops.emplace(e.first, makeInnerExpression(type, *base, *propertyString, std::move(e.second))); + stops.emplace(e.first, makeInnerExpression(type, *base, std::move(e.second))); } if (interpolatable(type)) { @@ -597,14 +484,83 @@ optional<std::unique_ptr<Expression>> composite(type::Type type, } } -optional<std::unique_ptr<Expression>> convertCompositeFunctionToExpression(type::Type type, - const Convertible& value, - Error& err) { +optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type type, + const Convertible& value, + Error& err) { if (!isObject(value)) { err = { "function must be an object" }; return {}; } + FunctionType functionType = FunctionType::Invalid; + + auto typeValue = objectMember(value, "type"); + if (!typeValue) { + functionType = interpolatable(type) ? FunctionType::Exponential : FunctionType::Interval; + } else { + optional<std::string> string = toString(*typeValue); + if (string) { + if (*string == "interval") + functionType = FunctionType::Interval; + if (*string == "exponential" && interpolatable(type)) + functionType = FunctionType::Exponential; + if (*string == "categorical") + functionType = FunctionType::Categorical; + if (*string == "identity") + functionType = FunctionType::Identity; + } + } + + if (!objectMember(value, "property")) { + // Camera function. + switch (functionType) { + case FunctionType::Interval: + return convertIntervalFunction(type, value, err, zoom()); + case FunctionType::Exponential: + return convertExponentialFunction(type, value, err, zoom()); + default: + err = { "unsupported function type" }; + return {}; + } + } + + auto propertyValue = objectMember(value, "property"); + if (!propertyValue) { + err = { "function must specify property" }; + return {}; + } + + auto property = toString(*propertyValue); + if (!property) { + err = { "function property must be a string" }; + return {}; + } + + if (functionType == FunctionType::Identity) { + return type.match( + [&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> { + return string(get(literal(*property))); + }, + [&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> { + return number(get(literal(*property))); + }, + [&] (const type::BooleanType&) -> optional<std::unique_ptr<Expression>> { + return boolean(get(literal(*property))); + }, + [&] (const type::ColorType&) -> optional<std::unique_ptr<Expression>> { + return toColor(get(literal(*property))); + }, + [&] (const type::Array& array) -> optional<std::unique_ptr<Expression>> { + return std::unique_ptr<Expression>( + std::make_unique<ArrayAssertion>(array, get(literal(*property)))); + }, + [&] (const auto&) -> optional<std::unique_ptr<Expression>> { + assert(false); // No properties use this type. + return {}; + } + ); + } + auto stopsValue = objectMember(value, "stops"); if (!stopsValue) { err = { "function value must specify stops" }; @@ -636,62 +592,73 @@ optional<std::unique_ptr<Expression>> convertCompositeFunctionToExpression(type: const auto& stop = arrayMember(first, 0); if (!isObject(stop)) { - err = { "stop must be an object" }; - return {}; - } - - auto sourceValue = objectMember(stop, "value"); - if (!sourceValue) { - err = { "stop must specify value" }; - return {}; - } - - if (toBool(*sourceValue)) { - switch (functionType(type, value)) { - case FunctionType::Categorical: - return composite<bool>(type, value, err, [] (type::Type type_, double, const std::string& property, std::map<bool, std::unique_ptr<Expression>> stops) { - return categorical<bool>(type_, property, std::move(stops)); - }); - default: - err = { "unsupported function type" }; - return {}; - } - } - - if (toNumber(*sourceValue)) { - switch (functionType(type, value)) { + // Source function. + switch (functionType) { case FunctionType::Interval: - return composite<double>(type, value, err, [] (type::Type type_, double, const std::string& property, std::map<double, std::unique_ptr<Expression>> stops) { - return step(type_, number(get(literal(property))), std::move(stops)); - }); + return convertIntervalFunction(type, value, err, number(get(literal(*property)))); case FunctionType::Exponential: - return composite<double>(type, value, err, [] (type::Type type_, double base, const std::string& property, std::map<double, std::unique_ptr<Expression>> stops) { - return interpolate(type_, exponential(base), number(get(literal(property))), std::move(stops)); - }); + return convertExponentialFunction(type, value, err, number(get(literal(*property)))); case FunctionType::Categorical: - return composite<int64_t>(type, value, err, [] (type::Type type_, double, const std::string& property, std::map<int64_t, std::unique_ptr<Expression>> stops) { - return categorical<int64_t>(type_, property, std::move(stops)); - }); + return convertCategoricalFunction(type, value, err, *property); default: err = { "unsupported function type" }; return {}; } - } - - if (toString(*sourceValue)) { - switch (functionType(type, value)) { - case FunctionType::Categorical: - return composite<std::string>(type, value, err, [] (type::Type type_, double, const std::string& property, std::map<std::string, std::unique_ptr<Expression>> stops) { - return categorical<std::string>(type_, property, std::move(stops)); - }); - default: - err = { "unsupported function type" }; + } else { + // Composite function. + auto sourceValue = objectMember(stop, "value"); + if (!sourceValue) { + err = { "stop must specify value" }; return {}; } - } - err = { "stop domain value must be a number, string, or boolean" }; - return {}; + if (toBool(*sourceValue)) { + switch (functionType) { + case FunctionType::Categorical: + return composite<bool>(type, value, err, [&] (type::Type type_, double, std::map<bool, std::unique_ptr<Expression>> stops) { + return categorical<bool>(type_, *property, std::move(stops)); + }); + default: + err = { "unsupported function type" }; + return {}; + } + } + + if (toNumber(*sourceValue)) { + switch (functionType) { + case FunctionType::Interval: + return composite<double>(type, value, err, [&] (type::Type type_, double, std::map<double, std::unique_ptr<Expression>> stops) { + return step(type_, number(get(literal(*property))), std::move(stops)); + }); + case FunctionType::Exponential: + return composite<double>(type, value, err, [&] (type::Type type_, double base, std::map<double, std::unique_ptr<Expression>> stops) { + return interpolate(type_, exponential(base), number(get(literal(*property))), std::move(stops)); + }); + case FunctionType::Categorical: + return composite<int64_t>(type, value, err, [&] (type::Type type_, double, std::map<int64_t, std::unique_ptr<Expression>> stops) { + return categorical<int64_t>(type_, *property, std::move(stops)); + }); + default: + err = { "unsupported function type" }; + return {}; + } + } + + if (toString(*sourceValue)) { + switch (functionType) { + case FunctionType::Categorical: + return composite<std::string>(type, value, err, [&] (type::Type type_, double, std::map<std::string, std::unique_ptr<Expression>> stops) { + return categorical<std::string>(type_, *property, std::move(stops)); + }); + default: + err = { "unsupported function type" }; + return {}; + } + } + + err = { "stop domain value must be a number, string, or boolean" }; + return {}; + } } } // namespace conversion diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index 74171763a0..77a39c51f9 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -138,17 +138,7 @@ void stringify(Writer& writer, const Undefined&) { } template <class Writer, class T> -void stringify(Writer& writer, const CameraFunction<T>& fn) { - stringify(writer, fn.getExpression().serialize()); -} - -template <class Writer, class T> -void stringify(Writer& writer, const SourceFunction<T>& fn) { - stringify(writer, fn.getExpression().serialize()); -} - -template <class Writer, class T> -void stringify(Writer& writer, const CompositeFunction<T>& fn) { +void stringify(Writer& writer, const PropertyExpression<T>& fn) { stringify(writer, fn.getExpression().serialize()); } diff --git a/src/mbgl/style/expression/find_zoom_curve.cpp b/src/mbgl/style/expression/find_zoom_curve.cpp index ce8487a3af..1e0a936605 100644 --- a/src/mbgl/style/expression/find_zoom_curve.cpp +++ b/src/mbgl/style/expression/find_zoom_curve.cpp @@ -2,6 +2,7 @@ #include <mbgl/style/expression/compound_expression.hpp> #include <mbgl/style/expression/let.hpp> #include <mbgl/style/expression/coalesce.hpp> +#include <mbgl/style/expression/is_constant.hpp> #include <mbgl/util/variant.hpp> #include <mbgl/util/optional.hpp> @@ -59,14 +60,17 @@ optional<variant<const Interpolate*, const Step*, ParsingError>> findZoomCurve(c return result; } -variant<const Interpolate*, const Step*> findZoomCurveChecked(const expression::Expression* e) { +variant<std::nullptr_t, const Interpolate*, const Step*> findZoomCurveChecked(const expression::Expression* e) { + if (isZoomConstant(*e)) { + return nullptr; + } return findZoomCurve(e)->match( - [](const ParsingError&) -> variant<const Interpolate*, const Step*> { + [](const ParsingError&) -> variant<std::nullptr_t, const Interpolate*, const Step*> { assert(false); - return {}; + return nullptr; }, - [](auto zoomCurve) -> variant<const Interpolate*, const Step*> { - return {std::move(zoomCurve)}; + [](auto zoomCurve) -> variant<std::nullptr_t, const Interpolate*, const Step*> { + return zoomCurve; } ); } diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index dfcf7993a7..9206e96982 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -154,10 +154,7 @@ public: [&] (const T& t) { return t; }, - [&] (const SourceFunction<T>& t) { - return t.evaluate(feature, defaultValue); - }, - [&] (const CompositeFunction<T>& t) { + [&] (const PropertyExpression<T>& t) { return t.evaluate(z, feature, defaultValue); }); } diff --git a/test/fixtures/style_parser/expressions.info.json b/test/fixtures/style_parser/expressions.info.json index 9e1765ecd0..4649227934 100644 --- a/test/fixtures/style_parser/expressions.info.json +++ b/test/fixtures/style_parser/expressions.info.json @@ -5,7 +5,7 @@ [1, "WARNING", "ParseStyle", "[2]: Expected number but found string instead."], [1, "WARNING", "ParseStyle", "\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression."], [1, "WARNING", "ParseStyle", "value must be a string"], - [1, "WARNING", "ParseStyle", "property expressions not supported"], + [1, "WARNING", "ParseStyle", "data expressions not supported"], [1, "WARNING", "ParseStyle", "Type array<number> is not interpolatable."] ] } diff --git a/test/programs/symbol_program.test.cpp b/test/programs/symbol_program.test.cpp index ed709a4ba7..b2467d5998 100644 --- a/test/programs/symbol_program.test.cpp +++ b/test/programs/symbol_program.test.cpp @@ -13,7 +13,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 12.0f); - binder = SymbolSizeBinder::create(1.0f, style::CameraFunction<float>( + binder = SymbolSizeBinder::create(1.0f, style::PropertyExpression<float>( interpolate( linear(), zoom(), @@ -24,7 +24,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 9.5f); - binder = SymbolSizeBinder::create(0.0f, style::CameraFunction<float>( + binder = SymbolSizeBinder::create(0.0f, style::PropertyExpression<float>( interpolate( linear(), zoom(), @@ -35,7 +35,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 8.0f); - binder = SymbolSizeBinder::create(12.0f, style::CameraFunction<float>( + binder = SymbolSizeBinder::create(12.0f, style::PropertyExpression<float>( interpolate( linear(), zoom(), @@ -46,7 +46,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 18.0f); - binder = SymbolSizeBinder::create(0.0f, style::SourceFunction<float>( + binder = SymbolSizeBinder::create(0.0f, style::PropertyExpression<float>( interpolate( linear(), number(get("x")), @@ -56,7 +56,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, true); EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, false); - binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction<float>( + binder = SymbolSizeBinder::create(5.0f, style::PropertyExpression<float>( interpolate( linear(), zoom(), diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index a48be2c075..fa89576afa 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -2,9 +2,8 @@ #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/constant.hpp> -#include <mbgl/style/conversion/function.hpp> +#include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/data_driven_property_value.hpp> -#include <mbgl/util/rapidjson.hpp> using namespace mbgl; using namespace mbgl::style; @@ -14,7 +13,7 @@ TEST(StyleConversion, Function) { Error error; auto parseFunction = [&](const std::string& json) { - return convertJSON<CameraFunction<float>>(json, error); + return convertJSON<PropertyValue<float>>(json, error); }; auto fn1 = parseFunction(R"({"stops":[]})"); @@ -46,7 +45,7 @@ TEST(StyleConversion, Function) { auto fn8 = parseFunction("[]"); ASSERT_FALSE(fn8); - ASSERT_EQ("function must be an object", error.message); + ASSERT_EQ("value must be a number", error.message); auto fn9 = parseFunction(R"({"stops":[[0,0]],"base":false})"); ASSERT_FALSE(fn9); @@ -56,10 +55,8 @@ TEST(StyleConversion, Function) { TEST(StyleConversion, CompositeFunctionExpression) { Error error; - auto parseFunction = [&](const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); - return convert<DataDrivenPropertyValue<float>>(doc, error); + auto parseFunction = [&](const std::string& json) { + return convertJSON<DataDrivenPropertyValue<float>>(json, error); }; auto fn1 = parseFunction(R"(["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10])"); @@ -71,7 +68,7 @@ TEST(StyleConversion, CompositeFunctionExpression) { auto fn3 = parseFunction(R"(["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10] ])"); ASSERT_TRUE(fn3); - auto fn4 = parseFunction(R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10], 0 ])"); + auto fn4 = parseFunction(R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10]], 0])"); ASSERT_TRUE(fn4); auto fn5 = parseFunction(R"(["coalesce", ["interpolate", ["linear"], ["number", ["get", "x"]], 0, ["zoom"], 10, 10], 0])"); diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp index 67e48c942e..f111e40ff3 100644 --- a/test/style/conversion/light.test.cpp +++ b/test/style/conversion/light.test.cpp @@ -32,22 +32,23 @@ TEST(StyleConversion, Light) { ASSERT_TRUE(light->getAnchor().isUndefined()); ASSERT_FALSE(light->getAnchor().isConstant()); - ASSERT_FALSE(light->getAnchor().isCameraFunction()); + ASSERT_FALSE(light->getAnchor().isExpression()); ASSERT_FALSE(light->getIntensity().isUndefined()); ASSERT_TRUE(light->getIntensity().isConstant()); ASSERT_EQ(light->getIntensity().asConstant(), 0.3f); - ASSERT_FALSE(light->getAnchor().isCameraFunction()); + ASSERT_FALSE(light->getIntensity().isExpression()); ASSERT_FALSE(light->getColor().isUndefined()); ASSERT_FALSE(light->getColor().isConstant()); - ASSERT_TRUE(light->getColor().isCameraFunction()); + ASSERT_TRUE(light->getColor().isExpression()); + ASSERT_FALSE(light->getColor().asExpression().isZoomConstant()); ASSERT_FALSE(light->getPosition().isUndefined()); ASSERT_TRUE(light->getPosition().isConstant()); std::array<float, 3> expected{{ 3, 90, 90 }}; ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({ expected })); - ASSERT_FALSE(light->getPosition().isCameraFunction()); + ASSERT_FALSE(light->getPosition().isExpression()); } { @@ -56,7 +57,7 @@ TEST(StyleConversion, Light) { ASSERT_FALSE(light->getColor().isUndefined()); ASSERT_TRUE(light->getColor().isConstant()); - ASSERT_FALSE(light->getColor().isCameraFunction()); + ASSERT_FALSE(light->getColor().isExpression()); ASSERT_EQ(light->getColorTransition().duration, mbgl::Duration(mbgl::Milliseconds(1000))); ASSERT_FALSE((bool) light->getColorTransition().delay); } diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index bc73b0cedb..8bc78098cd 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -82,9 +82,9 @@ TEST(Stringify, Filter) { ASSERT_EQ(stringify(Filter(eq(literal("a"), literal("b")))), "[\"==\",\"a\",\"b\"]"); } -TEST(Stringify, CameraFunction) { +TEST(Stringify, PropertyExpression) { using namespace mbgl::style::expression::dsl; - ASSERT_EQ(stringify(CameraFunction<float>( + ASSERT_EQ(stringify(PropertyExpression<float>( interpolate( linear(), zoom(), @@ -92,11 +92,8 @@ TEST(Stringify, CameraFunction) { 1.0, literal(2.0) ))), "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0,1.0,2.0]"); -} -TEST(Stringify, SourceFunction) { - using namespace mbgl::style::expression::dsl; - ASSERT_EQ(stringify(SourceFunction<float>( + ASSERT_EQ(stringify(PropertyExpression<float>( interpolate( exponential(2.0), number(get("property")), @@ -104,11 +101,8 @@ TEST(Stringify, SourceFunction) { 1.0, literal(2.0) ))), "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]"); -} -TEST(Stringify, CompositeFunction) { - using namespace mbgl::style::expression::dsl; - ASSERT_EQ(stringify(CompositeFunction<float>( + ASSERT_EQ(stringify(PropertyExpression<float>( interpolate( linear(), zoom(), @@ -125,7 +119,7 @@ TEST(Stringify, CompositeFunction) { TEST(Stringify, PropertyValue) { using namespace mbgl::style::expression::dsl; ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0"); - ASSERT_EQ(stringify(PropertyValue<float>(CameraFunction<float>( + ASSERT_EQ(stringify(PropertyValue<float>(PropertyExpression<float>( interpolate( exponential(2.0), zoom(), diff --git a/test/style/function/camera_function.test.cpp b/test/style/function/camera_function.test.cpp deleted file mode 100644 index 1f7e81fc2c..0000000000 --- a/test/style/function/camera_function.test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include <iostream> -#include <mbgl/test/util.hpp> - -#include <mbgl/renderer/property_evaluator.hpp> -#include <mbgl/renderer/property_evaluation_parameters.hpp> -#include <mbgl/style/expression/dsl.hpp> - -using namespace mbgl; -using namespace mbgl::style; -using namespace mbgl::style::expression::dsl; - -float evaluate(PropertyValue<float> value, float zoom) { - return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0)); -} - -TEST(CameraFunction, Constant) { - EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0)); - EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 0)); - EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 0)); - EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 4)); - EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 4)); - EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 4)); - EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 22)); - EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 22)); - EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 22)); -} - -TEST(CameraFunction, Expression) { - CameraFunction<float> function(interpolate(linear(), zoom(), 0.0, literal(0.0), 1.0, literal(1.0))); - EXPECT_EQ(0.0, evaluate(function, 0.0)); - EXPECT_EQ(0.5, evaluate(function, 0.5)); -} diff --git a/test/style/function/source_function.test.cpp b/test/style/function/source_function.test.cpp deleted file mode 100644 index d1e5e1a974..0000000000 --- a/test/style/function/source_function.test.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include <mbgl/test/util.hpp> -#include <mbgl/test/stub_geometry_tile_feature.hpp> - -#include <mbgl/style/function/source_function.hpp> -#include <mbgl/style/expression/dsl.hpp> - -using namespace mbgl; -using namespace mbgl::style; - -using namespace std::string_literals; - -static StubGeometryTileFeature oneInteger { - PropertyMap {{ "property", uint64_t(1) }} -}; - -static StubGeometryTileFeature oneDouble { - PropertyMap {{ "property", 1.0 }} -}; - -static StubGeometryTileFeature oneString { - PropertyMap {{ "property", "1"s }} -}; - -TEST(SourceFunction, Defaults) { - using namespace mbgl::style::expression::dsl; - - EXPECT_EQ(1.0f, SourceFunction<float>(number(get("property")), 0.0) - .evaluate(oneInteger, 2.0f)); - EXPECT_EQ(1.0f, SourceFunction<float>(number(get("property")), 0.0) - .evaluate(oneDouble, 2.0f)); - EXPECT_EQ(0.0f, SourceFunction<float>(number(get("property")), 0.0) - .evaluate(oneString, 2.0f)); - EXPECT_EQ(2.0f, SourceFunction<float>(number(get("property"))) - .evaluate(oneString, 2.0f)); -} diff --git a/test/style/properties.test.cpp b/test/style/properties.test.cpp index 4d63f7e671..ef064ccba2 100644 --- a/test/style/properties.test.cpp +++ b/test/style/properties.test.cpp @@ -123,10 +123,10 @@ TEST(TransitioningDataDrivenPropertyValue, Evaluate) { }; using namespace mbgl::style::expression::dsl; - SourceFunction<float> sourceFunction(number(get("property_name"))); + PropertyExpression<float> expression(number(get("property_name"))); Transitioning<DataDrivenPropertyValue<float>> t1 { - DataDrivenPropertyValue<float>(sourceFunction), + DataDrivenPropertyValue<float>(expression), t0, transition, TimePoint::min() diff --git a/test/style/function/composite_function.test.cpp b/test/style/property_expression.test.cpp index 917689ce23..e4ee5f115f 100644 --- a/test/style/function/composite_function.test.cpp +++ b/test/style/property_expression.test.cpp @@ -1,7 +1,9 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_geometry_tile_feature.hpp> -#include <mbgl/style/function/composite_function.hpp> +#include <mbgl/style/property_expression.hpp> +#include <mbgl/renderer/property_evaluator.hpp> +#include <mbgl/renderer/property_evaluation_parameters.hpp> #include <mbgl/style/expression/dsl.hpp> using namespace mbgl; @@ -14,8 +16,49 @@ static StubGeometryTileFeature oneInteger { PropertyMap {{ "property", uint64_t(1) }} }; -TEST(CompositeFunction, ZoomInterpolation) { - EXPECT_EQ(40.0f, CompositeFunction<float>( +static StubGeometryTileFeature oneDouble { + PropertyMap {{ "property", 1.0 }} +}; + +static StubGeometryTileFeature oneString { + PropertyMap {{ "property", "1"s }} +}; + +float evaluate(PropertyValue<float> value, float zoom) { + return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0)); +} + +TEST(PropertyExpression, Constant) { + EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0)); + EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 0)); + EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 0)); + EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 4)); + EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 4)); + EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 4)); + EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 22)); + EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 22)); + EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 22)); +} + +TEST(PropertyExpression, Expression) { + PropertyExpression<float> expression(interpolate(linear(), zoom(), 0.0, literal(0.0), 1.0, literal(1.0))); + EXPECT_EQ(0.0, evaluate(expression, 0.0)); + EXPECT_EQ(0.5, evaluate(expression, 0.5)); +} + +TEST(PropertyExpression, Defaults) { + EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0) + .evaluate(oneInteger, 2.0f)); + EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0) + .evaluate(oneDouble, 2.0f)); + EXPECT_EQ(0.0f, PropertyExpression<float>(number(get("property")), 0.0) + .evaluate(oneString, 2.0f)); + EXPECT_EQ(2.0f, PropertyExpression<float>(number(get("property"))) + .evaluate(oneString, 2.0f)); +} + +TEST(PropertyExpression, ZoomInterpolation) { + EXPECT_EQ(40.0f, PropertyExpression<float>( interpolate(linear(), zoom(), 0.0, interpolate(linear(), number(get("property")), 1.0, literal(24.0)), 1.5, interpolate(linear(), number(get("property")), 1.0, literal(36.0)), @@ -23,28 +66,28 @@ TEST(CompositeFunction, ZoomInterpolation) { ), 0.0f) .evaluate(2.0f, oneInteger, -1.0f)) << "Should interpolate between stops"; - EXPECT_EQ(33.0, CompositeFunction<float>( + EXPECT_EQ(33.0, PropertyExpression<float>( interpolate(linear(), zoom(), 5.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)), 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0)) ), 0.0f) .evaluate(0.0f, oneInteger, -1.0f)) << "Use first stop output for input values from -inf to first stop"; - EXPECT_EQ(66.0, CompositeFunction<float>( + EXPECT_EQ(66.0, PropertyExpression<float>( interpolate(linear(), zoom(), 0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)), 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0)) ), 0.0f) .evaluate(20.0f, oneInteger, -1.0f)) << "Use last stop output for input values from last stop to +inf"; - EXPECT_EQ(66.0f, CompositeFunction<float>( + EXPECT_EQ(66.0f, PropertyExpression<float>( interpolate(linear(), zoom(), 0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)), 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0)) ), 0.0f) .evaluate(10.0f, oneInteger, -1.0f)) << "Should interpolate TO the last stop."; - EXPECT_EQ(33.0f, CompositeFunction<float>( + EXPECT_EQ(33.0f, PropertyExpression<float>( interpolate(linear(), zoom(), 0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)), 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0)) @@ -52,8 +95,8 @@ TEST(CompositeFunction, ZoomInterpolation) { .evaluate(0.0f, oneInteger, -1.0f)) << "Should interpolate TO the first stop"; } -TEST(CompositeFunction, Issue8460) { - CompositeFunction<float> fn1( +TEST(PropertyExpression, Issue8460) { + PropertyExpression<float> fn1( interpolate(linear(), zoom(), 15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)), 15.2, interpolate(linear(), number(get("property")), 1.0, literal(600.0)) @@ -64,7 +107,7 @@ TEST(CompositeFunction, Issue8460) { EXPECT_NEAR(600.0f, fn1.evaluate(15.2f, oneInteger, -1.0f), 0.00); EXPECT_NEAR(600.0f, fn1.evaluate(16.0f, oneInteger, -1.0f), 0.00); - CompositeFunction<float> fn2( + PropertyExpression<float> fn2( interpolate(linear(), zoom(), 15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)), 15.2, interpolate(linear(), number(get("property")), 1.0, literal(300.0)), |