From 6dfe56510caa87b3e0fdbb8256d13ec955764d53 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 28 Jun 2018 14:58:52 -0700 Subject: [darwin] Replace use of *Stops with expressions DSL --- platform/darwin/test/MGLHeatmapStyleLayerTests.mm | 109 +++++++++++++--------- 1 file changed, 63 insertions(+), 46 deletions(-) (limited to 'platform/darwin/test/MGLHeatmapStyleLayerTests.mm') 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 #include +#include @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 propertyValue = { 0xff }; + mbgl::style::PropertyValue 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 intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction( + 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 propertyValue = { 0xff }; + mbgl::style::PropertyValue 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 intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction( + 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 propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue 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 intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction( + 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 exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction( + 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 innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction( + 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 propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue 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 intervalStops = {{ - { -INFINITY, 0xff }, - { 18, 0xff }, - }}; - propertyValue = mbgl::style::CameraFunction { intervalStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CameraFunction( + 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 exponentialStops = { {{18, 0xff}}, 1.0 }; - propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::SourceFunction( + 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 innerStops { {18, 0xff} }; - mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; - - propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; - + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::CompositeFunction( + 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}]; -- cgit v1.2.1