summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-06-27 16:57:23 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-06-29 15:38:11 -0700
commit542a4b4501794653b55fd1ffc60cb01348d8fc88 (patch)
tree9e451d4117427044d4155396992faf0495a544f7 /test
parent16a3f318a13448a46a4f59b0e8df6a7f0b73bc17 (diff)
downloadqtlocation-mapboxgl-542a4b4501794653b55fd1ffc60cb01348d8fc88.tar.gz
[core] Replace use of *Stops with expressions DSL
Diffstat (limited to 'test')
-rw-r--r--test/api/query.test.cpp20
-rw-r--r--test/programs/symbol_program.test.cpp52
-rw-r--r--test/renderer/group_by_layout.test.cpp6
-rw-r--r--test/style/conversion/stringify.test.cpp73
-rw-r--r--test/style/function/camera_function.test.cpp59
-rw-r--r--test/style/function/composite_function.test.cpp69
-rw-r--r--test/style/function/source_function.test.cpp76
-rw-r--r--test/style/properties.test.cpp11
8 files changed, 143 insertions, 223 deletions
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index ffab52692b..5960de3b31 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -8,6 +8,7 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/style/source.hpp>
+#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/gl/headless_frontend.hpp>
@@ -67,20 +68,20 @@ TEST(Query, QueryRenderedFeaturesFilterLayer) {
}
TEST(Query, QueryRenderedFeaturesFilter) {
- QueryTest test;
- ParsingContext context;
+ using namespace mbgl::style::expression::dsl;
+ QueryTest test;
auto zz = test.map.pixelForLatLng({ 0, 0 });
- const Filter eqFilter(createCompoundExpression("filter-==", createLiteral("key1"), createLiteral("value1"), context));
+ const Filter eqFilter(eq(get("key1"), literal("value1")));
auto features1 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{}, { eqFilter }});
EXPECT_EQ(features1.size(), 1u);
- const Filter idNotEqFilter(createCompoundExpression("!", std::move(*createCompoundExpression("filter-id-==", createLiteral("feature1"), context)), context));
+ const Filter idNotEqFilter(ne(id(), literal("feature1")));
auto features2 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{{ "layer4" }}, { idNotEqFilter }});
EXPECT_EQ(features2.size(), 0u);
- const Filter gtFilter(createCompoundExpression("filter->", createLiteral("key2"), createLiteral(1.0), context));
+ const Filter gtFilter(gt(number(get("key2")), literal(1.0)));
auto features3 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{ }, { gtFilter }});
EXPECT_EQ(features3.size(), 1u);
}
@@ -109,18 +110,19 @@ TEST(Query, QuerySourceFeaturesOptionValidation) {
}
TEST(Query, QuerySourceFeaturesFilter) {
+ using namespace mbgl::style::expression::dsl;
+
QueryTest test;
- ParsingContext context;
- const Filter eqFilter(createCompoundExpression("filter-==", createLiteral("key1"), createLiteral("value1"), context));
+ const Filter eqFilter(eq(get("key1"), literal("value1")));
auto features1 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { eqFilter }});
EXPECT_EQ(features1.size(), 1u);
- const Filter idNotEqFilter(createCompoundExpression("!", std::move(*createCompoundExpression("filter-id-==", createLiteral("feature1"), context)), context));
+ const Filter idNotEqFilter(ne(id(), literal("feature1")));
auto features2 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { idNotEqFilter }});
EXPECT_EQ(features2.size(), 0u);
- const Filter gtFilter(createCompoundExpression("filter->", createLiteral("key2"), createLiteral(1.0), context));
+ const Filter gtFilter(gt(number(get("key2")), literal(1.0)));
auto features3 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { gtFilter }});
EXPECT_EQ(features3.size(), 1u);
}
diff --git a/test/programs/symbol_program.test.cpp b/test/programs/symbol_program.test.cpp
index 62a2e58d7b..ed709a4ba7 100644
--- a/test/programs/symbol_program.test.cpp
+++ b/test/programs/symbol_program.test.cpp
@@ -1,8 +1,10 @@
#include <mbgl/test/util.hpp>
#include <mbgl/programs/symbol_program.hpp>
+#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
+using namespace mbgl::style::expression::dsl;
TEST(SymbolProgram, SymbolSizeBinder) {
auto binder = SymbolSizeBinder::create(5.0f, 12.0f, 0.0f);
@@ -11,45 +13,55 @@ TEST(SymbolProgram, SymbolSizeBinder) {
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true);
EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 12.0f);
- binder = SymbolSizeBinder::create(1.0f, style::CameraFunction<float>(style::ExponentialStops<float>({
- {0.0f, 8.0f},
- {10.0f, 18.0f}
- }, 1.0f)), 0.0f);
+ binder = SymbolSizeBinder::create(1.0f, style::CameraFunction<float>(
+ interpolate(
+ linear(),
+ zoom(),
+ 0., literal(8.),
+ 10., literal(18.))), 0.0f);
uniformValues = binder->uniformValues(1.5f);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true);
EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 9.5f);
- binder = SymbolSizeBinder::create(0.0f, style::CameraFunction<float>(style::ExponentialStops<float>({
- {1.0f, 8.0f},
- {11.0f, 18.0f}
- }, 1.0f)), 0.0f);
+ binder = SymbolSizeBinder::create(0.0f, style::CameraFunction<float>(
+ interpolate(
+ linear(),
+ zoom(),
+ 1., literal(8.),
+ 11., literal(18.))), 0.0f);
uniformValues = binder->uniformValues(0.5f);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true);
EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 8.0f);
- binder = SymbolSizeBinder::create(12.0f, style::CameraFunction<float>(style::ExponentialStops<float>({
- {1.0f, 8.0f},
- {11.0f, 18.0f}
- }, 1.0f)), 0.0f);
+ binder = SymbolSizeBinder::create(12.0f, style::CameraFunction<float>(
+ interpolate(
+ linear(),
+ zoom(),
+ 1., literal(8.),
+ 11., literal(18.))), 0.0f);
uniformValues = binder->uniformValues(12.5f);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true);
EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 18.0f);
- binder = SymbolSizeBinder::create(0.0f, style::SourceFunction<float>("x", style::ExponentialStops<float>({
- {1.0f, 8.0f},
- {11.0f, 18.0f}
- }, 1.0f)), 0.0f);
+ binder = SymbolSizeBinder::create(0.0f, style::SourceFunction<float>(
+ interpolate(
+ linear(),
+ number(get("x")),
+ 1., literal(8.),
+ 11., literal(18.))), 0.0f);
uniformValues = binder->uniformValues(12.5f);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, true);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, false);
- binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction<float>("x", style::CompositeExponentialStops<float>({
- {1.0f, {{0.0f, 8.0f}, {100.0f, 18.0f}}},
- {11.0f, {{0.0f, 12.0f}, {100.0f, 24.9f}}}
- }, 1.0f)), 0.0f);
+ binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction<float>(
+ interpolate(
+ linear(),
+ zoom(),
+ 1., interpolate(linear(), number(get("x")), 0., literal(8.), 100., literal(18.)),
+ 11., interpolate(linear(), number(get("x")), 0., literal(12.), 100., literal(24.9)))), 0.0f);
uniformValues = binder->uniformValues(5.5f);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false);
EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, false);
diff --git a/test/renderer/group_by_layout.test.cpp b/test/renderer/group_by_layout.test.cpp
index 6cf17e2279..8d0b432481 100644
--- a/test/renderer/group_by_layout.test.cpp
+++ b/test/renderer/group_by_layout.test.cpp
@@ -5,7 +5,7 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
-#include <mbgl/style/expression/compound_expression.hpp>
+#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
using namespace mbgl::style;
@@ -38,11 +38,11 @@ TEST(GroupByLayout, UnrelatedType) {
}
TEST(GroupByLayout, UnrelatedFilter) {
+ using namespace mbgl::style::expression::dsl;
std::vector<std::unique_ptr<Layer>> layers;
layers.push_back(std::make_unique<LineLayer>("a", "source"));
layers.push_back(std::make_unique<LineLayer>("b", "source"));
- ParsingContext context;
- layers[0]->as<LineLayer>()->setFilter(Filter(createCompoundExpression("filter-has-id", context)));
+ layers[0]->as<LineLayer>()->setFilter(Filter(get("property")));
auto result = groupByLayout(toRenderLayers(layers));
ASSERT_EQ(2u, result.size());
}
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp
index c3faf1f838..567c022036 100644
--- a/test/style/conversion/stringify.test.cpp
+++ b/test/style/conversion/stringify.test.cpp
@@ -4,6 +4,7 @@
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
+#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <rapidjson/writer.h>
@@ -76,56 +77,62 @@ TEST(Stringify, Value) {
}
TEST(Stringify, Filter) {
- using namespace mbgl::style::expression;
-
+ using namespace mbgl::style::expression::dsl;
ASSERT_EQ(stringify(Filter()), "null");
-
- ParsingContext context;
- ASSERT_EQ(stringify(Filter(createCompoundExpression("filter-==", createLiteral("a"), createLiteral(1.0), context))), "[\"filter-==\",\"a\",1.0]");
+ ASSERT_EQ(stringify(Filter(eq(literal("a"), literal(1.0)))), "[\"==\",\"a\",1.0]");
}
TEST(Stringify, CameraFunction) {
- ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 1 })),
- "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0]");
- ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 })),
- "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]");
- ASSERT_EQ(stringify(CameraFunction<float>(IntervalStops<float> { {{0, 1}} })),
- "[\"step\",[\"zoom\"],0.0,1.0]");
+ using namespace mbgl::style::expression::dsl;
+ ASSERT_EQ(stringify(CameraFunction<float>(
+ interpolate(
+ linear(),
+ zoom(),
+ 0.0, literal(1.0),
+ 1.0, literal(2.0)
+ ))),
+ "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0,1.0,2.0]");
}
TEST(Stringify, SourceFunction) {
- ASSERT_EQ(stringify(SourceFunction<float>("property", ExponentialStops<float> { {{0, 1}}, 2 })),
- "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]");
- ASSERT_EQ(stringify(SourceFunction<float>("property", IntervalStops<float> { {{0, 1}} })),
- "[\"step\",[\"number\",[\"get\",\"property\"]],0.0,1.0]");
- ASSERT_EQ(stringify(SourceFunction<float>("property", CategoricalStops<float> { {{CategoricalValue(true), 1}} })),
- "[\"case\",[\"boolean\",[\"get\",\"property\"]],1.0,[\"error\"]]");
- ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {})),
- "[\"number\",[\"get\",\"property\"]]");
- ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {}, 0.0f)),
- "[\"number\",[\"get\",\"property\"]]");
+ using namespace mbgl::style::expression::dsl;
+ ASSERT_EQ(stringify(SourceFunction<float>(
+ interpolate(
+ exponential(2.0),
+ number(get("property")),
+ 0.0, literal(1.0),
+ 1.0, literal(2.0)
+ ))),
+ "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]");
}
TEST(Stringify, CompositeFunction) {
- ASSERT_EQ(stringify(CompositeFunction<float>("property",
- CompositeExponentialStops<float> {
- {
- { 0, {{0, 1}} },
- { 1, {{0, 1}} }
- },
- 2
- }, 0.0f)),
+ using namespace mbgl::style::expression::dsl;
+ ASSERT_EQ(stringify(CompositeFunction<float>(
+ interpolate(
+ linear(),
+ zoom(),
+ 0.0, interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0)),
+ 1.0, interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0))
+ ))),
"[\"interpolate\","
"[\"linear\"],"
"[\"zoom\"],"
- "0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0],"
- "1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]]");
+ "0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0],"
+ "1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]]");
}
TEST(Stringify, PropertyValue) {
+ using namespace mbgl::style::expression::dsl;
ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0");
- ASSERT_EQ(stringify(PropertyValue<float>(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 }))),
- "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]");
+ ASSERT_EQ(stringify(PropertyValue<float>(CameraFunction<float>(
+ interpolate(
+ exponential(2.0),
+ zoom(),
+ 0.0, literal(1.0),
+ 1.0, literal(2.0)
+ )))),
+ "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0,1.0,2.0]");
}
TEST(Stringify, Layout) {
diff --git a/test/style/function/camera_function.test.cpp b/test/style/function/camera_function.test.cpp
index 59e3f2cef3..1f7e81fc2c 100644
--- a/test/style/function/camera_function.test.cpp
+++ b/test/style/function/camera_function.test.cpp
@@ -3,19 +3,15 @@
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/property_evaluation_parameters.hpp>
+#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
using namespace mbgl::style;
+using namespace mbgl::style::expression::dsl;
float evaluate(PropertyValue<float> value, float zoom) {
return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
}
-std::string evaluate(PropertyValue<std::string> value, float zoom) {
- return value.evaluate(PropertyEvaluator<std::string>(PropertyEvaluationParameters(zoom), ""));
-}
-bool evaluate(PropertyValue<bool> value, float zoom) {
- return value.evaluate(PropertyEvaluator<bool>(PropertyEvaluationParameters(zoom), false));
-}
TEST(CameraFunction, Constant) {
EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0));
@@ -29,51 +25,8 @@ TEST(CameraFunction, Constant) {
EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 22));
}
-TEST(CameraFunction, Stops) {
- // Explicit constant slope in fringe regions.
- CameraFunction<float> slope_1(ExponentialStops<float> { { { 0, 1.5 }, { 6, 1.5 }, { 8, 3 }, { 22, 3 } }, 1.75});
- EXPECT_EQ(1.5, evaluate(slope_1, 0));
- EXPECT_EQ(1.5, evaluate(slope_1, 4));
- EXPECT_EQ(1.5, evaluate(slope_1, 6));
- ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, 7));
- EXPECT_EQ(3.0, evaluate(slope_1, 8));
- EXPECT_EQ(3.0, evaluate(slope_1, 9));
- EXPECT_EQ(3.0, evaluate(slope_1, 15));
- EXPECT_EQ(3.0, evaluate(slope_1, 22));
-
-
- // Test constant values in fringe regions.
- CameraFunction<float> slope_2(ExponentialStops<float> { { { 6, 1.5 }, { 8, 3 } }, 1.75 });
- EXPECT_EQ(1.5, evaluate(slope_2, 0));
- EXPECT_EQ(1.5, evaluate(slope_2, 4));
- EXPECT_EQ(1.5, evaluate(slope_2, 6));
- ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, 7));
- EXPECT_EQ(3.0, evaluate(slope_2, 8));
- EXPECT_EQ(3.0, evaluate(slope_2, 9));
- EXPECT_EQ(3.0, evaluate(slope_2, 15));
- EXPECT_EQ(3.0, evaluate(slope_2, 22));
-
-
- // Explicit constant slope in fringe regions.
- CameraFunction<float> slope_4(ExponentialStops<float> { { { 0, 2 }, { 8, 10 } }, 1 });
- EXPECT_EQ(2, evaluate(slope_4, 0));
- EXPECT_EQ(3, evaluate(slope_4, 1));
- EXPECT_EQ(4, evaluate(slope_4, 2));
- EXPECT_EQ(4.75, evaluate(slope_4, 2.75));
- EXPECT_EQ(10, evaluate(slope_4, 8));
-
- // discrete values
- CameraFunction<std::string> discrete_0(IntervalStops<std::string> { {{3, "string0"}, {6, "string1"}, {9, "string2"}} });
- EXPECT_EQ("string0", evaluate(discrete_0, 2));
- EXPECT_EQ("string0", evaluate(discrete_0, 4));
- EXPECT_EQ("string1", evaluate(discrete_0, 7));
- EXPECT_EQ("string2", evaluate(discrete_0, 9));
- EXPECT_EQ("string2", evaluate(discrete_0, 10));
-
- CameraFunction<bool> discreteBool(IntervalStops<bool> { {{1, false}, {3, true}} });
- EXPECT_FALSE(evaluate(discreteBool, 0));
- EXPECT_FALSE(evaluate(discreteBool, 1));
- EXPECT_FALSE(evaluate(discreteBool, 2));
- EXPECT_TRUE(evaluate(discreteBool, 3));
- EXPECT_TRUE(evaluate(discreteBool, 4));
+TEST(CameraFunction, Expression) {
+ CameraFunction<float> function(interpolate(linear(), zoom(), 0.0, literal(0.0), 1.0, literal(1.0)));
+ EXPECT_EQ(0.0, evaluate(function, 0.0));
+ EXPECT_EQ(0.5, evaluate(function, 0.5));
}
diff --git a/test/style/function/composite_function.test.cpp b/test/style/function/composite_function.test.cpp
index 09b79a8b8f..917689ce23 100644
--- a/test/style/function/composite_function.test.cpp
+++ b/test/style/function/composite_function.test.cpp
@@ -2,9 +2,11 @@
#include <mbgl/test/stub_geometry_tile_feature.hpp>
#include <mbgl/style/function/composite_function.hpp>
+#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
using namespace mbgl::style;
+using namespace mbgl::style::expression::dsl;
using namespace std::string_literals;
@@ -13,54 +15,61 @@ static StubGeometryTileFeature oneInteger {
};
TEST(CompositeFunction, ZoomInterpolation) {
- EXPECT_EQ(40.0f, CompositeFunction<float>("property", CompositeExponentialStops<float>({
- {0.0f, {{uint64_t(1), 24.0f}}},
- {1.5f, {{uint64_t(1), 36.0f}}},
- {3.0f, {{uint64_t(1), 48.0f}}}
- }), 0.0f)
+ EXPECT_EQ(40.0f, CompositeFunction<float>(
+ interpolate(linear(), zoom(),
+ 0.0, interpolate(linear(), number(get("property")), 1.0, literal(24.0)),
+ 1.5, interpolate(linear(), number(get("property")), 1.0, literal(36.0)),
+ 3.0, interpolate(linear(), number(get("property")), 1.0, literal(48.0))
+ ), 0.0f)
.evaluate(2.0f, oneInteger, -1.0f)) << "Should interpolate between stops";
- EXPECT_EQ(33.0, CompositeFunction<float>("property", CompositeExponentialStops<float>({
- {5.0f, {{uint64_t(1), 33.0f}}},
- {10.0f, {{uint64_t(1), 66.0f}}}
- }), 0.0f)
+ EXPECT_EQ(33.0, CompositeFunction<float>(
+ interpolate(linear(), zoom(),
+ 5.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
+ 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
+ ), 0.0f)
.evaluate(0.0f, oneInteger, -1.0f)) << "Use first stop output for input values from -inf to first stop";
- EXPECT_EQ(66.0, CompositeFunction<float>("property", CompositeExponentialStops<float>({
- {0.0f, {{uint64_t(1), 33.0f}}},
- {10.0f, {{uint64_t(1), 66.0f}}}
- }), 0.0f)
+ EXPECT_EQ(66.0, CompositeFunction<float>(
+ interpolate(linear(), zoom(),
+ 0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
+ 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
+ ), 0.0f)
.evaluate(20.0f, oneInteger, -1.0f)) << "Use last stop output for input values from last stop to +inf";
- EXPECT_EQ(66.0f, CompositeFunction<float>("property", CompositeExponentialStops<float>({
- {0.0f, {{uint64_t(1), 33.0f}}},
- {10.0f, {{uint64_t(1), 66.0f}}}
- }), 0.0f)
+ EXPECT_EQ(66.0f, CompositeFunction<float>(
+ interpolate(linear(), zoom(),
+ 0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
+ 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
+ ), 0.0f)
.evaluate(10.0f, oneInteger, -1.0f)) << "Should interpolate TO the last stop.";
- EXPECT_EQ(33.0f, CompositeFunction<float>("property", CompositeExponentialStops<float>({
- {0.0f, {{uint64_t(1), 33.0f}}},
- {10.0f, {{uint64_t(1), 66.0f}}}
- }), 0.0f)
+ EXPECT_EQ(33.0f, CompositeFunction<float>(
+ interpolate(linear(), zoom(),
+ 0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
+ 10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
+ ), 0.0f)
.evaluate(0.0f, oneInteger, -1.0f)) << "Should interpolate TO the first stop";
}
TEST(CompositeFunction, Issue8460) {
- CompositeFunction<float> fn1("property", CompositeExponentialStops<float>({
- {15.0f, {{uint64_t(1), 0.0f}}},
- {15.2f, {{uint64_t(1), 600.0f}}},
- }), 0.0f);
+ CompositeFunction<float> fn1(
+ interpolate(linear(), zoom(),
+ 15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
+ 15.2, interpolate(linear(), number(get("property")), 1.0, literal(600.0))
+ ), 0.0f);
EXPECT_NEAR( 0.0f, fn1.evaluate(15.0f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(300.0f, fn1.evaluate(15.1f, oneInteger, -1.0f), 0.01);
EXPECT_NEAR(600.0f, fn1.evaluate(15.2f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(600.0f, fn1.evaluate(16.0f, oneInteger, -1.0f), 0.00);
- CompositeFunction<float> fn2("property", CompositeExponentialStops<float>({
- {15.0f, {{uint64_t(1), 0.0f}}},
- {15.2f, {{uint64_t(1), 300.0f}}},
- {18.0f, {{uint64_t(1), 600.0f}}},
- }), 0.0f);
+ CompositeFunction<float> fn2(
+ interpolate(linear(), zoom(),
+ 15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
+ 15.2, interpolate(linear(), number(get("property")), 1.0, literal(300.0)),
+ 18.0, interpolate(linear(), number(get("property")), 1.0, literal(600.0))
+ ), 0.0f);
EXPECT_NEAR( 0.0f, fn2.evaluate(15.0f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(150.0f, fn2.evaluate(15.1f, oneInteger, -1.0f), 0.01);
diff --git a/test/style/function/source_function.test.cpp b/test/style/function/source_function.test.cpp
index 46ad961002..d1e5e1a974 100644
--- a/test/style/function/source_function.test.cpp
+++ b/test/style/function/source_function.test.cpp
@@ -2,6 +2,7 @@
#include <mbgl/test/stub_geometry_tile_feature.hpp>
#include <mbgl/style/function/source_function.hpp>
+#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
using namespace mbgl::style;
@@ -20,78 +21,15 @@ static StubGeometryTileFeature oneString {
PropertyMap {{ "property", "1"s }}
};
-static StubGeometryTileFeature red {
- PropertyMap {{ "property", "red"s }}
-};
-
-static StubGeometryTileFeature oneTwoInteger {
- PropertyMap {{ "property", std::vector<Value>({uint64_t(1), uint64_t(2)}) }}
-};
-
-static StubGeometryTileFeature oneTwoDouble {
- PropertyMap {{ "property", std::vector<Value>({1.0, 2.0}) }}
-};
-
-static StubGeometryTileFeature oneTwoString {
- PropertyMap {{ "property", std::vector<Value>({"1"s, "2"s}) }}
-};
-
-static StubGeometryTileFeature trueFeature {
- PropertyMap {{ "property", true }}
-};
+TEST(SourceFunction, Defaults) {
+ using namespace mbgl::style::expression::dsl;
-static StubGeometryTileFeature falseFeature {
- PropertyMap {{ "property", false }}
-};
-
-TEST(SourceFunction, Identity) {
- EXPECT_EQ(1.0f, SourceFunction<float>("property", IdentityStops<float>(), 0.0f)
+ EXPECT_EQ(1.0f, SourceFunction<float>(number(get("property")), 0.0)
.evaluate(oneInteger, 2.0f));
- EXPECT_EQ(1.0f, SourceFunction<float>("property", IdentityStops<float>(), 0.0f)
+ EXPECT_EQ(1.0f, SourceFunction<float>(number(get("property")), 0.0)
.evaluate(oneDouble, 2.0f));
- EXPECT_EQ(0.0f, SourceFunction<float>("property", IdentityStops<float>(), 0.0f)
+ EXPECT_EQ(0.0f, SourceFunction<float>(number(get("property")), 0.0)
.evaluate(oneString, 2.0f));
- EXPECT_EQ(2.0f, SourceFunction<float>("property", IdentityStops<float>())
+ EXPECT_EQ(2.0f, SourceFunction<float>(number(get("property")))
.evaluate(oneString, 2.0f));
-
- EXPECT_EQ(Color::red(), SourceFunction<Color>("property", IdentityStops<Color>(), Color::black())
- .evaluate(red, Color::black()));
- EXPECT_EQ(Color::black(), SourceFunction<Color>("property", IdentityStops<Color>(), Color::black())
- .evaluate(oneInteger, Color::black()));
-
- std::array<float, 2> zeroArray {{ 0, 0 }};
- EXPECT_EQ((std::array<float, 2> {{ 1, 2 }}), (SourceFunction<std::array<float, 2>>("property", IdentityStops<std::array<float, 2>>(), zeroArray)
- .evaluate(oneTwoInteger, zeroArray)));
- EXPECT_EQ((std::array<float, 2> {{ 1, 2 }}), (SourceFunction<std::array<float, 2>>("property", IdentityStops<std::array<float, 2>>(), zeroArray)
- .evaluate(oneTwoDouble, zeroArray)));
- EXPECT_EQ((std::array<float, 2> {{ 0, 0 }}), (SourceFunction<std::array<float, 2>>("property", IdentityStops<std::array<float, 2>>(), zeroArray)
- .evaluate(oneTwoString, zeroArray)));
-}
-
-TEST(SourceFunction, Categorical) {
- EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }}))
- .evaluate(oneInteger, 0.0f));
- EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }}))
- .evaluate(oneDouble, 0.0f));
- EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }}))
- .evaluate(oneString, 0.0f));
-
- CategoricalStops<float>::Stops stops;
- stops["1"s] = 1.0f;
-
- EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>(stops))
- .evaluate(oneInteger, 0.0f));
- EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>(stops))
- .evaluate(oneDouble, 0.0f));
- EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>(stops))
- .evaluate(oneString, 0.0f));
-
- EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ true, 1.0f }}))
- .evaluate(trueFeature, 0.0f));
- EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ true, 1.0f }}))
- .evaluate(falseFeature, 0.0f));
- EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ false, 1.0f }}))
- .evaluate(trueFeature, 0.0f));
- EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ false, 1.0f }}))
- .evaluate(falseFeature, 0.0f));
}
diff --git a/test/style/properties.test.cpp b/test/style/properties.test.cpp
index 279fadb8c2..4d63f7e671 100644
--- a/test/style/properties.test.cpp
+++ b/test/style/properties.test.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/style/properties.hpp>
+#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/data_driven_property_evaluator.hpp>
@@ -120,12 +121,10 @@ TEST(TransitioningDataDrivenPropertyValue, Evaluate) {
TransitionOptions(),
TimePoint::min()
};
-
- SourceFunction<float> sourceFunction = {
- "property_name",
- IdentityStops<float>()
- };
-
+
+ using namespace mbgl::style::expression::dsl;
+ SourceFunction<float> sourceFunction(number(get("property_name")));
+
Transitioning<DataDrivenPropertyValue<float>> t1 {
DataDrivenPropertyValue<float>(sourceFunction),
t0,