diff options
author | Aleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com> | 2019-05-13 23:02:05 +0300 |
---|---|---|
committer | Aleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com> | 2019-05-28 14:38:01 +0300 |
commit | 9809c9f8f5583739e07d1a02df4c6cb96dfc4a10 (patch) | |
tree | f61c9979ad7943c1975aad6725054b2458c22b36 /test/map | |
parent | ddb6f749ec8992c363c067b6ad5871b31ccb7b8a (diff) | |
download | qtlocation-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/map')
-rw-r--r-- | test/map/transform.test.cpp | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 33d325dfb2..3d37312b17 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -288,25 +288,48 @@ TEST(Transform, Padding) { ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude()); ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude()); - - transform.jumpTo(CameraOptions().withCenter(LatLng { 10, -100 }).withZoom(10.0)); + CameraOptions nonPaddedCameraOptions = CameraOptions().withCenter(LatLng { 10, -100 }).withZoom(10.0); + transform.jumpTo(nonPaddedCameraOptions); const LatLng trueCenter = transform.getLatLng(); ASSERT_DOUBLE_EQ(10, trueCenter.latitude()); ASSERT_DOUBLE_EQ(-100, trueCenter.longitude()); ASSERT_DOUBLE_EQ(10, transform.getZoom()); - const LatLng manualShiftedCenter = transform.getState().screenCoordinateToLatLng({ + const LatLng screenCenter = transform.screenCoordinateToLatLng({ + 1000.0 / 2.0, 1000.0 / 2.0, - 1000.0 / 4.0, + }); + const LatLng upperHalfCenter = transform.screenCoordinateToLatLng({ + 1000.0 / 2.0, + 1000.0 * 0.25, }); EdgeInsets padding(1000.0 / 2.0, 0, 0, 0); - const LatLng shiftedCenter = transform.getLatLng(padding); - ASSERT_NE(trueCenter.latitude(), shiftedCenter.latitude()); - ASSERT_NEAR(trueCenter.longitude(), shiftedCenter.longitude(), 1e-8); - ASSERT_DOUBLE_EQ(manualShiftedCenter.latitude(), shiftedCenter.latitude()); - ASSERT_DOUBLE_EQ(manualShiftedCenter.longitude(), shiftedCenter.longitude()); + // CameraOption center and zoom don't change when padding changes: center of + // viewport remains the same as padding defines viwport center offset in rendering. + CameraOptions paddedOptions = CameraOptions().withPadding(padding); + transform.jumpTo(paddedOptions); + const LatLng theSameCenter = transform.getLatLng(); + ASSERT_DOUBLE_EQ(trueCenter.latitude(), theSameCenter.latitude()); + ASSERT_DOUBLE_EQ(trueCenter.longitude(), theSameCenter.longitude()); + + // However, LatLng is now at the center of lower half - verify conversion + // from screen coordinate to LatLng. + const LatLng paddedLowerHalfScreenCenter = transform.screenCoordinateToLatLng({ + 1000.0 / 2.0, + 1000.0 * 0.75, + }); + ASSERT_NEAR(screenCenter.latitude(), paddedLowerHalfScreenCenter.latitude(), 1e-10); + ASSERT_NEAR(screenCenter.longitude(), paddedLowerHalfScreenCenter.longitude(), 1e-10); + + // LatLng previously in upper half center, should now be under screen center. + const LatLng paddedScreenCenter = transform.screenCoordinateToLatLng({ + 1000.0 / 2.0, + 1000.0 / 2.0, + }); + ASSERT_NEAR(upperHalfCenter.latitude(), paddedScreenCenter.latitude(), 1e-10); + ASSERT_NEAR(upperHalfCenter.longitude(), paddedScreenCenter.longitude(), 1e-10); } TEST(Transform, MoveBy) { @@ -440,7 +463,7 @@ TEST(Transform, Camera) { flyOptions.transitionFrameFn = [&](double t) { ASSERT_TRUE(t >= 0 && t <= 1); ASSERT_LE(latLng2.latitude(), transform.getLatLng().latitude()); - ASSERT_GE(latLng2.longitude(), transform.getLatLng({}, LatLng::Unwrapped).longitude()); + ASSERT_GE(latLng2.longitude(), transform.getLatLng(LatLng::Unwrapped).longitude()); }; flyOptions.transitionFinishFn = [&]() { // XXX Fix precision loss in flyTo: @@ -618,7 +641,7 @@ TEST(Transform, LatLngBounds) { // Try crossing the antimeridian from the right. transform.jumpTo(CameraOptions().withCenter(LatLng { 0.0, 200.0 })); - ASSERT_DOUBLE_EQ(transform.getLatLng({}, LatLng::Unwrapped).longitude(), 180.0); + ASSERT_DOUBLE_EQ(transform.getLatLng(LatLng::Unwrapped).longitude(), 180.0); ASSERT_DOUBLE_EQ(transform.getLatLng().longitude(), -180.0); // -1 | 0 | +1 |