summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/map/map.test.cpp21
-rw-r--r--test/map/transform.test.cpp72
2 files changed, 93 insertions, 0 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 0ec97fd3bc..c161065e1a 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -241,6 +241,27 @@ TEST(Map, LatLngsToCameraWithBearingAndPitch) {
ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20.0);
}
+TEST(Map, LatLngsToCameraWithBearingAndPitchMinMax) {
+ MapTest<> test;
+
+ std::vector<LatLng> latLngs{{40.712730, 74.005953}, {15.68169, 73.499857}, {30.82678, 83.4082}};
+
+ test.map.setBounds(BoundOptions().withMinPitch(0).withMaxPitch(0));
+ CameraOptions virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23, 45);
+ EXPECT_NEAR(virtualCamera.bearing.value_or(0), 23.0, 1e-5);
+ EXPECT_NEAR(virtualCamera.zoom.value_or(0), 2.75434, 1e-5);
+ EXPECT_NEAR(virtualCamera.center->latitude(), 28.49288, 1e-5);
+ EXPECT_NEAR(virtualCamera.center->longitude(), 74.97437, 1e-5);
+ ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 0);
+
+ test.map.setBounds(BoundOptions().withMinPitch(20).withMaxPitch(60));
+ virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23, 0);
+ EXPECT_NEAR(virtualCamera.bearing.value_or(0), 23.0, 1e-5);
+ EXPECT_NEAR(virtualCamera.zoom.value_or(0), 3.04378, 1e-5);
+ EXPECT_NEAR(virtualCamera.center->latitude(), 28.53718, 1e-5);
+ EXPECT_NEAR(virtualCamera.center->longitude(), 74.31746, 1e-5);
+ ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20.0);
+}
TEST(Map, CameraToLatLngBounds) {
MapTest<> test;
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp
index 02ecbfbee4..506e61aca7 100644
--- a/test/map/transform.test.cpp
+++ b/test/map/transform.test.cpp
@@ -788,3 +788,75 @@ TEST(Transform, LatLngBounds) {
transform.moveBy(ScreenCoordinate { 500, 0 });
ASSERT_DOUBLE_EQ(transform.getLatLng().longitude(), 120.0);
}
+
+TEST(Transform, InvalidPitch) {
+ Transform transform;
+ transform.resize({1, 1});
+
+ ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
+ ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
+ ASSERT_DOUBLE_EQ(0, transform.getZoom());
+ ASSERT_DOUBLE_EQ(0, transform.getPitch());
+
+ transform.jumpTo(CameraOptions().withZoom(1.0).withPitch(45));
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getPitch());
+
+ const double invalid = NAN;
+
+ transform.jumpTo(CameraOptions().withPitch(invalid));
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getPitch());
+
+ transform.jumpTo(CameraOptions().withPitch(60));
+ ASSERT_DOUBLE_EQ(60 * util::DEG2RAD, transform.getPitch());
+}
+
+TEST(Transform, MinMaxPitch) {
+ Transform transform;
+ transform.resize({1, 1});
+
+ ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
+ ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
+ ASSERT_DOUBLE_EQ(0, transform.getZoom());
+ ASSERT_DOUBLE_EQ(0, transform.getPitch());
+
+ transform.jumpTo(CameraOptions().withZoom(1.0).withPitch(60));
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
+ ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch(), transform.getPitch());
+ ASSERT_DOUBLE_EQ(60 * util::DEG2RAD, transform.getPitch());
+
+ transform.setMaxPitch(70);
+ transform.jumpTo(CameraOptions().withPitch(70));
+ ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch(), transform.getPitch());
+ ASSERT_DOUBLE_EQ(60 * util::DEG2RAD, transform.getPitch());
+
+ transform.setMaxPitch(45);
+ transform.jumpTo(CameraOptions().withPitch(60));
+ ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch(), transform.getPitch());
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getPitch());
+
+ transform.jumpTo(CameraOptions().withPitch(0));
+ ASSERT_DOUBLE_EQ(transform.getState().getMinPitch(), transform.getPitch());
+ ASSERT_DOUBLE_EQ(0, transform.getPitch());
+
+ transform.setMinPitch(-10);
+ transform.jumpTo(CameraOptions().withPitch(-10));
+ ASSERT_DOUBLE_EQ(transform.getState().getMinPitch(), transform.getPitch());
+ ASSERT_DOUBLE_EQ(0, transform.getPitch());
+
+ transform.setMinPitch(15);
+ transform.jumpTo(CameraOptions().withPitch(0));
+ ASSERT_DOUBLE_EQ(transform.getState().getMinPitch(), transform.getPitch());
+ ASSERT_DOUBLE_EQ(15 * util::DEG2RAD, transform.getPitch());
+
+ transform.setMinPitch(45);
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getState().getMinPitch());
+ transform.setMaxPitch(45);
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getState().getMaxPitch());
+
+ transform.setMaxPitch(10);
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getState().getMaxPitch());
+
+ transform.setMinPitch(60);
+ ASSERT_DOUBLE_EQ(45 * util::DEG2RAD, transform.getState().getMinPitch());
+}