diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2017-02-28 19:54:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 19:54:24 -0800 |
commit | f901e776b3e63aaaa6bc0cc4476624bf84127fe6 (patch) | |
tree | 3e311971d57109c64e5ace45c111fb5909e7fb7b /test/util | |
parent | c3ed1f51ca677c8c2045320fe13ec881cbd94772 (diff) | |
download | qtlocation-mapboxgl-f901e776b3e63aaaa6bc0cc4476624bf84127fe6.tar.gz |
[core] Implement data-driven styling for {text,icon}-{color,opacity,halo-color,halo-blur,halo-width} (#7939)
* Add symbol dds attributes and adapt style code generation
* Update to mapbox-gl-js/master
* Refactor SymbolFeature as a subclass of GeometryTileFeature
Prepares for enabling DDS on symbol paint properties by allowing the
SymbolFeatures, which we keep around after constructing SymbolLayout,
to be used in evaluating data-driven paint properties later in the
layout process.
* Draft approach for splitting icon/text paint properties
The `Program` types are set up to bind GL attributes to each of the
data-driven paint properties specified in the `PaintProperties` type
provided. Since `SymbolPaintProperties` specifies both `Text*` and
`Icon*` properties, the symbolIcon, symbolIconSDF, and symbolGlyph
programs each attempt to bind roughly double the number of attributes
that they actually need.
This change addresses this by:
- Adding the more specific `IconPaintProperties` and `TextPaintProperties` types, which are subsets of the full `SymbolPaintProperties`.
- The symbol layer continues to use its `SymbolPaintProperties paint` member to track layer property state, but it provides helpers that construct objects of each the specific `{Icon,Text}PaintProperties::Evaluated` type, for use by the painter.
- The three symbol programs instantiate `Program<>` using the appropriate `{Icon,Text}PaintProperties` type.
* check in generated style code
* Populate paint buffers for symbol DDS properties
* Address first round of review comments
* Refactor VectorTile{Layer,Feature} to explicitly share data
* Update submodule
Diffstat (limited to 'test/util')
-rw-r--r-- | test/util/merge_lines.test.cpp | 136 |
1 files changed, 86 insertions, 50 deletions
diff --git a/test/util/merge_lines.test.cpp b/test/util/merge_lines.test.cpp index 0a39419b70..8a3a400887 100644 --- a/test/util/merge_lines.test.cpp +++ b/test/util/merge_lines.test.cpp @@ -8,95 +8,131 @@ const std::u16string bbb = u"b"; using namespace mbgl; -TEST(MergeLines, SameText) { - // merges lines with the same text - std::vector<mbgl::SymbolFeature> input1 = { - { FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, bbb, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{8, 0}, {9, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{6, 0}, {7, 0}, {8, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{5, 0}, {6, 0}}}, aaa, {}, {{0, 0}}, 0, 0 } +class GeometryTileFeatureStub : public GeometryTileFeature { +public: + GeometryTileFeatureStub(optional<FeatureIdentifier> id_, FeatureType type_, GeometryCollection geometry_, + std::unordered_map<std::string, Value> properties_) : + id(id_), + type(type_), + geometry(geometry_), + properties(properties_) + {} + + FeatureType getType() const override { return type; } + optional<Value> getValue(const std::string& key) const override { + auto it = properties.find(key); + if (it != properties.end()) { + return it->second; + } + return {}; }; + std::unordered_map<std::string,Value> getProperties() const override { return properties; }; + optional<FeatureIdentifier> getID() const override { return id; }; + GeometryCollection getGeometries() const override { return geometry; }; + + optional<FeatureIdentifier> id; + FeatureType type; + GeometryCollection geometry; + std::unordered_map<std::string,Value> properties; +}; + +class SymbolFeatureStub : public SymbolFeature { +public: + SymbolFeatureStub(optional<FeatureIdentifier> id_, FeatureType type_, GeometryCollection geometry_, + std::unordered_map<std::string, Value> properties_, optional<std::u16string> text_, + optional<std::string> icon_, std::size_t index_) : + SymbolFeature(std::make_unique<GeometryTileFeatureStub>(id_, type_, geometry_, properties_)) + { + text = text_; + icon = icon_; + index = index_; + } +}; - const std::vector<mbgl::SymbolFeature> expected1 = { - { FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, bbb, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 } +TEST(MergeLines, SameText) { + // merges lines with the same text + std::vector<mbgl::SymbolFeature> input1; + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, {}, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, {}, bbb, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{8, 0}, {9, 0}}}, {}, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, {}, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{6, 0}, {7, 0}, {8, 0}}}, {}, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{5, 0}, {6, 0}}}, {}, aaa, {}, 0)); + + const std::vector<GeometryTileFeatureStub> expected1 = { + { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}}, {} }, + { {}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, {} }, + { {}, FeatureType::LineString, {{{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}}, {} }, + { {}, FeatureType::LineString, {{}}, {} }, + { {}, FeatureType::LineString, {{}}, {} }, + { {}, FeatureType::LineString, {{}}, {} } }; - + mbgl::util::mergeLines(input1); for (int i = 0; i < 6; i++) { - EXPECT_TRUE(input1[i].geometry == expected1[i].geometry); + EXPECT_TRUE(input1[i].geometry == expected1[i].getGeometries()); } } TEST(MergeLines, BothEnds) { // mergeLines handles merge from both ends - std::vector<mbgl::SymbolFeature> input2 = { - { FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, aaa, {}, {{0, 0}}, 0, 0 } - }; - - const std::vector<mbgl::SymbolFeature> expected2 = { - { FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 } + std::vector<mbgl::SymbolFeature> input2; + input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, {}, aaa, {}, 0 }); + input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, {}, aaa, {}, 0 }); + input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, {}, aaa, {}, 0 }); + + const std::vector<GeometryTileFeatureStub> expected2 = { + { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}}, {} }, + { {}, FeatureType::LineString, {{}}, {} }, + { {}, FeatureType::LineString, {{}}, {} } }; mbgl::util::mergeLines(input2); for (int i = 0; i < 3; i++) { - EXPECT_TRUE(input2[i].geometry == expected2[i].geometry); + EXPECT_TRUE(input2[i].geometry == expected2[i].getGeometries()); } } TEST(MergeLines, CircularLines) { // mergeLines handles circular lines - std::vector<mbgl::SymbolFeature> input3 = { - { FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{{4, 0}, {0, 0}}}, aaa, {}, {{0, 0}}, 0, 0 } - }; - - const std::vector<mbgl::SymbolFeature> expected3 = { - { FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {0, 0}}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 }, - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 } + std::vector<mbgl::SymbolFeature> input3; + input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, {}, aaa, {}, 0 }); + input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, {}, aaa, {}, 0 }); + input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{4, 0}, {0, 0}}}, {}, aaa, {}, 0 }); + + const std::vector<GeometryTileFeatureStub> expected3 = { + { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {0, 0}}}, {} }, + { {}, FeatureType::LineString, {{}}, {} }, + { {}, FeatureType::LineString, {{}}, {} } }; mbgl::util::mergeLines(input3); for (int i = 0; i < 3; i++) { - EXPECT_TRUE(input3[i].geometry == expected3[i].geometry); + EXPECT_TRUE(input3[i].geometry == expected3[i].getGeometries()); } } TEST(MergeLines, EmptyOuterGeometry) { - std::vector<mbgl::SymbolFeature> input = { - { FeatureType::LineString, {}, aaa, {}, {{0, 0}}, 0, 0 }, - }; + std::vector<mbgl::SymbolFeature> input; + input.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {}, {}, aaa, {}, 0 }); - const std::vector<mbgl::SymbolFeature> expected = input; + const std::vector<GeometryTileFeatureStub> expected = { { {}, FeatureType::LineString, {}, {} } }; mbgl::util::mergeLines(input); - EXPECT_EQ(expected[0].geometry, input[0].geometry); + EXPECT_EQ(input[0].geometry, expected[0].getGeometries()); } TEST(MergeLines, EmptyInnerGeometry) { - std::vector<mbgl::SymbolFeature> input = { - { FeatureType::LineString, {{}}, aaa, {}, {{0, 0}}, 0, 0 }, - }; + std::vector<mbgl::SymbolFeature> input; + input.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{}}, {}, aaa, {}, 0 }); - const std::vector<mbgl::SymbolFeature> expected = input; + const std::vector<GeometryTileFeatureStub> expected = { { {}, FeatureType::LineString, {{}}, {} } }; mbgl::util::mergeLines(input); - EXPECT_EQ(expected[0].geometry, input[0].geometry); + EXPECT_EQ(input[0].geometry, expected[0].getGeometries()); } |