summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-07 18:07:23 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-10 03:36:45 +0200
commit026b6d4c01a3d96af9629cc1790373137ecab950 (patch)
treec63cdb8429c793c3abfa8bc92c68c8fb848d7c54 /test
parent808bf7004a4360a4cc7095f97c235c92d3679f8b (diff)
downloadqtlocation-mapboxgl-026b6d4c01a3d96af9629cc1790373137ecab950.tar.gz
[core] Coordinate wrapping fixes
- Make returning LatLngs unwrapped by default. - PointAnnotation and ShapeAnnotation are always wrapped so they can be selected via intersection from the visible tile boundaries. - Fixes LatLng::wrap() calculation. - Fixes LatLng::unwrapForShortestPath() calculation. The new unwrapForShortestPath algorithm unwraps the start coordinate either forwards or backwards depending on the end coordinate value, so we can always cross the antimeridian when needed and still obtain a wrapped end coordinate in the end. Fixes #4214.
Diffstat (limited to 'test')
-rw-r--r--test/map/transform.cpp16
-rw-r--r--test/util/geo.cpp28
2 files changed, 38 insertions, 6 deletions
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index 98fc1223e5..4412b78b04 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -158,13 +158,17 @@ TEST(Transform, UnwrappedLatLng) {
ASSERT_NEAR(fromScreenCoordinate.latitude, 37.999999999999829, 0.0001); // 1.71E-13
ASSERT_NEAR(fromScreenCoordinate.longitude, -76.999999999999773, 0.0001); // 2.27E-13
- LatLng wrappedForwards = state.screenCoordinateToLatLng(state.latLngToScreenCoordinate({ 38, 283, LatLng::Wrapped }));
+ LatLng wrappedForwards = state.screenCoordinateToLatLng(state.latLngToScreenCoordinate({ 38, 283 }));
ASSERT_NEAR(wrappedForwards.latitude, 37.999999999999716, 0.0001); // 2.84E-13
- ASSERT_DOUBLE_EQ(wrappedForwards.longitude, fromScreenCoordinate.longitude);
-
- LatLng wrappedBackwards = state.screenCoordinateToLatLng(state.latLngToScreenCoordinate({ 38, -437, LatLng::Wrapped }));
- ASSERT_DOUBLE_EQ(wrappedBackwards.latitude, wrappedForwards.latitude);
- ASSERT_DOUBLE_EQ(wrappedBackwards.longitude, fromScreenCoordinate.longitude);
+ ASSERT_NEAR(wrappedForwards.longitude, 282.99999999988751, 0.0001); // 1.1249E-11
+ wrappedForwards.wrap();
+ ASSERT_NEAR(wrappedForwards.longitude, -77.000000000112493, 0.001); // 1.1249E-11
+
+ LatLng wrappedBackwards = state.screenCoordinateToLatLng(state.latLngToScreenCoordinate({ 38, -437 }));
+ ASSERT_NEAR(wrappedBackwards.latitude, wrappedForwards.latitude, 0.001);
+ ASSERT_NEAR(wrappedBackwards.longitude, -436.99999999988728, 0.001); // 1.1272E-11
+ wrappedBackwards.wrap();
+ ASSERT_NEAR(wrappedBackwards.longitude, -76.99999999988728, 0.001); // 1.1272E-11
}
TEST(Transform, ConstrainHeightOnly) {
diff --git a/test/util/geo.cpp b/test/util/geo.cpp
index 86f448ebbc..bdf335dc47 100644
--- a/test/util/geo.cpp
+++ b/test/util/geo.cpp
@@ -105,6 +105,34 @@ TEST(LatLng, FromTileID) {
}
}
+TEST(LatLng, Boundaries) {
+ LatLng coordinate;
+ ASSERT_DOUBLE_EQ(0, coordinate.latitude);
+ ASSERT_DOUBLE_EQ(0, coordinate.longitude);
+
+ coordinate.longitude = -180.1;
+ ASSERT_DOUBLE_EQ(-180.1, coordinate.longitude);
+
+ coordinate.wrap();
+ ASSERT_DOUBLE_EQ(179.90000000000001, coordinate.longitude); // 1E-14
+
+ coordinate.longitude = 180.9;
+ coordinate.wrap();
+ ASSERT_DOUBLE_EQ(-179.09999999999999, coordinate.longitude);
+
+ coordinate.longitude = -360.5;
+ coordinate.wrap();
+ ASSERT_DOUBLE_EQ(-0.5, coordinate.longitude);
+
+ coordinate.longitude = 360.5;
+ coordinate.wrap();
+ ASSERT_DOUBLE_EQ(0.5, coordinate.longitude);
+
+ coordinate.longitude = 360000.5;
+ coordinate.wrap();
+ ASSERT_DOUBLE_EQ(0.5, coordinate.longitude);
+}
+
TEST(LatLngBounds, FromTileID) {
{
const LatLngBounds bounds{ TileID(0, 0, 0, 0) };