From a2edfc79f03ee5fe4e7f1b4cd2b4eb63b2604622 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Wed, 22 Jan 2020 13:34:22 +0200 Subject: [PATCH] Add CrossTileSymbolLayerIndex.offscreenSymbols test --- test/text/cross_tile_symbol_index.test.cpp | 55 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/test/text/cross_tile_symbol_index.test.cpp b/test/text/cross_tile_symbol_index.test.cpp index 61597e021..6119392fd 100644 --- a/test/text/cross_tile_symbol_index.test.cpp +++ b/test/text/cross_tile_symbol_index.test.cpp @@ -1,6 +1,7 @@ -#include +#include #include #include +#include using namespace mbgl; @@ -342,3 +343,55 @@ TEST(CrossTileSymbolLayerIndex, bucketReplacement) { ASSERT_EQ(secondBucket.symbolInstances.at(2).crossTileID, 3u); // C' gets new ID } +namespace { + +void populatePosMatrix(mat4& posMatrix, const OverscaledTileID& tileId, double lat, double lon, double zoom) { + TransformState transformState; + transformState.setSize({512, 512}); + transformState.setLatLngZoom(LatLng(lat, lon), zoom); + transformState.matrixFor(posMatrix, tileId.toUnwrapped()); + matrix::multiply(posMatrix, transformState.getProjectionMatrix(), posMatrix); +} + +} // namespace + +TEST(CrossTileSymbolLayerIndex, offscreenSymbols) { + uint32_t maxCrossTileID = 0; + CrossTileSymbolLayerIndex index(maxCrossTileID); + + Immutable layout = + makeMutable(); + bool iconsNeedLinear = false; + bool sortFeaturesByY = false; + std::string bucketLeaderID = "test"; + + OverscaledTileID tileId(7, 0, 6, 18, 24); + std::vector mainInstances; + mainInstances.push_back(makeSymbolInstance(1000, 1000, u"Washington")); + mainInstances.push_back(makeSymbolInstance(2000, 2000, u"Richmond")); + SymbolBucket symbolBucket{layout, + {}, + 16.0f, + 1.0f, + 0, + iconsNeedLinear, + sortFeaturesByY, + bucketLeaderID, + std::move(mainInstances), + 1.0f, + false, + {}, + false /*iconsInText*/}; + mat4 posMatrix; + populatePosMatrix(posMatrix, tileId, 60.0, 25.0, 7.0); + index.addBucket(tileId, posMatrix, symbolBucket); + + EXPECT_EQ(symbolBucket.symbolInstances.at(0).crossTileID, SymbolInstance::invalidCrossTileID()); + EXPECT_EQ(symbolBucket.symbolInstances.at(1).crossTileID, SymbolInstance::invalidCrossTileID()); + + populatePosMatrix(posMatrix, tileId, 39.0, -76.0, 7.0); + index.addBucket(tileId, posMatrix, symbolBucket); + + EXPECT_EQ(symbolBucket.symbolInstances.at(0).crossTileID, 1u); + EXPECT_EQ(symbolBucket.symbolInstances.at(1).crossTileID, 2u); +} \ No newline at end of file