From 2e5530519e6a56dde019618262ea6ce5c10c72f5 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 13 Jul 2018 18:14:12 -0700 Subject: [PATCH] [core] Replace {Source,Camera,Composite}Function with PropertyExpression --- .../function/camera_function.benchmark.cpp | 8 +- .../function/composite_function.benchmark.cpp | 9 +- .../function/source_function.benchmark.cpp | 10 +- cmake/core-files.cmake | 4 +- cmake/test-files.cmake | 6 +- .../mbgl/style/color_ramp_property_value.hpp | 2 +- .../conversion/color_ramp_property_value.hpp | 2 - .../conversion/data_driven_property_value.hpp | 64 ++-- include/mbgl/style/conversion/function.hpp | 66 +--- .../mbgl/style/conversion/property_value.hpp | 49 +-- .../mbgl/style/data_driven_property_value.hpp | 40 +-- .../mbgl/style/expression/find_zoom_curve.hpp | 2 +- .../mbgl/style/function/camera_function.hpp | 70 ----- .../mbgl/style/function/source_function.hpp | 52 --- ...e_function.hpp => property_expression.hpp} | 87 +++-- include/mbgl/style/property_value.hpp | 23 +- platform/android/config.cmake | 2 +- .../android/src/style/conversion/function.hpp | 51 --- .../style/conversion/property_expression.hpp | 31 ++ .../src/style/conversion/property_value.hpp | 14 +- platform/darwin/src/MGLStyleValue_Private.h | 10 +- .../test/MGLBackgroundStyleLayerTests.mm | 6 +- .../darwin/test/MGLCircleStyleLayerTests.mm | 50 +-- .../test/MGLFillExtrusionStyleLayerTests.mm | 26 +- .../darwin/test/MGLFillStyleLayerTests.mm | 26 +- .../darwin/test/MGLHeatmapStyleLayerTests.mm | 16 +- .../test/MGLHillshadeStyleLayerTests.mm | 12 +- .../darwin/test/MGLLineStyleLayerTests.mm | 52 +-- .../darwin/test/MGLRasterStyleLayerTests.mm | 16 +- .../darwin/test/MGLStyleLayerTests.mm.ejs | 6 +- .../darwin/test/MGLSymbolStyleLayerTests.mm | 172 +++++----- platform/glfw/glfw_view.cpp | 6 +- src/mbgl/programs/symbol_program.cpp | 18 +- src/mbgl/programs/symbol_program.hpp | 42 +-- .../cross_faded_property_evaluator.cpp | 8 +- .../cross_faded_property_evaluator.hpp | 2 +- .../data_driven_property_evaluator.hpp | 19 +- src/mbgl/renderer/paint_property_binder.hpp | 33 +- .../possibly_evaluated_property_value.hpp | 23 +- src/mbgl/renderer/property_evaluator.hpp | 2 +- src/mbgl/style/conversion/function.cpp | 297 ++++++++---------- src/mbgl/style/conversion/stringify.hpp | 12 +- src/mbgl/style/expression/find_zoom_curve.cpp | 14 +- src/mbgl/style/properties.hpp | 5 +- .../style_parser/expressions.info.json | 2 +- test/programs/symbol_program.test.cpp | 10 +- test/style/conversion/function.test.cpp | 15 +- test/style/conversion/light.test.cpp | 11 +- test/style/conversion/stringify.test.cpp | 16 +- test/style/function/camera_function.test.cpp | 32 -- test/style/function/source_function.test.cpp | 35 --- test/style/properties.test.cpp | 4 +- ....test.cpp => property_expression.test.cpp} | 63 +++- 53 files changed, 702 insertions(+), 951 deletions(-) delete mode 100644 include/mbgl/style/function/camera_function.hpp delete mode 100644 include/mbgl/style/function/source_function.hpp rename include/mbgl/style/{function/composite_function.hpp => property_expression.hpp} (52%) delete mode 100644 platform/android/src/style/conversion/function.hpp create mode 100644 platform/android/src/style/conversion/property_expression.hpp delete mode 100644 test/style/function/camera_function.test.cpp delete mode 100644 test/style/function/source_function.test.cpp rename test/style/{function/composite_function.test.cpp => property_expression.test.cpp} (60%) diff --git a/benchmark/function/camera_function.benchmark.cpp b/benchmark/function/camera_function.benchmark.cpp index 26de5701db1..52b6bc9f08e 100644 --- a/benchmark/function/camera_function.benchmark.cpp +++ b/benchmark/function/camera_function.benchmark.cpp @@ -1,9 +1,9 @@ #include -#include #include #include #include +#include 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> result = conversion::convertJSON>(doc, error); + optional> result = conversion::convertJSON>(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> function = conversion::convertJSON>(doc, error); + optional> function = conversion::convertJSON>(doc, error); if (!function) { state.SkipWithError(error.message.c_str()); } while(state.KeepRunning()) { float z = 24.0f * static_cast(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 8442e0aa153..77258669a5d 100644 --- a/benchmark/function/composite_function.benchmark.cpp +++ b/benchmark/function/composite_function.benchmark.cpp @@ -2,11 +2,10 @@ #include -#include - #include #include #include +#include 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> result = conversion::convertJSON>(doc, error); + optional> result = conversion::convertJSON>(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> function = conversion::convertJSON>(doc, error); + optional> function = conversion::convertJSON>(doc, error); if (!function) { state.SkipWithError(error.message.c_str()); } while(state.KeepRunning()) { float z = 24.0f * static_cast(rand() % 100) / 100; - function->evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast(rand() % 100) } }), -1.0f); + function->asExpression().evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast(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 af361943e39..402c9b89d24 100644 --- a/benchmark/function/source_function.benchmark.cpp +++ b/benchmark/function/source_function.benchmark.cpp @@ -2,11 +2,9 @@ #include -#include - #include #include -#include +#include 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> result = conversion::convertJSON>(doc, error); + optional> result = conversion::convertJSON>(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> function = conversion::convertJSON>(doc, error); + optional> function = conversion::convertJSON>(doc, error); if (!function) { state.SkipWithError(error.message.c_str()); } while(state.KeepRunning()) { - function->evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast(rand() % 100) } }), -1.0f); + function->asExpression().evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast(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 204bb78bce8..2aae6e4573b 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 5d76ffcadec..1961d78dfc7 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 3e93285d5ac..bc5639c8995 100644 --- a/include/mbgl/style/color_ramp_property_value.hpp +++ b/include/mbgl/style/color_ramp_property_value.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include 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 cf5d5e55d99..9394daa0504 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 #include #include -#include #include #include #include -#include #include 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 07ed201c995..363134bd3ee 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 #include #include -#include #include #include #include -#include - - namespace mbgl { namespace style { namespace conversion { template struct Converter> { - optional> operator()(const Convertible& value, Error& error) const { using namespace mbgl::style::expression; - + if (isUndefined(value)) { return DataDrivenPropertyValue(); - } else if (isExpression(value)) { + } + + optional> expression; + + if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType()); - 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(CameraFunction(std::move(*expression))); - } else if (!featureConstant && zoomConstant) { - return DataDrivenPropertyValue(SourceFunction(std::move(*expression))); - } else if (!featureConstant && !zoomConstant) { - return DataDrivenPropertyValue(CompositeFunction(std::move(*expression))); - } else { - auto literal = dynamic_cast(expression->get()); - assert(literal); - optional constant = fromExpressionValue(literal->getValue()); - if (!constant) { - return {}; - } - return DataDrivenPropertyValue(*constant); - } - } else if (!isObject(value)) { + expression = PropertyExpression(std::move(*parsed)); + } else if (isObject(value)) { + expression = convertFunctionToExpression(value, error); + } else { optional constant = convert(value, error); if (!constant) { return {}; } return DataDrivenPropertyValue(*constant); - } else if (!objectMember(value, "property")) { - optional> function = convert>(value, error); - if (!function) { - return {}; - } - return DataDrivenPropertyValue(*function); + } + + if (!expression) { + return {}; + } else if (!(*expression).isFeatureConstant() || !(*expression).isZoomConstant()) { + return { std::move(*expression) }; } else { - optional> composite = convert>(value, error); - if (composite) { - return DataDrivenPropertyValue(*composite); - } - optional> source = convert>(value, error); - if (!source) { + optional constant = fromExpressionValue( + dynamic_cast((*expression).getExpression()).getValue()); + if (!constant) { return {}; } - return DataDrivenPropertyValue(*source); + return DataDrivenPropertyValue(*constant); } } }; diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 5ddede324b0..6bc75d71414 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -1,8 +1,6 @@ #pragma once -#include -#include -#include +#include #include #include #include @@ -12,66 +10,28 @@ namespace mbgl { namespace style { namespace conversion { -template -optional> convertDefaultValue(const Convertible& value, Error& error) { - auto defaultValueValue = objectMember(value, "default"); - if (!defaultValueValue) { - return optional(); - } +optional> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&); - auto defaultValue = convert(*defaultValueValue, error); - if (!defaultValue) { - error = { R"(wrong type for "default": )" + error.message }; +template +optional> convertFunctionToExpression(const Convertible& value, Error& error) { + auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType(), value, error); + if (!expression) { return {}; } - return { *defaultValue }; -} - -optional> convertCameraFunctionToExpression(expression::type::Type, const Convertible&, Error&); -optional> convertSourceFunctionToExpression(expression::type::Type, const Convertible&, Error&); -optional> convertCompositeFunctionToExpression(expression::type::Type, const Convertible&, Error&); + optional defaultValue; -template -struct Converter> { - optional> operator()(const Convertible& value, Error& error) const { - auto expression = convertCameraFunctionToExpression(expression::valueTypeToExpressionType(), value, error); - if (!expression) { - return {}; - } - return CameraFunction(std::move(*expression), false); - } -}; - -template -struct Converter> { - optional> operator()(const Convertible& value, Error& error) const { - auto expression = convertSourceFunctionToExpression(expression::valueTypeToExpressionType(), value, error); - if (!expression) { - return {}; - } - auto defaultValue = convertDefaultValue(value, error); + auto defaultValueValue = objectMember(value, "default"); + if (defaultValueValue) { + defaultValue = convert(*defaultValueValue, error); if (!defaultValue) { + error = { R"(wrong type for "default": )" + error.message }; return {}; } - return SourceFunction(std::move(*expression), *defaultValue); } -}; -template -struct Converter> { - optional> operator()(const Convertible& value, Error& error) const { - auto expression = convertCompositeFunctionToExpression(expression::valueTypeToExpressionType(), value, error); - if (!expression) { - return {}; - } - auto defaultValue = convertDefaultValue(value, error); - if (!defaultValue) { - return {}; - } - return CompositeFunction(std::move(*expression), *defaultValue); - } -}; + return PropertyExpression(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 e52c63d0234..2256cfffb4e 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -22,34 +21,20 @@ struct Converter> { if (isUndefined(value)) { return PropertyValue(); - } else if (isExpression(value)) { + } + + optional> expression; + + if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType()); - 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(std::move(*expression)) }; - } else { - auto literal = dynamic_cast(expression->get()); - assert(literal); - optional constant = fromExpressionValue(literal->getValue()); - if (!constant) { - return {}; - } - return PropertyValue(*constant); - } + expression = PropertyExpression(std::move(*parsed)); } else if (isObject(value)) { - optional> function = convert>(value, error); - if (!function) { - return {}; - } - return { *function }; + expression = convertFunctionToExpression(value, error); } else { optional constant = convert(value, error); if (!constant) { @@ -57,6 +42,22 @@ struct Converter> { } 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 constant = fromExpressionValue( + dynamic_cast((*expression).getExpression()).getValue()); + if (!constant) { + return {}; + } + return PropertyValue(*constant); + } } }; diff --git a/include/mbgl/style/data_driven_property_value.hpp b/include/mbgl/style/data_driven_property_value.hpp index 0a1fce29c74..a95eaa4ea88 100644 --- a/include/mbgl/style/data_driven_property_value.hpp +++ b/include/mbgl/style/data_driven_property_value.hpp @@ -2,9 +2,7 @@ #include #include -#include -#include -#include +#include namespace mbgl { namespace style { @@ -15,9 +13,7 @@ class DataDrivenPropertyValue { using Value = variant< Undefined, T, - CameraFunction, - SourceFunction, - CompositeFunction>; + PropertyExpression>; Value value; @@ -33,32 +29,40 @@ class DataDrivenPropertyValue { public: DataDrivenPropertyValue() = default; - DataDrivenPropertyValue( T v) : value(std::move(v)) {} - DataDrivenPropertyValue( CameraFunction v) : value(std::move(v)) {} - DataDrivenPropertyValue( SourceFunction v) : value(std::move(v)) {} - DataDrivenPropertyValue(CompositeFunction v) : value(std::move(v)) {} + DataDrivenPropertyValue( T v) : value(std::move(v)) {} + DataDrivenPropertyValue(PropertyExpression v) : value(std::move(v)) {} bool isUndefined() const { return value.template is(); } bool isDataDriven() const { - return value.template is>() || value.template is>(); + return value.match( + [] (const Undefined&) { return false; }, + [] (const T&) { return false; }, + [] (const PropertyExpression& fn) { return !fn.isFeatureConstant(); } + ); } - + bool isZoomConstant() const { - return !value.template is>() && !value.template is>(); + return value.match( + [] (const Undefined&) { return true; }, + [] (const T&) { return true; }, + [] (const PropertyExpression& fn) { return fn.isZoomConstant(); } + ); } bool isExpression() const { return value.match( - [] (const Undefined&) { return false; }, - [] (const T&) { return false; }, - [] (const CameraFunction& fn) { return fn.isExpression; }, - [] (const SourceFunction& fn) { return fn.isExpression; }, - [] (const CompositeFunction& fn) { return fn.isExpression; }); + [] (const Undefined&) { return false; }, + [] (const T&) { return false; }, + [] (const PropertyExpression& fn) { return fn.isExpression; } + ); } + const T & asConstant() const { return value.template get< T >(); } + const PropertyExpression& asExpression() const { return value.template get>(); } + template auto match(Ts&&... ts) const { return value.match(std::forward(ts)...); diff --git a/include/mbgl/style/expression/find_zoom_curve.hpp b/include/mbgl/style/expression/find_zoom_curve.hpp index 1e19436dd90..6f1419a69fc 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> findZoomCurve(const expression::Expression* e); -variant findZoomCurveChecked(const expression::Expression* e); +variant 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 65b7991849d..00000000000 --- a/include/mbgl/style/function/camera_function.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace mbgl { -namespace style { - -template -class CameraFunction { -public: - // The second parameter should be used only for conversions from legacy functions. - CameraFunction(std::unique_ptr 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 typed = expression::fromExpressionValue(*result); - return typed ? *typed : T(); - } - return T(); - } - - float interpolationFactor(const Range& inputLevels, const float inputValue) const { - return zoomCurve.match( - [&](const expression::Interpolate* z) { - return z->interpolationFactor(Range { inputLevels.min, inputLevels.max }, inputValue); - }, - [&](const expression::Step*) { return 0.0f; } - ); - } - - Range getCoveringStops(const float lower, const float upper) const { - return zoomCurve.match( - [&](auto z) { return z->getCoveringStops(lower, upper); } - ); - } - - std::vector> possibleOutputs() const { - return expression::fromExpressionValues(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 expression; - const variant 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 a83e73a5d05..00000000000 --- a/include/mbgl/style/function/source_function.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { -namespace style { - -template -class SourceFunction { -public: - // The second parameter should be used only for conversions from legacy functions. - SourceFunction(std::unique_ptr expression_, optional defaultValue_ = {}) - : isExpression(defaultValue_), - expression(std::move(expression_)), - defaultValue(std::move(defaultValue_)) { - assert(expression::isZoomConstant(*expression)); - assert(!expression::isFeatureConstant(*expression)); - } - - template - T evaluate(const Feature& feature, T finalDefaultValue) const { - const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature)); - if (result) { - const optional typed = expression::fromExpressionValue(*result); - return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue; - } - return defaultValue ? *defaultValue : finalDefaultValue; - } - - std::vector> possibleOutputs() const { - return expression::fromExpressionValues(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 expression; - optional defaultValue; -}; - -} // namespace style -} // namespace mbgl diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/property_expression.hpp similarity index 52% rename from include/mbgl/style/function/composite_function.hpp rename to include/mbgl/style/property_expression.hpp index 3b63bd005db..16f154cdf24 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 CompositeFunction { +class PropertyExpression { public: - // The second parameter should be used only for conversions from legacy functions. - CompositeFunction(std::unique_ptr expression_, optional defaultValue_ = {}) - : isExpression(defaultValue_), + PropertyExpression(std::unique_ptr 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_, optional 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 typed = expression::fromExpressionValue(*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 - Range evaluate(const Range& zoomRange, const Feature& feature, T finalDefaultValue) { - return Range { - 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 typed = expression::fromExpressionValue(*result); + return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue; + } + return defaultValue ? *defaultValue : finalDefaultValue; } template 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 typed = expression::fromExpressionValue(*result); @@ -42,40 +64,61 @@ class CompositeFunction { } return defaultValue ? *defaultValue : finalDefaultValue; } - + float interpolationFactor(const Range& inputLevels, const float inputValue) const { return zoomCurve.match( + [](std::nullptr_t) { + assert(false); + return 0.0f; + }, [&](const expression::Interpolate* z) { return z->interpolationFactor(Range { inputLevels.min, inputLevels.max }, inputValue); }, - [&](const expression::Step*) { return 0.0f; } + [&](const expression::Step*) { + return 0.0f; + } ); } - + Range 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(0.0f, 0.0f); + }, + [&](auto z) { + return z->getCoveringStops(lower, upper); + } ); } - std::vector> possibleOutputs() const { - return expression::fromExpressionValues(expression->possibleOutputs()); + // Return the range obtained by evaluating the function at each of the zoom levels in zoomRange + template + Range evaluate(const Range& zoomRange, const Feature& feature, T finalDefaultValue) { + return Range { + 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> possibleOutputs() const { + return expression::fromExpressionValues(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 expression; optional defaultValue; - const variant zoomCurve; + variant zoomCurve; }; } // namespace style diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index 02d3a311487..1b0f3d2ab05 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include namespace mbgl { namespace style { @@ -10,7 +10,7 @@ namespace style { template class PropertyValue { private: - using Value = variant>; + using Value = variant>; Value value; friend bool operator==(const PropertyValue& lhs, const PropertyValue& rhs) { @@ -22,17 +22,24 @@ class PropertyValue { } public: - PropertyValue() : value() {} - PropertyValue( T constant) : value(constant) {} - PropertyValue(CameraFunction function) : value(function) {} + PropertyValue() + : value() {} + + PropertyValue(T constant) + : value(constant) {} + + PropertyValue(PropertyExpression 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& asCameraFunction() const { return value.template get>(); } + const T & asConstant() const { return value.template get< T >(); } + const PropertyExpression& asExpression() const { return value.template get>(); } template auto evaluate(const Evaluator& evaluator, TimePoint = {}) const { diff --git a/platform/android/config.cmake b/platform/android/config.cmake index 88130dc104a..21ec6a9e0ca 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 d6669b45087..00000000000 --- a/platform/android/src/style/conversion/function.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include -#include "../../conversion/conversion.hpp" -#include "../../conversion/constant.hpp" -#include "types.hpp" -#include "../../java/lang.hpp" - -#include -#include "../../gson/json_element.hpp" - -#include -#include - -namespace mbgl { -namespace android { -namespace conversion { - -template -struct Converter, mbgl::style::CameraFunction> { - - Result> operator()(jni::JNIEnv& env, const mbgl::style::CameraFunction& value) const { - // Convert expressions - mbgl::Value expressionValue = value.getExpression().serialize(); - return gson::JsonElement::New(env, expressionValue); - } -}; - -template -struct Converter, mbgl::style::SourceFunction> { - - Result> operator()(jni::JNIEnv& env, const mbgl::style::SourceFunction& value) const { - // Convert expressions - mbgl::Value expressionValue = value.getExpression().serialize(); - return gson::JsonElement::New(env, expressionValue); - } -}; - -template -struct Converter, mbgl::style::CompositeFunction> { - - Result> operator()(jni::JNIEnv& env, const mbgl::style::CompositeFunction& 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 00000000000..ae9d4ea41c4 --- /dev/null +++ b/platform/android/src/style/conversion/property_expression.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include "../../conversion/conversion.hpp" +#include "../../conversion/constant.hpp" +#include "types.hpp" +#include "../../java/lang.hpp" + +#include +#include "../../gson/json_element.hpp" + +#include +#include + +namespace mbgl { +namespace android { +namespace conversion { + +template +struct Converter, mbgl::style::PropertyExpression> { + + Result> operator()(jni::JNIEnv& env, const mbgl::style::PropertyExpression& 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 e6fbe421792..feed38b673b 100644 --- a/platform/android/src/style/conversion/property_value.hpp +++ b/platform/android/src/style/conversion/property_value.hpp @@ -5,8 +5,8 @@ #include #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 @@ class PropertyValueEvaluator { return *result; } - jni::jobject* operator()(const mbgl::style::CameraFunction &value) const { - return *convert, mbgl::style::CameraFunction>(env, value); - } - - jni::jobject* operator()(const mbgl::style::SourceFunction &value) const { - return *convert, mbgl::style::SourceFunction>(env, value); - } - - jni::jobject* operator()(const mbgl::style::CompositeFunction &value) const { - return *convert, mbgl::style::CompositeFunction>(env, value); + jni::jobject* operator()(const mbgl::style::PropertyExpression &value) const { + return *convert, mbgl::style::PropertyExpression>(env, value); } private: diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 27f9e766321..c1958fc0322 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -332,15 +332,7 @@ class MGLStyleValueTransformer { return [NSExpression expressionForConstantValue:constantValue]; } - NSExpression *operator()(const mbgl::style::CameraFunction &mbglValue) const { - return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; - } - - NSExpression *operator()(const mbgl::style::SourceFunction &mbglValue) const { - return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; - } - - NSExpression *operator()(const mbgl::style::CompositeFunction &mbglValue) const { + NSExpression *operator()(const mbgl::style::PropertyExpression &mbglValue) const { return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; } }; diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm index 9f805160d16..afd066df826 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm @@ -48,7 +48,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -101,7 +101,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -154,7 +154,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( 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 d04e5d72718..7bfccd65ef8 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.mm +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -69,7 +69,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -84,7 +84,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -100,7 +100,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -147,7 +147,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -162,7 +162,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -178,7 +178,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -225,7 +225,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -240,7 +240,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -256,7 +256,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -303,7 +303,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -347,7 +347,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -362,7 +362,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -378,7 +378,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -425,7 +425,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -469,7 +469,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -484,7 +484,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -500,7 +500,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -547,7 +547,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -562,7 +562,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -578,7 +578,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -625,7 +625,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -640,7 +640,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -656,7 +656,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -709,7 +709,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -753,7 +753,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm index c7a9a0c74ea..6427d672e71 100644 --- a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm @@ -69,7 +69,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -84,7 +84,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -100,7 +100,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -147,7 +147,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -162,7 +162,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -178,7 +178,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -225,7 +225,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -240,7 +240,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -256,7 +256,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -303,7 +303,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -356,7 +356,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("Fill Extrusion Pattern"), 18.0, literal("Fill Extrusion Pattern")) ); } @@ -415,7 +415,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -459,7 +459,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm index 3789133bc62..921b59416b4 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -69,7 +69,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(false), 18.0, literal(false)) ); } @@ -113,7 +113,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -128,7 +128,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -144,7 +144,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -191,7 +191,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -206,7 +206,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -222,7 +222,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -269,7 +269,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -284,7 +284,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -300,7 +300,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -347,7 +347,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("Fill Pattern"), 18.0, literal("Fill Pattern")) ); } @@ -406,7 +406,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -450,7 +450,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/darwin/test/MGLHeatmapStyleLayerTests.mm b/platform/darwin/test/MGLHeatmapStyleLayerTests.mm index c58cac9af01..a51a324cd96 100644 --- a/platform/darwin/test/MGLHeatmapStyleLayerTests.mm +++ b/platform/darwin/test/MGLHeatmapStyleLayerTests.mm @@ -69,7 +69,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -122,7 +122,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -175,7 +175,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -190,7 +190,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -206,7 +206,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -253,7 +253,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -268,7 +268,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -284,7 +284,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( 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 d5d470944ca..2e8795759f8 100644 --- a/platform/darwin/test/MGLHillshadeStyleLayerTests.mm +++ b/platform/darwin/test/MGLHillshadeStyleLayerTests.mm @@ -51,7 +51,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -104,7 +104,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -157,7 +157,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -210,7 +210,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -254,7 +254,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -298,7 +298,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( 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 3f9a824d38d..8ad354ef586 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.mm +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -69,7 +69,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("square"), 18.0, literal("square")) ); } @@ -113,7 +113,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("miter"), 18.0, literal("miter")) ); } @@ -151,7 +151,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -195,7 +195,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -239,7 +239,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -254,7 +254,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -270,7 +270,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -317,7 +317,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -332,7 +332,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -348,7 +348,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -395,7 +395,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({1, 2}), 18.0, literal({1, 2})) ); } @@ -439,7 +439,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -454,7 +454,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -470,7 +470,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -517,7 +517,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -532,7 +532,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -548,7 +548,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -595,7 +595,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -610,7 +610,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -626,7 +626,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -673,7 +673,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("Line Pattern"), 18.0, literal("Line Pattern")) ); } @@ -732,7 +732,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -776,7 +776,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -820,7 +820,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -835,7 +835,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -851,7 +851,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( 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 217c585037f..9325bb48f50 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.mm +++ b/platform/darwin/test/MGLRasterStyleLayerTests.mm @@ -51,7 +51,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -95,7 +95,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -139,7 +139,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -192,7 +192,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -236,7 +236,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -280,7 +280,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -333,7 +333,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("nearest"), 18.0, literal("nearest")) ); } @@ -377,7 +377,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( 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 13cec9820b7..44996fa125d 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 f22ea04f6e8..7566617872e 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -69,7 +69,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -113,7 +113,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("bottom-right"), 18.0, literal("bottom-right")) ); } @@ -151,7 +151,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -195,7 +195,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("Icon Image"), 18.0, literal("Icon Image")) ); } @@ -239,7 +239,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -254,7 +254,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction>( + propertyValue = mbgl::style::PropertyExpression>( interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 })) ); } @@ -270,7 +270,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction>( + propertyValue = mbgl::style::PropertyExpression>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 }))) ); } @@ -308,7 +308,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -352,7 +352,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -396,7 +396,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -440,7 +440,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -455,7 +455,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -471,7 +471,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -509,7 +509,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -553,7 +553,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -568,7 +568,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -584,7 +584,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -622,7 +622,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("both"), 18.0, literal("both")) ); } @@ -672,7 +672,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1, 1, 1 }), 18.0, literal({ 1, 1, 1, 1 })) ); } @@ -716,7 +716,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -760,7 +760,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(false), 18.0, literal(false)) ); } @@ -804,7 +804,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -848,7 +848,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -863,7 +863,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -879,7 +879,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -917,7 +917,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -961,7 +961,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("line"), 18.0, literal("line")) ); } @@ -1005,7 +1005,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1049,7 +1049,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("Text Field"), 18.0, literal("Text Field")) ); } @@ -1087,7 +1087,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -1131,7 +1131,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("bottom-right"), 18.0, literal("bottom-right")) ); } @@ -1169,7 +1169,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ "Text Font", "Tnof Txet" }), 18.0, literal({ "Text Font", "Tnof Txet" })) ); } @@ -1207,7 +1207,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1222,7 +1222,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1238,7 +1238,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1276,7 +1276,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -1320,7 +1320,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("right"), 18.0, literal("right")) ); } @@ -1358,7 +1358,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1373,7 +1373,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1389,7 +1389,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1427,7 +1427,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1477,7 +1477,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -1492,7 +1492,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction>( + propertyValue = mbgl::style::PropertyExpression>( interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 })) ); } @@ -1508,7 +1508,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction>( + propertyValue = mbgl::style::PropertyExpression>( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 }))) ); } @@ -1546,7 +1546,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(true), 18.0, literal(true)) ); } @@ -1590,7 +1590,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1634,7 +1634,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -1678,7 +1678,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1693,7 +1693,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1709,7 +1709,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1747,7 +1747,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("auto"), 18.0, literal("auto")) ); } @@ -1791,7 +1791,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("lowercase"), 18.0, literal("lowercase")) ); } @@ -1829,7 +1829,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -1844,7 +1844,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -1860,7 +1860,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -1907,7 +1907,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -1922,7 +1922,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -1938,7 +1938,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -1985,7 +1985,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2000,7 +2000,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2016,7 +2016,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -2063,7 +2063,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2078,7 +2078,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2094,7 +2094,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2141,7 +2141,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2156,7 +2156,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2172,7 +2172,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2225,7 +2225,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -2269,7 +2269,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } @@ -2313,7 +2313,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2328,7 +2328,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2344,7 +2344,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -2391,7 +2391,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2406,7 +2406,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2422,7 +2422,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2469,7 +2469,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2484,7 +2484,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) ); } @@ -2500,7 +2500,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) ); } @@ -2547,7 +2547,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2562,7 +2562,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2578,7 +2578,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2625,7 +2625,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal(1.0), 18.0, literal(1.0)) ); } @@ -2640,7 +2640,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::SourceFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) ); } @@ -2656,7 +2656,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CompositeFunction( + propertyValue = mbgl::style::PropertyExpression( interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) ); } @@ -2709,7 +2709,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction>( + propertyValue = mbgl::style::PropertyExpression>( step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) ); } @@ -2753,7 +2753,7 @@ - (void)testProperties { { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::CameraFunction( + propertyValue = mbgl::style::PropertyExpression( step(zoom(), literal("viewport"), 18.0, literal("viewport")) ); } diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 60cc20e05a4..d7cabf62447 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( + extrusionLayer->setFillExtrusionColor(PropertyExpression( interpolate(linear(), number(get("height")), 0.f, toColor("#160e23"), 50.f, toColor("#00615f"), 100.f, toColor("#55e9ff")))); extrusionLayer->setFillExtrusionOpacity(0.6f); - extrusionLayer->setFillExtrusionHeight(SourceFunction(get("height"))); - extrusionLayer->setFillExtrusionBase(SourceFunction(get("min_height"))); + extrusionLayer->setFillExtrusionHeight(PropertyExpression(get("height"))); + extrusionLayer->setFillExtrusionBase(PropertyExpression(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 84a7a53f1d8..8df3b4ae3c3 100644 --- a/src/mbgl/programs/symbol_program.cpp +++ b/src/mbgl/programs/symbol_program.cpp @@ -17,14 +17,20 @@ std::unique_ptr SymbolSizeBinder::create(const float tileZoom, const style::DataDrivenPropertyValue& sizeProperty, const float defaultValue) { return sizeProperty.match( - [&] (const style::CompositeFunction& function) -> std::unique_ptr { - return std::make_unique(tileZoom, function, defaultValue); - }, - [&] (const style::SourceFunction& function) { - return std::make_unique(tileZoom, function, defaultValue); + [&] (const Undefined& value) -> std::unique_ptr { + return std::make_unique(tileZoom, value, defaultValue); }, - [&] (const auto& value) -> std::unique_ptr { + [&] (float value) -> std::unique_ptr { return std::make_unique(tileZoom, value, defaultValue); + }, + [&] (const style::PropertyExpression& expression) -> std::unique_ptr { + if (expression.isFeatureConstant()) { + return std::make_unique(tileZoom, expression, defaultValue); + } else if (expression.isZoomConstant()) { + return std::make_unique(tileZoom, expression, defaultValue); + } else { + return std::make_unique(tileZoom, expression, defaultValue); + } } ); } diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 51f9a48f7f4..35b5821918b 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -143,13 +143,13 @@ class ConstantSymbolSizeBinder final : public SymbolSizeBinder { ConstantSymbolSizeBinder(const float /*tileZoom*/, const style::Undefined&, const float defaultValue) : layoutSize(defaultValue) {} - ConstantSymbolSizeBinder(const float tileZoom, const style::CameraFunction& function_, const float /*defaultValue*/) - : layoutSize(function_.evaluate(tileZoom + 1)), - function(function_) { - const Range zoomLevels = function_.getCoveringStops(tileZoom, tileZoom + 1); + ConstantSymbolSizeBinder(const float tileZoom, const style::PropertyExpression& expression_, const float /*defaultValue*/) + : layoutSize(expression_.evaluate(tileZoom + 1)), + expression(expression_) { + const Range zoomLevels = expression_.getCoveringStops(tileZoom, tileZoom + 1); coveringRanges = std::make_tuple( zoomLevels, - Range { function_.evaluate(zoomLevels.min), function_.evaluate(zoomLevels.max) } + Range { expression_.evaluate(zoomLevels.min), expression_.evaluate(zoomLevels.max) } ); } @@ -157,7 +157,7 @@ class ConstantSymbolSizeBinder final : public SymbolSizeBinder { 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 @@ class ConstantSymbolSizeBinder final : public SymbolSizeBinder { const Range& zoomLevels = std::get<0>(*coveringRanges); const Range& 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 @@ class ConstantSymbolSizeBinder final : public SymbolSizeBinder { float layoutSize; optional, Range>> coveringRanges; - optional> function; + optional> expression; }; class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder { @@ -190,13 +190,13 @@ class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder { using VertexVector = gl::VertexVector; using VertexBuffer = gl::VertexBuffer; - SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, const style::SourceFunction& function_, const float defaultValue_) - : function(function_), + SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, style::PropertyExpression expression_, const float defaultValue_) + : expression(std::move(expression_)), defaultValue(defaultValue_) { } Range 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 @@ class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder { return { true, false, unused, unused, unused }; } - style::SourceFunction function; + style::PropertyExpression expression; const float defaultValue; }; class CompositeFunctionSymbolSizeBinder final : public SymbolSizeBinder { public: - CompositeFunctionSymbolSizeBinder(const float tileZoom, const style::CompositeFunction& function_, const float defaultValue_) - : function(function_), + CompositeFunctionSymbolSizeBinder(const float tileZoom, style::PropertyExpression 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 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 @@ class CompositeFunctionSymbolSizeBinder final : public SymbolSizeBinder { return { false, false, sizeInterpolationT, unused, unused }; } - style::CompositeFunction function; + style::PropertyExpression expression; const float defaultValue; float layoutZoom; Range coveringZoomStops; diff --git a/src/mbgl/renderer/cross_faded_property_evaluator.cpp b/src/mbgl/renderer/cross_faded_property_evaluator.cpp index 4dff9dbf12b..9a7af8636cc 100644 --- a/src/mbgl/renderer/cross_faded_property_evaluator.cpp +++ b/src/mbgl/renderer/cross_faded_property_evaluator.cpp @@ -16,10 +16,10 @@ Faded CrossFadedPropertyEvaluator::operator()(const T& constant) const { } template -Faded CrossFadedPropertyEvaluator::operator()(const style::CameraFunction& function) const { - return calculate(function.evaluate(parameters.z - 1.0f), - function.evaluate(parameters.z), - function.evaluate(parameters.z + 1.0f)); +Faded CrossFadedPropertyEvaluator::operator()(const style::PropertyExpression& expression) const { + return calculate(expression.evaluate(parameters.z - 1.0f), + expression.evaluate(parameters.z), + expression.evaluate(parameters.z + 1.0f)); } template diff --git a/src/mbgl/renderer/cross_faded_property_evaluator.hpp b/src/mbgl/renderer/cross_faded_property_evaluator.hpp index 40ecba5d933..1d17c5eb2f7 100644 --- a/src/mbgl/renderer/cross_faded_property_evaluator.hpp +++ b/src/mbgl/renderer/cross_faded_property_evaluator.hpp @@ -27,7 +27,7 @@ class CrossFadedPropertyEvaluator { Faded operator()(const style::Undefined&) const; Faded operator()(const T& constant) const; - Faded operator()(const style::CameraFunction&) const; + Faded operator()(const style::PropertyExpression&) const; private: Faded 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 79ecd0d4957..f9452cc5726 100644 --- a/src/mbgl/renderer/data_driven_property_evaluator.hpp +++ b/src/mbgl/renderer/data_driven_property_evaluator.hpp @@ -23,21 +23,18 @@ class DataDrivenPropertyEvaluator { return ResultType(constant); } - ResultType operator()(const style::CameraFunction& function) const { - if (!parameters.useIntegerZoom) { - return ResultType(function.evaluate(parameters.z)); + ResultType operator()(const style::PropertyExpression& 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 - 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 3a49882f12f..aade672ae77 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -130,13 +130,13 @@ class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder { using Attribute = ZoomInterpolatedAttributeType; using AttributeBinding = typename Attribute::Binding; - SourceFunctionPaintPropertyBinder(style::SourceFunction function_, T defaultValue_) - : function(std::move(function_)), + SourceFunctionPaintPropertyBinder(style::PropertyExpression 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 @@ class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder { } private: - style::SourceFunction function; + style::PropertyExpression expression; T defaultValue; gl::VertexVector vertexVector; optional> vertexBuffer; @@ -187,14 +187,14 @@ class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder { using AttributeBinding = typename Attribute::Binding; using Vertex = gl::detail::Vertex; - CompositeFunctionPaintPropertyBinder(style::CompositeFunction function_, float zoom, T defaultValue_) - : function(std::move(function_)), + CompositeFunctionPaintPropertyBinder(style::PropertyExpression 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 range = function.evaluate(zoomRange, feature, defaultValue); + Range range = expression.evaluate(zoomRange, feature, defaultValue); this->statistics.add(range.min); this->statistics.add(range.max); AttributeValue value = zoomInterpolatedAttributeValue( @@ -218,10 +218,10 @@ class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder { } 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 @@ class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder { } private: - style::CompositeFunction function; + style::PropertyExpression expression; T defaultValue; Range zoomRange; gl::VertexVector vertexVector; @@ -249,11 +249,12 @@ PaintPropertyBinder::create(const PossiblyEvaluatedPropertyValue& value [&] (const T& constant) -> std::unique_ptr> { return std::make_unique>(constant); }, - [&] (const style::SourceFunction& function) { - return std::make_unique>(function, defaultValue); - }, - [&] (const style::CompositeFunction& function) { - return std::make_unique>(function, zoom, defaultValue); + [&] (const style::PropertyExpression& expression) -> std::unique_ptr> { + if (expression.isZoomConstant()) { + return std::make_unique>(expression, defaultValue); + } else { + return std::make_unique>(expression, zoom, defaultValue); + } } ); } diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index e662d5dfb14..f2d265f2f7a 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 -#include +#include #include #include @@ -12,8 +11,7 @@ class PossiblyEvaluatedPropertyValue { private: using Value = variant< T, - style::SourceFunction, - style::CompositeFunction>; + style::PropertyExpression>; Value value; @@ -45,17 +43,14 @@ class PossiblyEvaluatedPropertyValue { template T evaluate(const Feature& feature, float zoom, T defaultValue) const { return this->match( - [&] (const T& constant_) { return constant_; }, - [&] (const style::SourceFunction& function) { - return function.evaluate(feature, defaultValue); - }, - [&] (const style::CompositeFunction& 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& 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 3ac05739209..03e0f5a002d 100644 --- a/src/mbgl/renderer/property_evaluator.hpp +++ b/src/mbgl/renderer/property_evaluator.hpp @@ -16,7 +16,7 @@ class PropertyEvaluator { T operator()(const style::Undefined&) const { return defaultValue; } T operator()(const T& constant) const { return constant; } - T operator()(const style::CameraFunction& fn) const { return fn.evaluate(parameters.z); } + T operator()(const style::PropertyExpression& 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 64adf522a1d..39e061d75a0 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 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> convertLiteral(type::Type type, const Convertible& value, Error& error) { return type.match( [&] (const type::NumberType&) -> optional> { @@ -426,106 +403,16 @@ static optional> convertCategoricalFunction(type::Ty return {}; } -optional> 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> 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> { - return string(get(literal(*property))); - }, - [&] (const type::NumberType&) -> optional> { - return number(get(literal(*property))); - }, - [&] (const type::BooleanType&) -> optional> { - return boolean(get(literal(*property))); - }, - [&] (const type::ColorType&) -> optional> { - return toColor(get(literal(*property))); - }, - [&] (const type::Array& array) -> optional> { - return std::unique_ptr( - std::make_unique(array, get(literal(*property)))); - }, - [&] (const auto&) -> optional> { - assert(false); // No properties use this type. - return {}; - } - ); - default: - error = { "unsupported function type" }; - return {}; - } -} - -template +template optional> composite(type::Type type, const Convertible& value, Error& error, - std::unique_ptr (*makeInnerExpression) (type::Type type, - double base, - const std::string& property, - std::map>)) { - 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> composite(type::Type type, std::map> 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> composite(type::Type type, } } -optional> convertCompositeFunctionToExpression(type::Type type, - const Convertible& value, - Error& err) { +optional> 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 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> { + return string(get(literal(*property))); + }, + [&] (const type::NumberType&) -> optional> { + return number(get(literal(*property))); + }, + [&] (const type::BooleanType&) -> optional> { + return boolean(get(literal(*property))); + }, + [&] (const type::ColorType&) -> optional> { + return toColor(get(literal(*property))); + }, + [&] (const type::Array& array) -> optional> { + return std::unique_ptr( + std::make_unique(array, get(literal(*property)))); + }, + [&] (const auto&) -> optional> { + 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> 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(type, value, err, [] (type::Type type_, double, const std::string& property, std::map> stops) { - return categorical(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(type, value, err, [] (type::Type type_, double, const std::string& property, std::map> 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(type, value, err, [] (type::Type type_, double base, const std::string& property, std::map> 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(type, value, err, [] (type::Type type_, double, const std::string& property, std::map> stops) { - return categorical(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(type, value, err, [] (type::Type type_, double, const std::string& property, std::map> stops) { - return categorical(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(type, value, err, [&] (type::Type type_, double, std::map> stops) { + return categorical(type_, *property, std::move(stops)); + }); + default: + err = { "unsupported function type" }; + return {}; + } + } + + if (toNumber(*sourceValue)) { + switch (functionType) { + case FunctionType::Interval: + return composite(type, value, err, [&] (type::Type type_, double, std::map> stops) { + return step(type_, number(get(literal(*property))), std::move(stops)); + }); + case FunctionType::Exponential: + return composite(type, value, err, [&] (type::Type type_, double base, std::map> stops) { + return interpolate(type_, exponential(base), number(get(literal(*property))), std::move(stops)); + }); + case FunctionType::Categorical: + return composite(type, value, err, [&] (type::Type type_, double, std::map> stops) { + return categorical(type_, *property, std::move(stops)); + }); + default: + err = { "unsupported function type" }; + return {}; + } + } + + if (toString(*sourceValue)) { + switch (functionType) { + case FunctionType::Categorical: + return composite(type, value, err, [&] (type::Type type_, double, std::map> stops) { + return categorical(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 74171763a08..77a39c51f99 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 -void stringify(Writer& writer, const CameraFunction& fn) { - stringify(writer, fn.getExpression().serialize()); -} - -template -void stringify(Writer& writer, const SourceFunction& fn) { - stringify(writer, fn.getExpression().serialize()); -} - -template -void stringify(Writer& writer, const CompositeFunction& fn) { +void stringify(Writer& writer, const PropertyExpression& 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 ce8487a3af9..1e0a9366050 100644 --- a/src/mbgl/style/expression/find_zoom_curve.cpp +++ b/src/mbgl/style/expression/find_zoom_curve.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -59,14 +60,17 @@ optional> findZoomCurve(c return result; } -variant findZoomCurveChecked(const expression::Expression* e) { +variant findZoomCurveChecked(const expression::Expression* e) { + if (isZoomConstant(*e)) { + return nullptr; + } return findZoomCurve(e)->match( - [](const ParsingError&) -> variant { + [](const ParsingError&) -> variant { assert(false); - return {}; + return nullptr; }, - [](auto zoomCurve) -> variant { - return {std::move(zoomCurve)}; + [](auto zoomCurve) -> variant { + return zoomCurve; } ); } diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index dfcf7993a73..9206e969820 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -154,10 +154,7 @@ class Properties { [&] (const T& t) { return t; }, - [&] (const SourceFunction& t) { - return t.evaluate(feature, defaultValue); - }, - [&] (const CompositeFunction& t) { + [&] (const PropertyExpression& 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 9e1765ecd0e..4649227934d 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 is not interpolatable."] ] } diff --git a/test/programs/symbol_program.test.cpp b/test/programs/symbol_program.test.cpp index ed709a4ba7c..b2467d5998e 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().t, true); EXPECT_EQ(uniformValues.get().t, 12.0f); - binder = SymbolSizeBinder::create(1.0f, style::CameraFunction( + binder = SymbolSizeBinder::create(1.0f, style::PropertyExpression( interpolate( linear(), zoom(), @@ -24,7 +24,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 9.5f); - binder = SymbolSizeBinder::create(0.0f, style::CameraFunction( + binder = SymbolSizeBinder::create(0.0f, style::PropertyExpression( interpolate( linear(), zoom(), @@ -35,7 +35,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 8.0f); - binder = SymbolSizeBinder::create(12.0f, style::CameraFunction( + binder = SymbolSizeBinder::create(12.0f, style::PropertyExpression( interpolate( linear(), zoom(), @@ -46,7 +46,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 18.0f); - binder = SymbolSizeBinder::create(0.0f, style::SourceFunction( + binder = SymbolSizeBinder::create(0.0f, style::PropertyExpression( interpolate( linear(), number(get("x")), @@ -56,7 +56,7 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, false); - binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction( + binder = SymbolSizeBinder::create(5.0f, style::PropertyExpression( interpolate( linear(), zoom(), diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index a48be2c0750..fa89576afa2 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -2,9 +2,8 @@ #include #include -#include +#include #include -#include using namespace mbgl; using namespace mbgl::style; @@ -14,7 +13,7 @@ TEST(StyleConversion, Function) { Error error; auto parseFunction = [&](const std::string& json) { - return convertJSON>(json, error); + return convertJSON>(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>(doc, error); + auto parseFunction = [&](const std::string& json) { + return convertJSON>(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 67e48c942e3..f111e40ff34 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 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 bc73b0cedb8..8bc78098cde 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( + ASSERT_EQ(stringify(PropertyExpression( 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( + ASSERT_EQ(stringify(PropertyExpression( 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( + ASSERT_EQ(stringify(PropertyExpression( interpolate( linear(), zoom(), @@ -125,7 +119,7 @@ TEST(Stringify, CompositeFunction) { TEST(Stringify, PropertyValue) { using namespace mbgl::style::expression::dsl; ASSERT_EQ(stringify(PropertyValue(1)), "1.0"); - ASSERT_EQ(stringify(PropertyValue(CameraFunction( + ASSERT_EQ(stringify(PropertyValue(PropertyExpression( 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 1f7e81fc2cd..00000000000 --- a/test/style/function/camera_function.test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -#include -#include -#include - -using namespace mbgl; -using namespace mbgl::style; -using namespace mbgl::style::expression::dsl; - -float evaluate(PropertyValue value, float zoom) { - return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), 0)); -} - -TEST(CameraFunction, Constant) { - EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 0)); - EXPECT_EQ(3.8f, evaluate(PropertyValue(3.8), 0)); - EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 0)); - EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 4)); - EXPECT_EQ(3.8f, evaluate(PropertyValue(3.8), 4)); - EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 4)); - EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 22)); - EXPECT_EQ(3.8f, evaluate(PropertyValue(3.8), 22)); - EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 22)); -} - -TEST(CameraFunction, Expression) { - CameraFunction 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 d1e5e1a974d..00000000000 --- a/test/style/function/source_function.test.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -#include -#include - -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(number(get("property")), 0.0) - .evaluate(oneInteger, 2.0f)); - EXPECT_EQ(1.0f, SourceFunction(number(get("property")), 0.0) - .evaluate(oneDouble, 2.0f)); - EXPECT_EQ(0.0f, SourceFunction(number(get("property")), 0.0) - .evaluate(oneString, 2.0f)); - EXPECT_EQ(2.0f, SourceFunction(number(get("property"))) - .evaluate(oneString, 2.0f)); -} diff --git a/test/style/properties.test.cpp b/test/style/properties.test.cpp index 4d63f7e671e..ef064ccba2f 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 sourceFunction(number(get("property_name"))); + PropertyExpression expression(number(get("property_name"))); Transitioning> t1 { - DataDrivenPropertyValue(sourceFunction), + DataDrivenPropertyValue(expression), t0, transition, TimePoint::min() diff --git a/test/style/function/composite_function.test.cpp b/test/style/property_expression.test.cpp similarity index 60% rename from test/style/function/composite_function.test.cpp rename to test/style/property_expression.test.cpp index 917689ce23c..e4ee5f115fb 100644 --- a/test/style/function/composite_function.test.cpp +++ b/test/style/property_expression.test.cpp @@ -1,7 +1,9 @@ #include #include -#include +#include +#include +#include #include using namespace mbgl; @@ -14,8 +16,49 @@ static StubGeometryTileFeature oneInteger { PropertyMap {{ "property", uint64_t(1) }} }; -TEST(CompositeFunction, ZoomInterpolation) { - EXPECT_EQ(40.0f, CompositeFunction( +static StubGeometryTileFeature oneDouble { + PropertyMap {{ "property", 1.0 }} +}; + +static StubGeometryTileFeature oneString { + PropertyMap {{ "property", "1"s }} +}; + +float evaluate(PropertyValue value, float zoom) { + return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), 0)); +} + +TEST(PropertyExpression, Constant) { + EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 0)); + EXPECT_EQ(3.8f, evaluate(PropertyValue(3.8), 0)); + EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 0)); + EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 4)); + EXPECT_EQ(3.8f, evaluate(PropertyValue(3.8), 4)); + EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 4)); + EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 22)); + EXPECT_EQ(3.8f, evaluate(PropertyValue(3.8), 22)); + EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 22)); +} + +TEST(PropertyExpression, Expression) { + PropertyExpression 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(number(get("property")), 0.0) + .evaluate(oneInteger, 2.0f)); + EXPECT_EQ(1.0f, PropertyExpression(number(get("property")), 0.0) + .evaluate(oneDouble, 2.0f)); + EXPECT_EQ(0.0f, PropertyExpression(number(get("property")), 0.0) + .evaluate(oneString, 2.0f)); + EXPECT_EQ(2.0f, PropertyExpression(number(get("property"))) + .evaluate(oneString, 2.0f)); +} + +TEST(PropertyExpression, ZoomInterpolation) { + EXPECT_EQ(40.0f, PropertyExpression( 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( + EXPECT_EQ(33.0, PropertyExpression( 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( + EXPECT_EQ(66.0, PropertyExpression( 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( + EXPECT_EQ(66.0f, PropertyExpression( 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( + EXPECT_EQ(33.0f, PropertyExpression( 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 fn1( +TEST(PropertyExpression, Issue8460) { + PropertyExpression 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 fn2( + PropertyExpression 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)),