diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-06-28 14:58:52 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-06-29 15:38:11 -0700 |
commit | 6dfe56510caa87b3e0fdbb8256d13ec955764d53 (patch) | |
tree | 0df4859ec90a88d2fca83c18c2aef28924db25ae | |
parent | 542a4b4501794653b55fd1ffc60cb01348d8fc88 (diff) | |
download | qtlocation-mapboxgl-6dfe56510caa87b3e0fdbb8256d13ec955764d53.tar.gz |
[darwin] Replace use of *Stops with expressions DSL
-rw-r--r-- | include/mbgl/style/expression/dsl.hpp | 7 | ||||
-rwxr-xr-x | platform/darwin/scripts/generate-style-code.js | 16 | ||||
-rw-r--r-- | platform/darwin/test/MGLBackgroundStyleLayerTests.mm | 40 | ||||
-rw-r--r-- | platform/darwin/test/MGLCircleStyleLayerTests.mm | 292 | ||||
-rw-r--r-- | platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm | 156 | ||||
-rw-r--r-- | platform/darwin/test/MGLFillStyleLayerTests.mm | 144 | ||||
-rw-r--r-- | platform/darwin/test/MGLHeatmapStyleLayerTests.mm | 109 | ||||
-rw-r--r-- | platform/darwin/test/MGLHillshadeStyleLayerTests.mm | 79 | ||||
-rw-r--r-- | platform/darwin/test/MGLLightTest.mm | 2 | ||||
-rw-r--r-- | platform/darwin/test/MGLLineStyleLayerTests.mm | 317 | ||||
-rw-r--r-- | platform/darwin/test/MGLRasterStyleLayerTests.mm | 131 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleLayerTests.mm.ejs | 32 | ||||
-rw-r--r-- | platform/darwin/test/MGLSymbolStyleLayerTests.mm | 1013 | ||||
-rw-r--r-- | src/mbgl/style/expression/dsl.cpp | 27 |
14 files changed, 1386 insertions, 979 deletions
diff --git a/include/mbgl/style/expression/dsl.hpp b/include/mbgl/style/expression/dsl.hpp index b4e1ed436e..8a5d1d84f5 100644 --- a/include/mbgl/style/expression/dsl.hpp +++ b/include/mbgl/style/expression/dsl.hpp @@ -5,6 +5,7 @@ #include <mbgl/style/expression/interpolator.hpp> #include <memory> +#include <initializer_list> namespace mbgl { namespace style { @@ -16,6 +17,8 @@ namespace dsl { std::unique_ptr<Expression> literal(const char* value); std::unique_ptr<Expression> literal(Value value); +std::unique_ptr<Expression> literal(std::initializer_list<double> value); +std::unique_ptr<Expression> literal(std::initializer_list<const char *> value); std::unique_ptr<Expression> number(std::unique_ptr<Expression>); std::unique_ptr<Expression> string(std::unique_ptr<Expression>); @@ -38,6 +41,10 @@ std::unique_ptr<Expression> gt(std::unique_ptr<Expression>, std::unique_ptr<Expression> lt(std::unique_ptr<Expression>, std::unique_ptr<Expression>); +std::unique_ptr<Expression> step(std::unique_ptr<Expression> input, + std::unique_ptr<Expression> output0, + double input1, std::unique_ptr<Expression> output1); + Interpolator linear(); Interpolator exponential(double base); Interpolator cubicBezier(double x1, double y1, double x2, double y2); diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 9089e57ad5..3809e9c636 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -101,7 +101,7 @@ global.objCTestValue = function (property, layerType, arraysAsStructs, indent) { case 'boolean': return property.default ? '@"false"' : '@"true"'; case 'number': - return '@"0xff"'; + return '@"1"'; case 'string': return `@"'${_.startCase(propertyName)}'"`; case 'enum': @@ -145,7 +145,7 @@ global.mbglTestValue = function (property, layerType) { case 'boolean': return property.default ? 'false' : 'true'; case 'number': - return '0xff'; + return '1.0'; case 'string': return `"${_.startCase(propertyName)}"`; case 'enum': { @@ -186,6 +186,18 @@ global.mbglTestValue = function (property, layerType) { } }; +global.mbglExpressionTestValue = function (property, layerType) { + let propertyName = originalPropertyName(property); + switch (property.type) { + case 'enum': + return `"${_.last(_.keys(property.values))}"`; + case 'color': + return 'mbgl::Color(1, 0, 0, 1)'; + default: + return global.mbglTestValue(property, layerType); + } +}; + global.testGetterImplementation = function (property, layerType, isFunction) { let helperMsg = testHelperMessage(property, layerType, isFunction); let value = `[MGLRuntimeStylingHelper ${helperMsg}]`; diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm index bf18b2d30e..9f805160d1 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLBackgroundLayerTests : MGLStyleLayerTests @end @@ -45,11 +46,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.backgroundColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getBackgroundColor(), propertyValue, @"Setting backgroundColor to a camera expression should update background-color."); @@ -85,23 +87,24 @@ @"background-opacity should be unset initially."); NSExpression *defaultExpression = layer.backgroundOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.backgroundOpacity = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getBackgroundOpacity(), propertyValue, @"Setting backgroundOpacity to a constant value expression should update background-opacity."); XCTAssertEqualObjects(layer.backgroundOpacity, constantExpression, @"backgroundOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.backgroundOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getBackgroundOpacity(), propertyValue, @"Setting backgroundOpacity to a camera expression should update background-opacity."); @@ -149,11 +152,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.backgroundPattern = functionExpression; - mbgl::style::IntervalStops<std::string> intervalStops = {{ - { -INFINITY, "Background Pattern" }, - { 18, "Background Pattern" }, - }}; - propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::string>( + step(zoom(), literal("Background Pattern"), 18.0, literal("Background Pattern")) + ); + } XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue, @"Setting backgroundPattern to a camera expression should update background-pattern."); diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.mm b/platform/darwin/test/MGLCircleStyleLayerTests.mm index 41f7238da2..d04e5d7271 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.mm +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/circle_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLCircleLayerTests : MGLStyleLayerTests @end @@ -54,23 +55,24 @@ @"circle-blur should be unset initially."); NSExpression *defaultExpression = layer.circleBlur; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.circleBlur = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, @"Setting circleBlur to a constant value expression should update circle-blur."); XCTAssertEqualObjects(layer.circleBlur, constantExpression, @"circleBlur should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleBlur = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, @"Setting circleBlur to a camera expression should update circle-blur."); @@ -80,8 +82,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleBlur = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, @"Setting circleBlur to a data expression should update circle-blur."); @@ -92,11 +98,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleBlur = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, @"Setting circleBlur to a camera-data expression should update circle-blur."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -137,11 +145,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, @"Setting circleColor to a camera expression should update circle-color."); @@ -151,8 +160,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, @"Setting circleColor to a data expression should update circle-color."); @@ -163,11 +176,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, @"Setting circleColor to a camera-data expression should update circle-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -196,23 +211,24 @@ @"circle-opacity should be unset initially."); NSExpression *defaultExpression = layer.circleOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.circleOpacity = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, @"Setting circleOpacity to a constant value expression should update circle-opacity."); XCTAssertEqualObjects(layer.circleOpacity, constantExpression, @"circleOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, @"Setting circleOpacity to a camera expression should update circle-opacity."); @@ -222,8 +238,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleOpacity = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, @"Setting circleOpacity to a data expression should update circle-opacity."); @@ -234,11 +254,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleOpacity = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, @"Setting circleOpacity to a camera-data expression should update circle-opacity."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -279,11 +301,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circlePitchAlignment = functionExpression; - mbgl::style::IntervalStops<mbgl::style::AlignmentType> intervalStops = {{ - { -INFINITY, mbgl::style::AlignmentType::Viewport }, - { 18, mbgl::style::AlignmentType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getCirclePitchAlignment(), propertyValue, @"Setting circlePitchAlignment to a camera expression should update circle-pitch-alignment."); @@ -310,23 +333,24 @@ @"circle-radius should be unset initially."); NSExpression *defaultExpression = layer.circleRadius; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.circleRadius = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, @"Setting circleRadius to a constant value expression should update circle-radius."); XCTAssertEqualObjects(layer.circleRadius, constantExpression, @"circleRadius should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleRadius = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, @"Setting circleRadius to a camera expression should update circle-radius."); @@ -336,8 +360,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleRadius = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, @"Setting circleRadius to a data expression should update circle-radius."); @@ -348,11 +376,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleRadius = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, @"Setting circleRadius to a camera-data expression should update circle-radius."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -393,11 +423,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleScaleAlignment = functionExpression; - mbgl::style::IntervalStops<mbgl::style::CirclePitchScaleType> intervalStops = {{ - { -INFINITY, mbgl::style::CirclePitchScaleType::Viewport }, - { 18, mbgl::style::CirclePitchScaleType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::CirclePitchScaleType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::CirclePitchScaleType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getCirclePitchScale(), propertyValue, @"Setting circleScaleAlignment to a camera expression should update circle-pitch-scale."); @@ -436,11 +467,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleStrokeColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, @"Setting circleStrokeColor to a camera expression should update circle-stroke-color."); @@ -450,8 +482,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleStrokeColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, @"Setting circleStrokeColor to a data expression should update circle-stroke-color."); @@ -462,11 +498,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleStrokeColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, @"Setting circleStrokeColor to a camera-data expression should update circle-stroke-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -495,23 +533,24 @@ @"circle-stroke-opacity should be unset initially."); NSExpression *defaultExpression = layer.circleStrokeOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.circleStrokeOpacity = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, @"Setting circleStrokeOpacity to a constant value expression should update circle-stroke-opacity."); XCTAssertEqualObjects(layer.circleStrokeOpacity, constantExpression, @"circleStrokeOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleStrokeOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, @"Setting circleStrokeOpacity to a camera expression should update circle-stroke-opacity."); @@ -521,8 +560,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleStrokeOpacity = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, @"Setting circleStrokeOpacity to a data expression should update circle-stroke-opacity."); @@ -533,11 +576,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleStrokeOpacity = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, @"Setting circleStrokeOpacity to a camera-data expression should update circle-stroke-opacity."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -566,23 +611,24 @@ @"circle-stroke-width should be unset initially."); NSExpression *defaultExpression = layer.circleStrokeWidth; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.circleStrokeWidth = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, @"Setting circleStrokeWidth to a constant value expression should update circle-stroke-width."); XCTAssertEqualObjects(layer.circleStrokeWidth, constantExpression, @"circleStrokeWidth should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleStrokeWidth = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, @"Setting circleStrokeWidth to a camera expression should update circle-stroke-width."); @@ -592,8 +638,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.circleStrokeWidth = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, @"Setting circleStrokeWidth to a data expression should update circle-stroke-width."); @@ -604,11 +654,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.circleStrokeWidth = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, @"Setting circleStrokeWidth to a camera-data expression should update circle-stroke-width."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -655,11 +707,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleTranslation = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getCircleTranslate(), propertyValue, @"Setting circleTranslation to a camera expression should update circle-translate."); @@ -698,11 +751,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.circleTranslationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::TranslateAnchorType::Viewport }, - { 18, mbgl::style::TranslateAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getCircleTranslateAnchor(), propertyValue, @"Setting circleTranslationAnchor to a camera expression should update circle-translate-anchor."); diff --git a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm index ac858d0edc..c7a9a0c74e 100644 --- a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/fill_extrusion_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLFillExtrusionLayerTests : MGLStyleLayerTests @end @@ -54,23 +55,24 @@ @"fill-extrusion-base should be unset initially."); NSExpression *defaultExpression = layer.fillExtrusionBase; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.fillExtrusionBase = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getFillExtrusionBase(), propertyValue, @"Setting fillExtrusionBase to a constant value expression should update fill-extrusion-base."); XCTAssertEqualObjects(layer.fillExtrusionBase, constantExpression, @"fillExtrusionBase should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionBase = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionBase(), propertyValue, @"Setting fillExtrusionBase to a camera expression should update fill-extrusion-base."); @@ -80,8 +82,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.fillExtrusionBase = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionBase(), propertyValue, @"Setting fillExtrusionBase to a data expression should update fill-extrusion-base."); @@ -92,11 +98,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.fillExtrusionBase = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getFillExtrusionBase(), propertyValue, @"Setting fillExtrusionBase to a camera-data expression should update fill-extrusion-base."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -137,11 +145,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionColor(), propertyValue, @"Setting fillExtrusionColor to a camera expression should update fill-extrusion-color."); @@ -151,8 +160,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.fillExtrusionColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionColor(), propertyValue, @"Setting fillExtrusionColor to a data expression should update fill-extrusion-color."); @@ -163,11 +176,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.fillExtrusionColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getFillExtrusionColor(), propertyValue, @"Setting fillExtrusionColor to a camera-data expression should update fill-extrusion-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -196,23 +211,24 @@ @"fill-extrusion-height should be unset initially."); NSExpression *defaultExpression = layer.fillExtrusionHeight; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.fillExtrusionHeight = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getFillExtrusionHeight(), propertyValue, @"Setting fillExtrusionHeight to a constant value expression should update fill-extrusion-height."); XCTAssertEqualObjects(layer.fillExtrusionHeight, constantExpression, @"fillExtrusionHeight should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionHeight = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionHeight(), propertyValue, @"Setting fillExtrusionHeight to a camera expression should update fill-extrusion-height."); @@ -222,8 +238,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.fillExtrusionHeight = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionHeight(), propertyValue, @"Setting fillExtrusionHeight to a data expression should update fill-extrusion-height."); @@ -234,11 +254,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.fillExtrusionHeight = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getFillExtrusionHeight(), propertyValue, @"Setting fillExtrusionHeight to a camera-data expression should update fill-extrusion-height."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -267,23 +289,24 @@ @"fill-extrusion-opacity should be unset initially."); NSExpression *defaultExpression = layer.fillExtrusionOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.fillExtrusionOpacity = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getFillExtrusionOpacity(), propertyValue, @"Setting fillExtrusionOpacity to a constant value expression should update fill-extrusion-opacity."); XCTAssertEqualObjects(layer.fillExtrusionOpacity, constantExpression, @"fillExtrusionOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionOpacity(), propertyValue, @"Setting fillExtrusionOpacity to a camera expression should update fill-extrusion-opacity."); @@ -331,11 +354,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionPattern = functionExpression; - mbgl::style::IntervalStops<std::string> intervalStops = {{ - { -INFINITY, "Fill Extrusion Pattern" }, - { 18, "Fill Extrusion Pattern" }, - }}; - propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::string>( + step(zoom(), literal("Fill Extrusion Pattern"), 18.0, literal("Fill Extrusion Pattern")) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionPattern(), propertyValue, @"Setting fillExtrusionPattern to a camera expression should update fill-extrusion-pattern."); @@ -389,11 +413,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionTranslation = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionTranslate(), propertyValue, @"Setting fillExtrusionTranslation to a camera expression should update fill-extrusion-translate."); @@ -432,11 +457,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillExtrusionTranslationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::TranslateAnchorType::Viewport }, - { 18, mbgl::style::TranslateAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getFillExtrusionTranslateAnchor(), propertyValue, @"Setting fillExtrusionTranslationAnchor to a camera expression should update fill-extrusion-translate-anchor."); diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm index 45bae07f43..3789133bc6 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/fill_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLFillLayerTests : MGLStyleLayerTests @end @@ -66,11 +67,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillAntialiased = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, false }, - { 18, false }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(false), 18.0, literal(false)) + ); + } XCTAssertEqual(rawLayer->getFillAntialias(), propertyValue, @"Setting fillAntialiased to a camera expression should update fill-antialias."); @@ -109,11 +111,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getFillColor(), propertyValue, @"Setting fillColor to a camera expression should update fill-color."); @@ -123,8 +126,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.fillColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getFillColor(), propertyValue, @"Setting fillColor to a data expression should update fill-color."); @@ -135,11 +142,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.fillColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getFillColor(), propertyValue, @"Setting fillColor to a camera-data expression should update fill-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -168,23 +177,24 @@ @"fill-opacity should be unset initially."); NSExpression *defaultExpression = layer.fillOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.fillOpacity = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, @"Setting fillOpacity to a constant value expression should update fill-opacity."); XCTAssertEqualObjects(layer.fillOpacity, constantExpression, @"fillOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, @"Setting fillOpacity to a camera expression should update fill-opacity."); @@ -194,8 +204,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.fillOpacity = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, @"Setting fillOpacity to a data expression should update fill-opacity."); @@ -206,11 +220,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.fillOpacity = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, @"Setting fillOpacity to a camera-data expression should update fill-opacity."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -251,11 +267,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillOutlineColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getFillOutlineColor(), propertyValue, @"Setting fillOutlineColor to a camera expression should update fill-outline-color."); @@ -265,8 +282,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.fillOutlineColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getFillOutlineColor(), propertyValue, @"Setting fillOutlineColor to a data expression should update fill-outline-color."); @@ -277,11 +298,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.fillOutlineColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getFillOutlineColor(), propertyValue, @"Setting fillOutlineColor to a camera-data expression should update fill-outline-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -322,11 +345,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillPattern = functionExpression; - mbgl::style::IntervalStops<std::string> intervalStops = {{ - { -INFINITY, "Fill Pattern" }, - { 18, "Fill Pattern" }, - }}; - propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::string>( + step(zoom(), literal("Fill Pattern"), 18.0, literal("Fill Pattern")) + ); + } XCTAssertEqual(rawLayer->getFillPattern(), propertyValue, @"Setting fillPattern to a camera expression should update fill-pattern."); @@ -380,11 +404,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillTranslation = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getFillTranslate(), propertyValue, @"Setting fillTranslation to a camera expression should update fill-translate."); @@ -423,11 +448,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.fillTranslationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::TranslateAnchorType::Viewport }, - { 18, mbgl::style::TranslateAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getFillTranslateAnchor(), propertyValue, @"Setting fillTranslationAnchor to a camera expression should update fill-translate-anchor."); diff --git a/platform/darwin/test/MGLHeatmapStyleLayerTests.mm b/platform/darwin/test/MGLHeatmapStyleLayerTests.mm index db15778872..c58cac9af0 100644 --- a/platform/darwin/test/MGLHeatmapStyleLayerTests.mm +++ b/platform/darwin/test/MGLHeatmapStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/heatmap_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLHeatmapLayerTests : MGLStyleLayerTests @end @@ -54,23 +55,24 @@ @"heatmap-intensity should be unset initially."); NSExpression *defaultExpression = layer.heatmapIntensity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.heatmapIntensity = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getHeatmapIntensity(), propertyValue, @"Setting heatmapIntensity to a constant value expression should update heatmap-intensity."); XCTAssertEqualObjects(layer.heatmapIntensity, constantExpression, @"heatmapIntensity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.heatmapIntensity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHeatmapIntensity(), propertyValue, @"Setting heatmapIntensity to a camera expression should update heatmap-intensity."); @@ -106,23 +108,24 @@ @"heatmap-opacity should be unset initially."); NSExpression *defaultExpression = layer.heatmapOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.heatmapOpacity = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getHeatmapOpacity(), propertyValue, @"Setting heatmapOpacity to a constant value expression should update heatmap-opacity."); XCTAssertEqualObjects(layer.heatmapOpacity, constantExpression, @"heatmapOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.heatmapOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHeatmapOpacity(), propertyValue, @"Setting heatmapOpacity to a camera expression should update heatmap-opacity."); @@ -158,23 +161,24 @@ @"heatmap-radius should be unset initially."); NSExpression *defaultExpression = layer.heatmapRadius; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.heatmapRadius = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getHeatmapRadius(), propertyValue, @"Setting heatmapRadius to a constant value expression should update heatmap-radius."); XCTAssertEqualObjects(layer.heatmapRadius, constantExpression, @"heatmapRadius should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.heatmapRadius = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHeatmapRadius(), propertyValue, @"Setting heatmapRadius to a camera expression should update heatmap-radius."); @@ -184,8 +188,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.heatmapRadius = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHeatmapRadius(), propertyValue, @"Setting heatmapRadius to a data expression should update heatmap-radius."); @@ -196,11 +204,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.heatmapRadius = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getHeatmapRadius(), propertyValue, @"Setting heatmapRadius to a camera-data expression should update heatmap-radius."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -229,23 +239,24 @@ @"heatmap-weight should be unset initially."); NSExpression *defaultExpression = layer.heatmapWeight; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.heatmapWeight = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getHeatmapWeight(), propertyValue, @"Setting heatmapWeight to a constant value expression should update heatmap-weight."); XCTAssertEqualObjects(layer.heatmapWeight, constantExpression, @"heatmapWeight should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.heatmapWeight = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHeatmapWeight(), propertyValue, @"Setting heatmapWeight to a camera expression should update heatmap-weight."); @@ -255,8 +266,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.heatmapWeight = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHeatmapWeight(), propertyValue, @"Setting heatmapWeight to a data expression should update heatmap-weight."); @@ -267,11 +282,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.heatmapWeight = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getHeatmapWeight(), propertyValue, @"Setting heatmapWeight to a camera-data expression should update heatmap-weight."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; diff --git a/platform/darwin/test/MGLHillshadeStyleLayerTests.mm b/platform/darwin/test/MGLHillshadeStyleLayerTests.mm index 2495b32d97..d5d470944c 100644 --- a/platform/darwin/test/MGLHillshadeStyleLayerTests.mm +++ b/platform/darwin/test/MGLHillshadeStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/hillshade_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLHillshadeLayerTests : MGLStyleLayerTests @end @@ -48,11 +49,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.hillshadeAccentColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getHillshadeAccentColor(), propertyValue, @"Setting hillshadeAccentColor to a camera expression should update hillshade-accent-color."); @@ -88,23 +90,24 @@ @"hillshade-exaggeration should be unset initially."); NSExpression *defaultExpression = layer.hillshadeExaggeration; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.hillshadeExaggeration = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getHillshadeExaggeration(), propertyValue, @"Setting hillshadeExaggeration to a constant value expression should update hillshade-exaggeration."); XCTAssertEqualObjects(layer.hillshadeExaggeration, constantExpression, @"hillshadeExaggeration should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.hillshadeExaggeration = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHillshadeExaggeration(), propertyValue, @"Setting hillshadeExaggeration to a camera expression should update hillshade-exaggeration."); @@ -152,11 +155,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.hillshadeHighlightColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getHillshadeHighlightColor(), propertyValue, @"Setting hillshadeHighlightColor to a camera expression should update hillshade-highlight-color."); @@ -204,11 +208,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.hillshadeIlluminationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::HillshadeIlluminationAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::HillshadeIlluminationAnchorType::Viewport }, - { 18, mbgl::style::HillshadeIlluminationAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::HillshadeIlluminationAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::HillshadeIlluminationAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getHillshadeIlluminationAnchor(), propertyValue, @"Setting hillshadeIlluminationAnchor to a camera expression should update hillshade-illumination-anchor."); @@ -235,23 +240,24 @@ @"hillshade-illumination-direction should be unset initially."); NSExpression *defaultExpression = layer.hillshadeIlluminationDirection; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.hillshadeIlluminationDirection = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getHillshadeIlluminationDirection(), propertyValue, @"Setting hillshadeIlluminationDirection to a constant value expression should update hillshade-illumination-direction."); XCTAssertEqualObjects(layer.hillshadeIlluminationDirection, constantExpression, @"hillshadeIlluminationDirection should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.hillshadeIlluminationDirection = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getHillshadeIlluminationDirection(), propertyValue, @"Setting hillshadeIlluminationDirection to a camera expression should update hillshade-illumination-direction."); @@ -290,11 +296,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.hillshadeShadowColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getHillshadeShadowColor(), propertyValue, @"Setting hillshadeShadowColor to a camera expression should update hillshade-shadow-color."); diff --git a/platform/darwin/test/MGLLightTest.mm b/platform/darwin/test/MGLLightTest.mm index a51c59c725..0bc7b15af3 100644 --- a/platform/darwin/test/MGLLightTest.mm +++ b/platform/darwin/test/MGLLightTest.mm @@ -104,7 +104,7 @@ XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == defaultTransition.delay); XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == defaultTransition.duration); - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; light.setIntensity(propertyValue); light.setIntensityTransition(transitionOptions); diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm index aa24bc8c15..3f9a824d38 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.mm +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/line_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLLineLayerTests : MGLStyleLayerTests @end @@ -66,11 +67,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineCap = functionExpression; - mbgl::style::IntervalStops<mbgl::style::LineCapType> intervalStops = {{ - { -INFINITY, mbgl::style::LineCapType::Square }, - { 18, mbgl::style::LineCapType::Square }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::LineCapType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::LineCapType>( + step(zoom(), literal("square"), 18.0, literal("square")) + ); + } XCTAssertEqual(rawLayer->getLineCap(), propertyValue, @"Setting lineCap to a camera expression should update line-cap."); @@ -109,11 +111,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineJoin = functionExpression; - mbgl::style::IntervalStops<mbgl::style::LineJoinType> intervalStops = {{ - { -INFINITY, mbgl::style::LineJoinType::Miter }, - { 18, mbgl::style::LineJoinType::Miter }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::LineJoinType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::LineJoinType>( + step(zoom(), literal("miter"), 18.0, literal("miter")) + ); + } XCTAssertEqual(rawLayer->getLineJoin(), propertyValue, @"Setting lineJoin to a camera expression should update line-join."); @@ -134,23 +137,24 @@ @"line-miter-limit should be unset initially."); NSExpression *defaultExpression = layer.lineMiterLimit; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineMiterLimit = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineMiterLimit(), propertyValue, @"Setting lineMiterLimit to a constant value expression should update line-miter-limit."); XCTAssertEqualObjects(layer.lineMiterLimit, constantExpression, @"lineMiterLimit should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineMiterLimit = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineMiterLimit(), propertyValue, @"Setting lineMiterLimit to a camera expression should update line-miter-limit."); @@ -177,23 +181,24 @@ @"line-round-limit should be unset initially."); NSExpression *defaultExpression = layer.lineRoundLimit; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineRoundLimit = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineRoundLimit(), propertyValue, @"Setting lineRoundLimit to a constant value expression should update line-round-limit."); XCTAssertEqualObjects(layer.lineRoundLimit, constantExpression, @"lineRoundLimit should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineRoundLimit = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineRoundLimit(), propertyValue, @"Setting lineRoundLimit to a camera expression should update line-round-limit."); @@ -220,23 +225,24 @@ @"line-blur should be unset initially."); NSExpression *defaultExpression = layer.lineBlur; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineBlur = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineBlur(), propertyValue, @"Setting lineBlur to a constant value expression should update line-blur."); XCTAssertEqualObjects(layer.lineBlur, constantExpression, @"lineBlur should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineBlur = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineBlur(), propertyValue, @"Setting lineBlur to a camera expression should update line-blur."); @@ -246,8 +252,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.lineBlur = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineBlur(), propertyValue, @"Setting lineBlur to a data expression should update line-blur."); @@ -258,11 +268,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.lineBlur = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getLineBlur(), propertyValue, @"Setting lineBlur to a camera-data expression should update line-blur."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -303,11 +315,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getLineColor(), propertyValue, @"Setting lineColor to a camera expression should update line-color."); @@ -317,8 +330,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.lineColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getLineColor(), propertyValue, @"Setting lineColor to a data expression should update line-color."); @@ -329,11 +346,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.lineColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getLineColor(), propertyValue, @"Setting lineColor to a camera-data expression should update line-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -374,11 +393,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineDashPattern = functionExpression; - mbgl::style::IntervalStops<std::vector<float>> intervalStops = {{ - { -INFINITY, {1, 2} }, - { 18, {1, 2} }, - }}; - propertyValue = mbgl::style::CameraFunction<std::vector<float>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::vector<float>>( + step(zoom(), literal({1, 2}), 18.0, literal({1, 2})) + ); + } XCTAssertEqual(rawLayer->getLineDasharray(), propertyValue, @"Setting lineDashPattern to a camera expression should update line-dasharray."); @@ -405,23 +425,24 @@ @"line-gap-width should be unset initially."); NSExpression *defaultExpression = layer.lineGapWidth; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineGapWidth = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineGapWidth(), propertyValue, @"Setting lineGapWidth to a constant value expression should update line-gap-width."); XCTAssertEqualObjects(layer.lineGapWidth, constantExpression, @"lineGapWidth should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineGapWidth = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineGapWidth(), propertyValue, @"Setting lineGapWidth to a camera expression should update line-gap-width."); @@ -431,8 +452,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.lineGapWidth = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineGapWidth(), propertyValue, @"Setting lineGapWidth to a data expression should update line-gap-width."); @@ -443,11 +468,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.lineGapWidth = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getLineGapWidth(), propertyValue, @"Setting lineGapWidth to a camera-data expression should update line-gap-width."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -476,23 +503,24 @@ @"line-offset should be unset initially."); NSExpression *defaultExpression = layer.lineOffset; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineOffset = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineOffset(), propertyValue, @"Setting lineOffset to a constant value expression should update line-offset."); XCTAssertEqualObjects(layer.lineOffset, constantExpression, @"lineOffset should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineOffset = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineOffset(), propertyValue, @"Setting lineOffset to a camera expression should update line-offset."); @@ -502,8 +530,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.lineOffset = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineOffset(), propertyValue, @"Setting lineOffset to a data expression should update line-offset."); @@ -514,11 +546,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.lineOffset = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getLineOffset(), propertyValue, @"Setting lineOffset to a camera-data expression should update line-offset."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -547,23 +581,24 @@ @"line-opacity should be unset initially."); NSExpression *defaultExpression = layer.lineOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineOpacity = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineOpacity(), propertyValue, @"Setting lineOpacity to a constant value expression should update line-opacity."); XCTAssertEqualObjects(layer.lineOpacity, constantExpression, @"lineOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineOpacity(), propertyValue, @"Setting lineOpacity to a camera expression should update line-opacity."); @@ -573,8 +608,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.lineOpacity = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineOpacity(), propertyValue, @"Setting lineOpacity to a data expression should update line-opacity."); @@ -585,11 +624,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.lineOpacity = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getLineOpacity(), propertyValue, @"Setting lineOpacity to a camera-data expression should update line-opacity."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -630,11 +671,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.linePattern = functionExpression; - mbgl::style::IntervalStops<std::string> intervalStops = {{ - { -INFINITY, "Line Pattern" }, - { 18, "Line Pattern" }, - }}; - propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::string>( + step(zoom(), literal("Line Pattern"), 18.0, literal("Line Pattern")) + ); + } XCTAssertEqual(rawLayer->getLinePattern(), propertyValue, @"Setting linePattern to a camera expression should update line-pattern."); @@ -688,11 +730,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineTranslation = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getLineTranslate(), propertyValue, @"Setting lineTranslation to a camera expression should update line-translate."); @@ -731,11 +774,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineTranslationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::TranslateAnchorType::Viewport }, - { 18, mbgl::style::TranslateAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getLineTranslateAnchor(), propertyValue, @"Setting lineTranslationAnchor to a camera expression should update line-translate-anchor."); @@ -762,23 +806,24 @@ @"line-width should be unset initially."); NSExpression *defaultExpression = layer.lineWidth; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.lineWidth = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getLineWidth(), propertyValue, @"Setting lineWidth to a constant value expression should update line-width."); XCTAssertEqualObjects(layer.lineWidth, constantExpression, @"lineWidth should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.lineWidth = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineWidth(), propertyValue, @"Setting lineWidth to a camera expression should update line-width."); @@ -788,8 +833,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.lineWidth = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getLineWidth(), propertyValue, @"Setting lineWidth to a data expression should update line-width."); @@ -800,11 +849,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.lineWidth = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getLineWidth(), propertyValue, @"Setting lineWidth to a camera-data expression should update line-width."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.mm b/platform/darwin/test/MGLRasterStyleLayerTests.mm index cc5c1b6984..217c585037 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.mm +++ b/platform/darwin/test/MGLRasterStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/raster_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLRasterLayerTests : MGLStyleLayerTests @end @@ -36,23 +37,24 @@ @"raster-brightness-max should be unset initially."); NSExpression *defaultExpression = layer.maximumRasterBrightness; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.maximumRasterBrightness = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterBrightnessMax(), propertyValue, @"Setting maximumRasterBrightness to a constant value expression should update raster-brightness-max."); XCTAssertEqualObjects(layer.maximumRasterBrightness, constantExpression, @"maximumRasterBrightness should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.maximumRasterBrightness = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterBrightnessMax(), propertyValue, @"Setting maximumRasterBrightness to a camera expression should update raster-brightness-max."); @@ -79,23 +81,24 @@ @"raster-brightness-min should be unset initially."); NSExpression *defaultExpression = layer.minimumRasterBrightness; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.minimumRasterBrightness = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterBrightnessMin(), propertyValue, @"Setting minimumRasterBrightness to a constant value expression should update raster-brightness-min."); XCTAssertEqualObjects(layer.minimumRasterBrightness, constantExpression, @"minimumRasterBrightness should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.minimumRasterBrightness = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterBrightnessMin(), propertyValue, @"Setting minimumRasterBrightness to a camera expression should update raster-brightness-min."); @@ -122,23 +125,24 @@ @"raster-contrast should be unset initially."); NSExpression *defaultExpression = layer.rasterContrast; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.rasterContrast = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterContrast(), propertyValue, @"Setting rasterContrast to a constant value expression should update raster-contrast."); XCTAssertEqualObjects(layer.rasterContrast, constantExpression, @"rasterContrast should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.rasterContrast = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterContrast(), propertyValue, @"Setting rasterContrast to a camera expression should update raster-contrast."); @@ -174,23 +178,24 @@ @"raster-fade-duration should be unset initially."); NSExpression *defaultExpression = layer.rasterFadeDuration; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.rasterFadeDuration = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterFadeDuration(), propertyValue, @"Setting rasterFadeDuration to a constant value expression should update raster-fade-duration."); XCTAssertEqualObjects(layer.rasterFadeDuration, constantExpression, @"rasterFadeDuration should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.rasterFadeDuration = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterFadeDuration(), propertyValue, @"Setting rasterFadeDuration to a camera expression should update raster-fade-duration."); @@ -217,23 +222,24 @@ @"raster-hue-rotate should be unset initially."); NSExpression *defaultExpression = layer.rasterHueRotation; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.rasterHueRotation = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterHueRotate(), propertyValue, @"Setting rasterHueRotation to a constant value expression should update raster-hue-rotate."); XCTAssertEqualObjects(layer.rasterHueRotation, constantExpression, @"rasterHueRotation should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.rasterHueRotation = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterHueRotate(), propertyValue, @"Setting rasterHueRotation to a camera expression should update raster-hue-rotate."); @@ -260,23 +266,24 @@ @"raster-opacity should be unset initially."); NSExpression *defaultExpression = layer.rasterOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.rasterOpacity = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterOpacity(), propertyValue, @"Setting rasterOpacity to a constant value expression should update raster-opacity."); XCTAssertEqualObjects(layer.rasterOpacity, constantExpression, @"rasterOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.rasterOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterOpacity(), propertyValue, @"Setting rasterOpacity to a camera expression should update raster-opacity."); @@ -324,11 +331,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.rasterResamplingMode = functionExpression; - mbgl::style::IntervalStops<mbgl::style::RasterResamplingType> intervalStops = {{ - { -INFINITY, mbgl::style::RasterResamplingType::Nearest }, - { 18, mbgl::style::RasterResamplingType::Nearest }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::RasterResamplingType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::RasterResamplingType>( + step(zoom(), literal("nearest"), 18.0, literal("nearest")) + ); + } XCTAssertEqual(rawLayer->getRasterResampling(), propertyValue, @"Setting rasterResamplingMode to a camera expression should update raster-resampling."); @@ -355,23 +363,24 @@ @"raster-saturation should be unset initially."); NSExpression *defaultExpression = layer.rasterSaturation; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.rasterSaturation = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getRasterSaturation(), propertyValue, @"Setting rasterSaturation to a constant value expression should update raster-saturation."); XCTAssertEqualObjects(layer.rasterSaturation, constantExpression, @"rasterSaturation should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.rasterSaturation = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getRasterSaturation(), propertyValue, @"Setting rasterSaturation to a camera expression should update raster-saturation."); diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs index 57e5fce533..13cec9820b 100644 --- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs +++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs @@ -13,6 +13,7 @@ #include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGL<%- camelize(type) %>LayerTests : MGLStyleLayerTests @end @@ -83,11 +84,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.<%- objCName(property) %> = functionExpression; - mbgl::style::IntervalStops<<%- mbglType(property) %>> intervalStops = {{ - { -INFINITY, <%- mbglTestValue(property, type) %> }, - { 18, <%- mbglTestValue(property, type) %> }, - }}; - propertyValue = mbgl::style::CameraFunction<<%- mbglType(property) %>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<<%- mbglType(property) %>>( + step(zoom(), literal(<%- mbglExpressionTestValue(property, type) %>), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>)) + ); + } XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, @"Setting <%- objCName(property) %> to a camera expression should update <%- originalPropertyName(property) %>."); @@ -98,8 +100,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.<%- objCName(property) %> = functionExpression; - mbgl::style::ExponentialStops<<%- mbglType(property) %>> exponentialStops = { {{18, <%- mbglTestValue(property, type) %>}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<<%- mbglType(property) %>> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<<%- mbglType(property) %>>( + interpolate(linear(), number(get("keyName")), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>)) + ); + } XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, @"Setting <%- objCName(property) %> to a data expression should update <%- originalPropertyName(property) %>."); @@ -110,11 +116,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.<%- objCName(property) %> = functionExpression; - std::map<float, <%- mbglType(property) %>> innerStops { {18, <%- mbglTestValue(property, type) %>} }; - mbgl::style::CompositeExponentialStops<<%- mbglType(property) %>> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<<%- mbglType(property) %>> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<<%- mbglType(property) %>>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>))) + ); + } + XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, @"Setting <%- objCName(property) %> to a camera-data expression should update <%- originalPropertyName(property) %>."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index e1a7ee4e0e..f22ea04f6e 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -8,6 +8,7 @@ #include <mbgl/style/layers/symbol_layer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/expression/dsl.hpp> @interface MGLSymbolLayerTests : MGLStyleLayerTests @end @@ -66,11 +67,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconAllowsOverlap = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getIconAllowOverlap(), propertyValue, @"Setting iconAllowsOverlap to a camera expression should update icon-allow-overlap."); @@ -109,11 +111,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::SymbolAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::SymbolAnchorType::BottomRight }, - { 18, mbgl::style::SymbolAnchorType::BottomRight }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolAnchorType>( + step(zoom(), literal("bottom-right"), 18.0, literal("bottom-right")) + ); + } XCTAssertEqual(rawLayer->getIconAnchor(), propertyValue, @"Setting iconAnchor to a camera expression should update icon-anchor."); @@ -146,11 +149,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconIgnoresPlacement = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getIconIgnorePlacement(), propertyValue, @"Setting iconIgnoresPlacement to a camera expression should update icon-ignore-placement."); @@ -189,11 +193,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconImageName = functionExpression; - mbgl::style::IntervalStops<std::string> intervalStops = {{ - { -INFINITY, "Icon Image" }, - { 18, "Icon Image" }, - }}; - propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::string>( + step(zoom(), literal("Icon Image"), 18.0, literal("Icon Image")) + ); + } XCTAssertEqual(rawLayer->getIconImage(), propertyValue, @"Setting iconImageName to a camera expression should update icon-image."); @@ -232,11 +237,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconOffset = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getIconOffset(), propertyValue, @"Setting iconOffset to a camera expression should update icon-offset."); @@ -246,8 +252,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconOffset = functionExpression; - mbgl::style::ExponentialStops<std::array<float, 2>> exponentialStops = { {{18, { 1, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<std::array<float, 2>> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<std::array<float, 2>>( + interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getIconOffset(), propertyValue, @"Setting iconOffset to a data expression should update icon-offset."); @@ -258,11 +268,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconOffset = functionExpression; - std::map<float, std::array<float, 2>> innerStops { {18, { 1, 1 }} }; - mbgl::style::CompositeExponentialStops<std::array<float, 2>> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 }))) + ); + } + XCTAssertEqual(rawLayer->getIconOffset(), propertyValue, @"Setting iconOffset to a camera-data expression should update icon-offset."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -294,11 +306,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconOptional = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getIconOptional(), propertyValue, @"Setting iconOptional to a camera expression should update icon-optional."); @@ -325,23 +338,24 @@ @"icon-padding should be unset initially."); NSExpression *defaultExpression = layer.iconPadding; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.iconPadding = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getIconPadding(), propertyValue, @"Setting iconPadding to a constant value expression should update icon-padding."); XCTAssertEqualObjects(layer.iconPadding, constantExpression, @"iconPadding should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconPadding = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconPadding(), propertyValue, @"Setting iconPadding to a camera expression should update icon-padding."); @@ -380,11 +394,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconPitchAlignment = functionExpression; - mbgl::style::IntervalStops<mbgl::style::AlignmentType> intervalStops = {{ - { -INFINITY, mbgl::style::AlignmentType::Auto }, - { 18, mbgl::style::AlignmentType::Auto }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + step(zoom(), literal("auto"), 18.0, literal("auto")) + ); + } XCTAssertEqual(rawLayer->getIconPitchAlignment(), propertyValue, @"Setting iconPitchAlignment to a camera expression should update icon-pitch-alignment."); @@ -411,23 +426,24 @@ @"icon-rotate should be unset initially."); NSExpression *defaultExpression = layer.iconRotation; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.iconRotation = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getIconRotate(), propertyValue, @"Setting iconRotation to a constant value expression should update icon-rotate."); XCTAssertEqualObjects(layer.iconRotation, constantExpression, @"iconRotation should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconRotation = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconRotate(), propertyValue, @"Setting iconRotation to a camera expression should update icon-rotate."); @@ -437,8 +453,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconRotation = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconRotate(), propertyValue, @"Setting iconRotation to a data expression should update icon-rotate."); @@ -449,11 +469,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconRotation = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getIconRotate(), propertyValue, @"Setting iconRotation to a camera-data expression should update icon-rotate."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -485,11 +507,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconRotationAlignment = functionExpression; - mbgl::style::IntervalStops<mbgl::style::AlignmentType> intervalStops = {{ - { -INFINITY, mbgl::style::AlignmentType::Auto }, - { 18, mbgl::style::AlignmentType::Auto }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + step(zoom(), literal("auto"), 18.0, literal("auto")) + ); + } XCTAssertEqual(rawLayer->getIconRotationAlignment(), propertyValue, @"Setting iconRotationAlignment to a camera expression should update icon-rotation-alignment."); @@ -516,23 +539,24 @@ @"icon-size should be unset initially."); NSExpression *defaultExpression = layer.iconScale; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.iconScale = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getIconSize(), propertyValue, @"Setting iconScale to a constant value expression should update icon-size."); XCTAssertEqualObjects(layer.iconScale, constantExpression, @"iconScale should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconScale = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconSize(), propertyValue, @"Setting iconScale to a camera expression should update icon-size."); @@ -542,8 +566,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconScale = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconSize(), propertyValue, @"Setting iconScale to a data expression should update icon-size."); @@ -554,11 +582,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconScale = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getIconSize(), propertyValue, @"Setting iconScale to a camera-data expression should update icon-size."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -590,11 +620,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconTextFit = functionExpression; - mbgl::style::IntervalStops<mbgl::style::IconTextFitType> intervalStops = {{ - { -INFINITY, mbgl::style::IconTextFitType::Both }, - { 18, mbgl::style::IconTextFitType::Both }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::IconTextFitType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::IconTextFitType>( + step(zoom(), literal("both"), 18.0, literal("both")) + ); + } XCTAssertEqual(rawLayer->getIconTextFit(), propertyValue, @"Setting iconTextFit to a camera expression should update icon-text-fit."); @@ -639,11 +670,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconTextFitPadding = functionExpression; - mbgl::style::IntervalStops<std::array<float, 4>> intervalStops = {{ - { -INFINITY, { 1, 1, 1, 1 } }, - { 18, { 1, 1, 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 4>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 4>>( + step(zoom(), literal({ 1, 1, 1, 1 }), 18.0, literal({ 1, 1, 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getIconTextFitPadding(), propertyValue, @"Setting iconTextFitPadding to a camera expression should update icon-text-fit-padding."); @@ -682,11 +714,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.keepsIconUpright = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getIconKeepUpright(), propertyValue, @"Setting keepsIconUpright to a camera expression should update icon-keep-upright."); @@ -725,11 +758,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.keepsTextUpright = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, false }, - { 18, false }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(false), 18.0, literal(false)) + ); + } XCTAssertEqual(rawLayer->getTextKeepUpright(), propertyValue, @"Setting keepsTextUpright to a camera expression should update text-keep-upright."); @@ -756,23 +790,24 @@ @"text-max-angle should be unset initially."); NSExpression *defaultExpression = layer.maximumTextAngle; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.maximumTextAngle = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextMaxAngle(), propertyValue, @"Setting maximumTextAngle to a constant value expression should update text-max-angle."); XCTAssertEqualObjects(layer.maximumTextAngle, constantExpression, @"maximumTextAngle should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.maximumTextAngle = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextMaxAngle(), propertyValue, @"Setting maximumTextAngle to a camera expression should update text-max-angle."); @@ -799,23 +834,24 @@ @"text-max-width should be unset initially."); NSExpression *defaultExpression = layer.maximumTextWidth; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.maximumTextWidth = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextMaxWidth(), propertyValue, @"Setting maximumTextWidth to a constant value expression should update text-max-width."); XCTAssertEqualObjects(layer.maximumTextWidth, constantExpression, @"maximumTextWidth should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.maximumTextWidth = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextMaxWidth(), propertyValue, @"Setting maximumTextWidth to a camera expression should update text-max-width."); @@ -825,8 +861,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.maximumTextWidth = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextMaxWidth(), propertyValue, @"Setting maximumTextWidth to a data expression should update text-max-width."); @@ -837,11 +877,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.maximumTextWidth = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextMaxWidth(), propertyValue, @"Setting maximumTextWidth to a camera-data expression should update text-max-width."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -873,11 +915,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.symbolAvoidsEdges = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getSymbolAvoidEdges(), propertyValue, @"Setting symbolAvoidsEdges to a camera expression should update symbol-avoid-edges."); @@ -916,11 +959,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.symbolPlacement = functionExpression; - mbgl::style::IntervalStops<mbgl::style::SymbolPlacementType> intervalStops = {{ - { -INFINITY, mbgl::style::SymbolPlacementType::Line }, - { 18, mbgl::style::SymbolPlacementType::Line }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolPlacementType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolPlacementType>( + step(zoom(), literal("line"), 18.0, literal("line")) + ); + } XCTAssertEqual(rawLayer->getSymbolPlacement(), propertyValue, @"Setting symbolPlacement to a camera expression should update symbol-placement."); @@ -947,23 +991,24 @@ @"symbol-spacing should be unset initially."); NSExpression *defaultExpression = layer.symbolSpacing; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.symbolSpacing = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getSymbolSpacing(), propertyValue, @"Setting symbolSpacing to a constant value expression should update symbol-spacing."); XCTAssertEqualObjects(layer.symbolSpacing, constantExpression, @"symbolSpacing should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.symbolSpacing = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getSymbolSpacing(), propertyValue, @"Setting symbolSpacing to a camera expression should update symbol-spacing."); @@ -1002,11 +1047,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.text = functionExpression; - mbgl::style::IntervalStops<std::string> intervalStops = {{ - { -INFINITY, "Text Field" }, - { 18, "Text Field" }, - }}; - propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::string>( + step(zoom(), literal("Text Field"), 18.0, literal("Text Field")) + ); + } XCTAssertEqual(rawLayer->getTextField(), propertyValue, @"Setting text to a camera expression should update text-field."); @@ -1039,11 +1085,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textAllowsOverlap = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getTextAllowOverlap(), propertyValue, @"Setting textAllowsOverlap to a camera expression should update text-allow-overlap."); @@ -1082,11 +1129,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::SymbolAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::SymbolAnchorType::BottomRight }, - { 18, mbgl::style::SymbolAnchorType::BottomRight }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::SymbolAnchorType>( + step(zoom(), literal("bottom-right"), 18.0, literal("bottom-right")) + ); + } XCTAssertEqual(rawLayer->getTextAnchor(), propertyValue, @"Setting textAnchor to a camera expression should update text-anchor."); @@ -1119,11 +1167,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textFontNames = functionExpression; - mbgl::style::IntervalStops<std::vector<std::string>> intervalStops = {{ - { -INFINITY, { "Text Font", "Tnof Txet" } }, - { 18, { "Text Font", "Tnof Txet" } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::vector<std::string>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::vector<std::string>>( + step(zoom(), literal({ "Text Font", "Tnof Txet" }), 18.0, literal({ "Text Font", "Tnof Txet" })) + ); + } XCTAssertEqual(rawLayer->getTextFont(), propertyValue, @"Setting textFontNames to a camera expression should update text-font."); @@ -1144,23 +1193,24 @@ @"text-size should be unset initially."); NSExpression *defaultExpression = layer.textFontSize; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textFontSize = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextSize(), propertyValue, @"Setting textFontSize to a constant value expression should update text-size."); XCTAssertEqualObjects(layer.textFontSize, constantExpression, @"textFontSize should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textFontSize = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextSize(), propertyValue, @"Setting textFontSize to a camera expression should update text-size."); @@ -1170,8 +1220,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textFontSize = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextSize(), propertyValue, @"Setting textFontSize to a data expression should update text-size."); @@ -1182,11 +1236,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textFontSize = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextSize(), propertyValue, @"Setting textFontSize to a camera-data expression should update text-size."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1218,11 +1274,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textIgnoresPlacement = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getTextIgnorePlacement(), propertyValue, @"Setting textIgnoresPlacement to a camera expression should update text-ignore-placement."); @@ -1261,11 +1318,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textJustification = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TextJustifyType> intervalStops = {{ - { -INFINITY, mbgl::style::TextJustifyType::Right }, - { 18, mbgl::style::TextJustifyType::Right }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TextJustifyType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TextJustifyType>( + step(zoom(), literal("right"), 18.0, literal("right")) + ); + } XCTAssertEqual(rawLayer->getTextJustify(), propertyValue, @"Setting textJustification to a camera expression should update text-justify."); @@ -1286,23 +1344,24 @@ @"text-letter-spacing should be unset initially."); NSExpression *defaultExpression = layer.textLetterSpacing; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textLetterSpacing = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextLetterSpacing(), propertyValue, @"Setting textLetterSpacing to a constant value expression should update text-letter-spacing."); XCTAssertEqualObjects(layer.textLetterSpacing, constantExpression, @"textLetterSpacing should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textLetterSpacing = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextLetterSpacing(), propertyValue, @"Setting textLetterSpacing to a camera expression should update text-letter-spacing."); @@ -1312,8 +1371,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textLetterSpacing = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextLetterSpacing(), propertyValue, @"Setting textLetterSpacing to a data expression should update text-letter-spacing."); @@ -1324,11 +1387,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textLetterSpacing = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextLetterSpacing(), propertyValue, @"Setting textLetterSpacing to a camera-data expression should update text-letter-spacing."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1348,23 +1413,24 @@ @"text-line-height should be unset initially."); NSExpression *defaultExpression = layer.textLineHeight; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textLineHeight = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextLineHeight(), propertyValue, @"Setting textLineHeight to a constant value expression should update text-line-height."); XCTAssertEqualObjects(layer.textLineHeight, constantExpression, @"textLineHeight should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textLineHeight = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextLineHeight(), propertyValue, @"Setting textLineHeight to a camera expression should update text-line-height."); @@ -1409,11 +1475,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textOffset = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, @"Setting textOffset to a camera expression should update text-offset."); @@ -1423,8 +1490,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textOffset = functionExpression; - mbgl::style::ExponentialStops<std::array<float, 2>> exponentialStops = { {{18, { 1, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<std::array<float, 2>> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<std::array<float, 2>>( + interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, @"Setting textOffset to a data expression should update text-offset."); @@ -1435,11 +1506,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textOffset = functionExpression; - std::map<float, std::array<float, 2>> innerStops { {18, { 1, 1 }} }; - mbgl::style::CompositeExponentialStops<std::array<float, 2>> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal({ 1, 1 }))) + ); + } + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, @"Setting textOffset to a camera-data expression should update text-offset."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1471,11 +1544,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textOptional = functionExpression; - mbgl::style::IntervalStops<bool> intervalStops = {{ - { -INFINITY, true }, - { 18, true }, - }}; - propertyValue = mbgl::style::CameraFunction<bool> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<bool>( + step(zoom(), literal(true), 18.0, literal(true)) + ); + } XCTAssertEqual(rawLayer->getTextOptional(), propertyValue, @"Setting textOptional to a camera expression should update text-optional."); @@ -1502,23 +1576,24 @@ @"text-padding should be unset initially."); NSExpression *defaultExpression = layer.textPadding; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textPadding = constantExpression; - mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + mbgl::style::PropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextPadding(), propertyValue, @"Setting textPadding to a constant value expression should update text-padding."); XCTAssertEqualObjects(layer.textPadding, constantExpression, @"textPadding should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textPadding = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextPadding(), propertyValue, @"Setting textPadding to a camera expression should update text-padding."); @@ -1557,11 +1632,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textPitchAlignment = functionExpression; - mbgl::style::IntervalStops<mbgl::style::AlignmentType> intervalStops = {{ - { -INFINITY, mbgl::style::AlignmentType::Auto }, - { 18, mbgl::style::AlignmentType::Auto }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + step(zoom(), literal("auto"), 18.0, literal("auto")) + ); + } XCTAssertEqual(rawLayer->getTextPitchAlignment(), propertyValue, @"Setting textPitchAlignment to a camera expression should update text-pitch-alignment."); @@ -1588,23 +1664,24 @@ @"text-rotate should be unset initially."); NSExpression *defaultExpression = layer.textRotation; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textRotation = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, @"Setting textRotation to a constant value expression should update text-rotate."); XCTAssertEqualObjects(layer.textRotation, constantExpression, @"textRotation should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textRotation = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, @"Setting textRotation to a camera expression should update text-rotate."); @@ -1614,8 +1691,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textRotation = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, @"Setting textRotation to a data expression should update text-rotate."); @@ -1626,11 +1707,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textRotation = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, @"Setting textRotation to a camera-data expression should update text-rotate."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1662,11 +1745,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textRotationAlignment = functionExpression; - mbgl::style::IntervalStops<mbgl::style::AlignmentType> intervalStops = {{ - { -INFINITY, mbgl::style::AlignmentType::Auto }, - { 18, mbgl::style::AlignmentType::Auto }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType>( + step(zoom(), literal("auto"), 18.0, literal("auto")) + ); + } XCTAssertEqual(rawLayer->getTextRotationAlignment(), propertyValue, @"Setting textRotationAlignment to a camera expression should update text-rotation-alignment."); @@ -1705,11 +1789,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textTransform = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TextTransformType> intervalStops = {{ - { -INFINITY, mbgl::style::TextTransformType::Lowercase }, - { 18, mbgl::style::TextTransformType::Lowercase }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TextTransformType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TextTransformType>( + step(zoom(), literal("lowercase"), 18.0, literal("lowercase")) + ); + } XCTAssertEqual(rawLayer->getTextTransform(), propertyValue, @"Setting textTransform to a camera expression should update text-transform."); @@ -1742,11 +1827,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getIconColor(), propertyValue, @"Setting iconColor to a camera expression should update icon-color."); @@ -1756,8 +1842,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getIconColor(), propertyValue, @"Setting iconColor to a data expression should update icon-color."); @@ -1768,11 +1858,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getIconColor(), propertyValue, @"Setting iconColor to a camera-data expression should update icon-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1801,23 +1893,24 @@ @"icon-halo-blur should be unset initially."); NSExpression *defaultExpression = layer.iconHaloBlur; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.iconHaloBlur = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getIconHaloBlur(), propertyValue, @"Setting iconHaloBlur to a constant value expression should update icon-halo-blur."); XCTAssertEqualObjects(layer.iconHaloBlur, constantExpression, @"iconHaloBlur should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconHaloBlur = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconHaloBlur(), propertyValue, @"Setting iconHaloBlur to a camera expression should update icon-halo-blur."); @@ -1827,8 +1920,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconHaloBlur = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconHaloBlur(), propertyValue, @"Setting iconHaloBlur to a data expression should update icon-halo-blur."); @@ -1839,11 +1936,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconHaloBlur = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getIconHaloBlur(), propertyValue, @"Setting iconHaloBlur to a camera-data expression should update icon-halo-blur."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1884,11 +1983,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconHaloColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getIconHaloColor(), propertyValue, @"Setting iconHaloColor to a camera expression should update icon-halo-color."); @@ -1898,8 +1998,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconHaloColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getIconHaloColor(), propertyValue, @"Setting iconHaloColor to a data expression should update icon-halo-color."); @@ -1910,11 +2014,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconHaloColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getIconHaloColor(), propertyValue, @"Setting iconHaloColor to a camera-data expression should update icon-halo-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -1943,23 +2049,24 @@ @"icon-halo-width should be unset initially."); NSExpression *defaultExpression = layer.iconHaloWidth; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.iconHaloWidth = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getIconHaloWidth(), propertyValue, @"Setting iconHaloWidth to a constant value expression should update icon-halo-width."); XCTAssertEqualObjects(layer.iconHaloWidth, constantExpression, @"iconHaloWidth should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconHaloWidth = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconHaloWidth(), propertyValue, @"Setting iconHaloWidth to a camera expression should update icon-halo-width."); @@ -1969,8 +2076,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconHaloWidth = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconHaloWidth(), propertyValue, @"Setting iconHaloWidth to a data expression should update icon-halo-width."); @@ -1981,11 +2092,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconHaloWidth = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getIconHaloWidth(), propertyValue, @"Setting iconHaloWidth to a camera-data expression should update icon-halo-width."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2014,23 +2127,24 @@ @"icon-opacity should be unset initially."); NSExpression *defaultExpression = layer.iconOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.iconOpacity = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getIconOpacity(), propertyValue, @"Setting iconOpacity to a constant value expression should update icon-opacity."); XCTAssertEqualObjects(layer.iconOpacity, constantExpression, @"iconOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconOpacity(), propertyValue, @"Setting iconOpacity to a camera expression should update icon-opacity."); @@ -2040,8 +2154,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.iconOpacity = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getIconOpacity(), propertyValue, @"Setting iconOpacity to a data expression should update icon-opacity."); @@ -2052,11 +2170,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.iconOpacity = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getIconOpacity(), propertyValue, @"Setting iconOpacity to a camera-data expression should update icon-opacity."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2103,11 +2223,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconTranslation = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getIconTranslate(), propertyValue, @"Setting iconTranslation to a camera expression should update icon-translate."); @@ -2146,11 +2267,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.iconTranslationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::TranslateAnchorType::Viewport }, - { 18, mbgl::style::TranslateAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getIconTranslateAnchor(), propertyValue, @"Setting iconTranslationAnchor to a camera expression should update icon-translate-anchor."); @@ -2189,11 +2311,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getTextColor(), propertyValue, @"Setting textColor to a camera expression should update text-color."); @@ -2203,8 +2326,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getTextColor(), propertyValue, @"Setting textColor to a data expression should update text-color."); @@ -2215,11 +2342,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getTextColor(), propertyValue, @"Setting textColor to a camera-data expression should update text-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2248,23 +2377,24 @@ @"text-halo-blur should be unset initially."); NSExpression *defaultExpression = layer.textHaloBlur; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textHaloBlur = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextHaloBlur(), propertyValue, @"Setting textHaloBlur to a constant value expression should update text-halo-blur."); XCTAssertEqualObjects(layer.textHaloBlur, constantExpression, @"textHaloBlur should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textHaloBlur = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextHaloBlur(), propertyValue, @"Setting textHaloBlur to a camera expression should update text-halo-blur."); @@ -2274,8 +2404,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textHaloBlur = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextHaloBlur(), propertyValue, @"Setting textHaloBlur to a data expression should update text-halo-blur."); @@ -2286,11 +2420,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textHaloBlur = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextHaloBlur(), propertyValue, @"Setting textHaloBlur to a camera-data expression should update text-halo-blur."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2331,11 +2467,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textHaloColor = functionExpression; - mbgl::style::IntervalStops<mbgl::Color> intervalStops = {{ - { -INFINITY, { 1, 0, 0, 1 } }, - { 18, { 1, 0, 0, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::Color>( + step(zoom(), literal(mbgl::Color(1, 0, 0, 1)), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getTextHaloColor(), propertyValue, @"Setting textHaloColor to a camera expression should update text-halo-color."); @@ -2345,8 +2482,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textHaloColor = functionExpression; - mbgl::style::ExponentialStops<mbgl::Color> exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<mbgl::Color> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<mbgl::Color>( + interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1))) + ); + } XCTAssertEqual(rawLayer->getTextHaloColor(), propertyValue, @"Setting textHaloColor to a data expression should update text-halo-color."); @@ -2357,11 +2498,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textHaloColor = functionExpression; - std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} }; - mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<mbgl::Color>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(mbgl::Color(1, 0, 0, 1)))) + ); + } + XCTAssertEqual(rawLayer->getTextHaloColor(), propertyValue, @"Setting textHaloColor to a camera-data expression should update text-halo-color."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2390,23 +2533,24 @@ @"text-halo-width should be unset initially."); NSExpression *defaultExpression = layer.textHaloWidth; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textHaloWidth = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextHaloWidth(), propertyValue, @"Setting textHaloWidth to a constant value expression should update text-halo-width."); XCTAssertEqualObjects(layer.textHaloWidth, constantExpression, @"textHaloWidth should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textHaloWidth = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextHaloWidth(), propertyValue, @"Setting textHaloWidth to a camera expression should update text-halo-width."); @@ -2416,8 +2560,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textHaloWidth = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextHaloWidth(), propertyValue, @"Setting textHaloWidth to a data expression should update text-halo-width."); @@ -2428,11 +2576,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textHaloWidth = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextHaloWidth(), propertyValue, @"Setting textHaloWidth to a camera-data expression should update text-halo-width."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2461,23 +2611,24 @@ @"text-opacity should be unset initially."); NSExpression *defaultExpression = layer.textOpacity; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; layer.textOpacity = constantExpression; - mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 1.0 }; XCTAssertEqual(rawLayer->getTextOpacity(), propertyValue, @"Setting textOpacity to a constant value expression should update text-opacity."); XCTAssertEqualObjects(layer.textOpacity, constantExpression, @"textOpacity should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"0xff"]; + constantExpression = [NSExpression expressionWithFormat:@"1"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textOpacity = functionExpression; - mbgl::style::IntervalStops<float> intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction<float> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<float>( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextOpacity(), propertyValue, @"Setting textOpacity to a camera expression should update text-opacity."); @@ -2487,8 +2638,12 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; layer.textOpacity = functionExpression; - mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction<float>( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } XCTAssertEqual(rawLayer->getTextOpacity(), propertyValue, @"Setting textOpacity to a data expression should update text-opacity."); @@ -2499,11 +2654,13 @@ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; layer.textOpacity = functionExpression; - std::map<float, float> innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction<float>( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + XCTAssertEqual(rawLayer->getTextOpacity(), propertyValue, @"Setting textOpacity to a camera-data expression should update text-opacity."); pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; @@ -2550,11 +2707,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textTranslation = functionExpression; - mbgl::style::IntervalStops<std::array<float, 2>> intervalStops = {{ - { -INFINITY, { 1, 1 } }, - { 18, { 1, 1 } }, - }}; - propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<std::array<float, 2>>( + step(zoom(), literal({ 1, 1 }), 18.0, literal({ 1, 1 })) + ); + } XCTAssertEqual(rawLayer->getTextTranslate(), propertyValue, @"Setting textTranslation to a camera expression should update text-translate."); @@ -2593,11 +2751,12 @@ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.textTranslationAnchor = functionExpression; - mbgl::style::IntervalStops<mbgl::style::TranslateAnchorType> intervalStops = {{ - { -INFINITY, mbgl::style::TranslateAnchorType::Viewport }, - { 18, mbgl::style::TranslateAnchorType::Viewport }, - }}; - propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType>( + step(zoom(), literal("viewport"), 18.0, literal("viewport")) + ); + } XCTAssertEqual(rawLayer->getTextTranslateAnchor(), propertyValue, @"Setting textTranslationAnchor to a camera expression should update text-translate-anchor."); diff --git a/src/mbgl/style/expression/dsl.cpp b/src/mbgl/style/expression/dsl.cpp index 9f204cadc9..15822ccf66 100644 --- a/src/mbgl/style/expression/dsl.cpp +++ b/src/mbgl/style/expression/dsl.cpp @@ -3,6 +3,7 @@ #include <mbgl/style/expression/assertion.hpp> #include <mbgl/style/expression/coercion.hpp> #include <mbgl/style/expression/equals.hpp> +#include <mbgl/style/expression/step.hpp> #include <mbgl/style/expression/interpolate.hpp> #include <mbgl/style/expression/compound_expression.hpp> #include <mbgl/util/ignore.hpp> @@ -35,6 +36,22 @@ std::unique_ptr<Expression> literal(Value value) { return std::make_unique<Literal>(value); } +std::unique_ptr<Expression> literal(std::initializer_list<double> value) { + std::vector<Value> values; + for (auto i : value) { + values.push_back(i); + } + return literal(values); +} + +std::unique_ptr<Expression> literal(std::initializer_list<const char *> value) { + std::vector<Value> values; + for (auto i : value) { + values.push_back(std::string(i)); + } + return literal(values); +} + std::unique_ptr<Expression> number(std::unique_ptr<Expression> value) { return std::make_unique<Assertion>(type::Number, vec(std::move(value))); } @@ -87,6 +104,16 @@ std::unique_ptr<Expression> lt(std::unique_ptr<Expression> lhs, return compound("<", std::move(lhs), std::move(rhs)); } +std::unique_ptr<Expression> step(std::unique_ptr<Expression> input, + std::unique_ptr<Expression> output0, + double input1, std::unique_ptr<Expression> output1) { + type::Type type = output0->getType(); + std::map<double, std::unique_ptr<Expression>> stops; + stops[-std::numeric_limits<double>::infinity()] = std::move(output0); + stops[input1] = std::move(output1); + return std::make_unique<Step>(type, std::move(input), std::move(stops)); +} + Interpolator linear() { return ExponentialInterpolator(1.0); } |