diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-30 11:06:59 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-17 15:13:38 -0800 |
commit | 38fcbe21d48186c4630a3b8a76d1b20e156faadd (patch) | |
tree | 098f73bfea98deb5202fe1c13b1277e43e322755 /test | |
parent | d4fc66af3924805d40576989c1e139ddafcc4670 (diff) | |
download | qtlocation-mapboxgl-38fcbe21d48186c4630a3b8a76d1b20e156faadd.tar.gz |
[core] Convert style properties to a tuple-based approach
This converts the style property classes (CirclePaintProperties and so on) to the same tuple-based approach as gl::Attribute and gl::Uniform. The approach is outlined in https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md.
The main advantage of this approach is it allows writing algorithms that work on sets of style properties, without resorting to code generation or manually repetitive code. This lets us iterate on approaches to data-driven properties more easily.
Another advantage is that the cascading, unevaluated, and evaluated states of a set of properties exist as independent structures, instead of individual properties holding their own state. This is a more functional approach that makes data flow clearer and reduces state.
Diffstat (limited to 'test')
-rw-r--r-- | test/gl/bucket.test.cpp | 2 | ||||
-rw-r--r-- | test/style/functions.test.cpp | 6 | ||||
-rw-r--r-- | test/text/quads.test.cpp | 96 |
3 files changed, 52 insertions, 52 deletions
diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp index 419aee183f..03cdc63a91 100644 --- a/test/gl/bucket.test.cpp +++ b/test/gl/bucket.test.cpp @@ -30,7 +30,7 @@ TEST(Buckets, LineBucket) { TEST(Buckets, SymbolBucket) { mbgl::MapMode mapMode = mbgl::MapMode::Still; - mbgl::style::SymbolLayoutProperties properties; + mbgl::style::SymbolLayoutProperties::Evaluated properties; bool sdfIcons = false; bool iconsNeedLinear = false; diff --git a/test/style/functions.test.cpp b/test/style/functions.test.cpp index 9577bcc633..8ca2f951e7 100644 --- a/test/style/functions.test.cpp +++ b/test/style/functions.test.cpp @@ -2,16 +2,16 @@ #include <mbgl/test/util.hpp> #include <mbgl/style/property_evaluator.hpp> -#include <mbgl/style/calculation_parameters.hpp> +#include <mbgl/style/property_evaluation_parameters.hpp> using namespace mbgl; using namespace mbgl::style; float evaluate(PropertyValue<float> value, float zoom) { - return PropertyValue<float>::visit(value, PropertyEvaluator<float>(CalculationParameters(zoom), 0)); + return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0)); } std::string evaluate(PropertyValue<std::string> value, float zoom) { - return PropertyValue<std::string>::visit(value, PropertyEvaluator<std::string>(CalculationParameters(zoom), "")); + return value.evaluate(PropertyEvaluator<std::string>(PropertyEvaluationParameters(zoom), "")); } TEST(Function, Constant) { diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp index 421d2f362d..c20218a82f 100644 --- a/test/text/quads.test.cpp +++ b/test/text/quads.test.cpp @@ -10,7 +10,7 @@ using namespace mbgl; using namespace mbgl::style; TEST(getIconQuads, normal) { - SymbolLayoutProperties layout; + SymbolLayoutProperties::Evaluated layout; Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0); SpriteAtlasElement image = { Rect<uint16_t>( 0, 0, 15, 11 ), @@ -58,7 +58,7 @@ TEST(getIconQuads, style) { // none { - SymbolLayoutProperties layout; + SymbolLayoutProperties::Evaluated layout; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -80,9 +80,9 @@ TEST(getIconQuads, style) { // width { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(24.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width); + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 24.0f; + layout.get<IconTextFit>() = IconTextFitType::Width; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -98,9 +98,9 @@ TEST(getIconQuads, style) { // width x textSize { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width); + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Width; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -116,13 +116,13 @@ TEST(getIconQuads, style) { // width x textSize + padding { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width); - layout.iconTextFitPadding.value[0] = 5.0f; - layout.iconTextFitPadding.value[1] = 10.0f; - layout.iconTextFitPadding.value[2] = 5.0f; - layout.iconTextFitPadding.value[3] = 10.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Width; + layout.get<IconTextFitPadding>()[0] = 5.0f; + layout.get<IconTextFitPadding>()[1] = 10.0f; + layout.get<IconTextFitPadding>()[2] = 5.0f; + layout.get<IconTextFitPadding>()[3] = 10.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -138,9 +138,9 @@ TEST(getIconQuads, style) { // height { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(24.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height); + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 24.0f; + layout.get<IconTextFit>() = IconTextFitType::Height; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -156,9 +156,9 @@ TEST(getIconQuads, style) { // height x textSize { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height); + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Height; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -174,13 +174,13 @@ TEST(getIconQuads, style) { // height x textSize + padding { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height); - layout.iconTextFitPadding.value[0] = 5.0f; - layout.iconTextFitPadding.value[1] = 10.0f; - layout.iconTextFitPadding.value[2] = 5.0f; - layout.iconTextFitPadding.value[3] = 10.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Height; + layout.get<IconTextFitPadding>()[0] = 5.0f; + layout.get<IconTextFitPadding>()[1] = 10.0f; + layout.get<IconTextFitPadding>()[2] = 5.0f; + layout.get<IconTextFitPadding>()[3] = 10.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -196,9 +196,9 @@ TEST(getIconQuads, style) { // both { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(24.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both); + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 24.0f; + layout.get<IconTextFit>() = IconTextFitType::Both; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -214,9 +214,9 @@ TEST(getIconQuads, style) { // both x textSize { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both); + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Both; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -232,13 +232,13 @@ TEST(getIconQuads, style) { // both x textSize + padding { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both); - layout.iconTextFitPadding.value[0] = 5.0f; - layout.iconTextFitPadding.value[1] = 10.0f; - layout.iconTextFitPadding.value[2] = 5.0f; - layout.iconTextFitPadding.value[3] = 10.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Both; + layout.get<IconTextFitPadding>()[0] = 5.0f; + layout.get<IconTextFitPadding>()[1] = 10.0f; + layout.get<IconTextFitPadding>()[2] = 5.0f; + layout.get<IconTextFitPadding>()[3] = 10.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -254,13 +254,13 @@ TEST(getIconQuads, style) { // both x textSize + padding t/r/b/l { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty<float>(12.0f); - layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both); - layout.iconTextFitPadding.value[0] = 0.0f; - layout.iconTextFitPadding.value[1] = 5.0f; - layout.iconTextFitPadding.value[2] = 10.0f; - layout.iconTextFitPadding.value[3] = 15.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get<TextSize>() = 12.0f; + layout.get<IconTextFit>() = IconTextFitType::Both; + layout.get<IconTextFitPadding>()[0] = 0.0f; + layout.get<IconTextFitPadding>()[1] = 5.0f; + layout.get<IconTextFitPadding>()[2] = 10.0f; + layout.get<IconTextFitPadding>()[3] = 15.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); |