summaryrefslogtreecommitdiff
path: root/test/api
diff options
context:
space:
mode:
authorAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-05-13 23:02:05 +0300
committerAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-05-28 14:38:01 +0300
commit9809c9f8f5583739e07d1a02df4c6cb96dfc4a10 (patch)
treef61c9979ad7943c1975aad6725054b2458c22b36 /test/api
parentddb6f749ec8992c363c067b6ad5871b31ccb7b8a (diff)
downloadqtlocation-mapboxgl-9809c9f8f5583739e07d1a02df4c6cb96dfc4a10.tar.gz
[core] Offset viewport center when edge insets are specified
The change is implemented in TransformState::getProjMatrix, the rest of the code is making sure that existing API contracts stay and there are tests verifyingrendering and render query processing only items within screen and given tolerance around screen edges. MapView: don't bake edge insets into relalculated camera center. Keep edge insets as property of camera in TransformState (similar to pitch, zoom, bearing) independent from specified camera center. Interpolate edge insets in animation. iOS Demo app: "Turn On/Off Content Insets" pitch the camera and navigate to convenient location in Denver, where streets are parallel to cardinal directions, to illustrate viewport center offset when edge insets are set. Tests: ViewFrustumCulling: although Annotations are deprecated, queryRenderedFeatures related tests in Annotations would need to get ported and decided to add the edge insets related query tests next to them. Verify frustum culling (render+queryRenderedFeatures) With different camera and edge insets setups. TODO: port Annotations tests. Transform.Padding: Verify that coordinates take proper place on screen after applying edge insets. LocalGlyphRasterizer: verify text rendering when applying padding. Related to #11882: both use projection matrix elements [8] and [9]. Alternative approach to this was to increase and offset map origin so that the screen would be a sub-rectangle in larger map viewport. This approach has a drawback of unecessary processing the items that are outside screen area. Fixes #12107, #12728, navigation-sdks/issues/120
Diffstat (limited to 'test/api')
-rw-r--r--test/api/annotations.test.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index d7cb572cb0..03330dc4c6 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -434,6 +434,73 @@ TEST(Annotations, VisibleFeatures) {
EXPECT_EQ(features.size(), ids.size());
}
+TEST(Annotations, ViewFrustumCulling) {
+ // The purpose of the test is to control that annotations outside screen
+ // rectangle are not rendered for different camera setup, especially when
+ // using edge insets - viewport center is then offsetted.
+
+ // Important premise of this test is "static const float viewportPadding = 100;"
+ // as defined in collision_index.cpp: tests using edge insets are writen so that
+ // padding is 128 (half of viewSize width). If increasing viewportPadding,
+ // increase the padding in test cases below.
+ AnnotationTest test;
+
+ auto viewSize = test.frontend.getSize();
+ auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
+
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
+ const LatLng center = { 5.0, 5.0 };
+ test.map.jumpTo(CameraOptions().withCenter(center).withZoom(3.0));
+
+ LatLng tl = test.map.latLngForPixel(ScreenCoordinate(0, 0));
+ LatLng br = test.map.latLngForPixel(ScreenCoordinate(viewSize.width, viewSize.height));
+
+ std::vector<LatLng> latLngs = {
+ tl,
+ test.map.latLngForPixel(ScreenCoordinate(viewSize.width, 0)),
+ test.map.latLngForPixel(ScreenCoordinate(0, viewSize.height)),
+ br,
+ center};
+
+ std::vector<mbgl::AnnotationID> ids;
+ for (auto latLng : latLngs) {
+ ids.push_back(test.map.addAnnotation(SymbolAnnotation { { latLng.longitude(), latLng.latitude() }, "default_marker" }));
+ }
+
+ std::vector<std::pair<CameraOptions, std::vector<uint64_t>>> expectedVisibleForCamera = {
+ // Start with all markers visible.
+ { CameraOptions(), { 0, 1, 2, 3, 4 } },
+ // Move center to topLeft: only former center and top left (now center) are visible.
+ { CameraOptions().withCenter(tl), { 0, 4 } },
+ // Reset center. With pitch: only top row markers and center are visible.
+ { CameraOptions().withCenter(center).withPitch(45), { 0, 1, 4 } },
+ // Reset pitch, and use padding to move viewport center: only topleft and center are visible.
+ { CameraOptions().withPitch(0).withPadding(EdgeInsets { viewSize.height * 0.5, viewSize.width * 0.5, 0, 0 }), { 0, 4 } },
+ // Use opposite padding to move viewport center: only bottom right and center are visible.
+ { CameraOptions().withPitch(0).withPadding(EdgeInsets { 0, 0, viewSize.height * 0.5, viewSize.width * 0.5 }), { 3, 4 } },
+ // Use top padding to move viewport center: top row and center are visible.
+ { CameraOptions().withPitch(0).withPadding(EdgeInsets { viewSize.height * 0.5, 0, 0, 0 }), { 0, 1, 4 } },
+ // Use bottom padding: only bottom right and center are visible.
+ { CameraOptions().withPitch(0).withPadding(EdgeInsets { 0, 0, viewSize.height * 0.5, 0 }), { 2, 3, 4 } },
+ // Left padding and pitch: top left, bottom left and center are visible.
+ { CameraOptions().withPitch(45).withPadding(EdgeInsets { 0, viewSize.width * 0.5, 0, 0 }), { 0, 2, 4 } }
+ };
+
+ for (unsigned i = 0; i < expectedVisibleForCamera.size(); i++) {
+ auto testCase = expectedVisibleForCamera[i];
+ test.map.jumpTo(testCase.first);
+ test.frontend.render(test.map);
+ auto features = test.frontend.getRenderer()->queryRenderedFeatures(box, {});
+ for (uint64_t id : testCase.second) { // testCase.second is vector of ids expected.
+ EXPECT_NE(std::find_if(features.begin(), features.end(), [&id](auto feature) {
+ return id == feature.id.template get<uint64_t>();
+ }), features.end()) << "Point with id " << id << " is missing in test case " << i;
+ EXPECT_EQ(features.size(), testCase.second.size()) << " in test case " << i;
+ }
+ }
+}
+
TEST(Annotations, TopOffsetPixels) {
AnnotationTest test;