diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-10-16 15:53:27 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-10-17 13:58:49 +0200 |
commit | 09763366960e11c76353188f0ce7a65692b0b9ee (patch) | |
tree | 593a9d23c1c58b9dd5f636e8626c7d1bf2c13875 | |
parent | 62af756ab8250e00a63776c2d32bf3123909eddb (diff) | |
download | qtlocation-mapboxgl-09763366960e11c76353188f0ce7a65692b0b9ee.tar.gz |
[core] CameraOptions receives and outputs angle and pitch as degrees, not radians
-rw-r--r-- | include/mbgl/map/camera.hpp | 5 | ||||
-rw-r--r-- | platform/android/src/map/camera_position.cpp | 6 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 15 | ||||
-rw-r--r-- | platform/darwin/src/MGLMapSnapshotter.mm | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 4 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 4 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 14 | ||||
-rw-r--r-- | test/fixtures/offline_database/offline_sideload.db | bin | 4096 -> 73728 bytes | |||
-rw-r--r-- | test/map/map.test.cpp | 16 |
11 files changed, 36 insertions, 38 deletions
diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index 53b5b590b1..33722a0018 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -27,11 +27,10 @@ struct CameraOptions { levels. */ optional<double> zoom; - /** Bearing, measured in radians counterclockwise from true north. Wrapped - to [−π rad, π rad). */ + /** Bearing, measured in degrees from true north. Wrapped to [0, 360). */ optional<double> angle; - /** Pitch toward the horizon measured in radians, with 0 rad resulting in a + /** Pitch toward the horizon measured in degrees , with 0 deg resulting in a two-dimensional map. */ optional<double> pitch; }; diff --git a/platform/android/src/map/camera_position.cpp b/platform/android/src/map/camera_position.cpp index 3caf4ea2f3..6c7b78c101 100644 --- a/platform/android/src/map/camera_position.cpp +++ b/platform/android/src/map/camera_position.cpp @@ -14,7 +14,7 @@ jni::Local<jni::Object<CameraPosition>> CameraPosition::New(jni::JNIEnv &env, mb // convert bearing, measured in radians counterclockwise from true north. // Wrapped to [−π rad, π rad). Android binding from 0 to 360 degrees - double bearing_degrees = -options.angle.value_or(0) * util::RAD2DEG; + double bearing_degrees = options.angle.value_or(0); while (bearing_degrees > 360) { bearing_degrees -= 360; } @@ -23,7 +23,7 @@ jni::Local<jni::Object<CameraPosition>> CameraPosition::New(jni::JNIEnv &env, mb } // convert tilt, core ranges from [0 rad, 1,0472 rad], android ranges from 0 to 60 - double tilt_degrees = options.pitch.value_or(0) * util::RAD2DEG; + double tilt_degrees = options.pitch.value_or(0); return javaClass.New(env, constructor, LatLng::New(env, center), options.zoom.value_or(0), tilt_degrees, bearing_degrees); } @@ -42,7 +42,7 @@ mbgl::CameraOptions CameraPosition::getCameraOptions(jni::JNIEnv& env, const jni {}, {}, position.Get(env, zoom), - position.Get(env, bearing) * util::DEG2RAD, + position.Get(env, bearing), position.Get(env, tilt) }; } diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 7b22e1e81b..f12c48f938 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -257,12 +257,12 @@ void NativeMapView::moveBy(jni::JNIEnv&, jni::jdouble dx, jni::jdouble dy, jni:: void NativeMapView::jumpTo(jni::JNIEnv&, jni::jdouble angle, jni::jdouble latitude, jni::jdouble longitude, jni::jdouble pitch, jni::jdouble zoom) { mbgl::CameraOptions options; if (angle != -1) { - options.angle = -angle * util::DEG2RAD; + options.angle = angle; } options.center = mbgl::LatLng(latitude, longitude); options.padding = insets; if (pitch != -1) { - options.pitch = pitch * util::DEG2RAD; + options.pitch = pitch; } if (zoom != -1) { options.zoom = zoom; @@ -274,12 +274,12 @@ void NativeMapView::jumpTo(jni::JNIEnv&, jni::jdouble angle, jni::jdouble latitu void NativeMapView::easeTo(jni::JNIEnv&, jni::jdouble angle, jni::jdouble latitude, jni::jdouble longitude, jni::jlong duration, jni::jdouble pitch, jni::jdouble zoom, jni::jboolean easing) { mbgl::CameraOptions cameraOptions; if (angle != -1) { - cameraOptions.angle = -angle * util::DEG2RAD; + cameraOptions.angle = angle; } cameraOptions.center = mbgl::LatLng(latitude, longitude); cameraOptions.padding = insets; if (pitch != -1) { - cameraOptions.pitch = pitch * util::DEG2RAD; + cameraOptions.pitch = pitch; } if (zoom != -1) { cameraOptions.zoom = zoom; @@ -298,12 +298,12 @@ void NativeMapView::easeTo(jni::JNIEnv&, jni::jdouble angle, jni::jdouble latitu void NativeMapView::flyTo(jni::JNIEnv&, jni::jdouble angle, jni::jdouble latitude, jni::jdouble longitude, jni::jlong duration, jni::jdouble pitch, jni::jdouble zoom) { mbgl::CameraOptions cameraOptions; if (angle != -1) { - cameraOptions.angle = -angle * util::DEG2RAD; + cameraOptions.angle = angle; } cameraOptions.center = mbgl::LatLng(latitude, longitude); cameraOptions.padding = insets; if (pitch != -1) { - cameraOptions.pitch = pitch * util::DEG2RAD; + cameraOptions.pitch = pitch; } if (zoom != -1) { cameraOptions.zoom = zoom; @@ -416,8 +416,7 @@ void NativeMapView::setVisibleCoordinateBounds(JNIEnv& env, const jni::Array<jni mbgl::EdgeInsets mbglInsets = { RectF::getTop(env, padding), RectF::getLeft(env, padding), RectF::getBottom(env, padding), RectF::getRight(env, padding) }; mbgl::CameraOptions cameraOptions = map->cameraForLatLngs(latLngs, mbglInsets); if (direction >= 0) { - // convert from degrees to radians - cameraOptions.angle = (-direction * M_PI) / 180; + cameraOptions.angle = direction; } mbgl::AnimationOptions animationOptions; diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index aa1a988b1b..590c387145 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -550,7 +550,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; if (CLLocationCoordinate2DIsValid(options.camera.centerCoordinate)) { cameraOptions.center = MGLLatLngFromLocationCoordinate2D(options.camera.centerCoordinate); } - cameraOptions.angle = MAX(0, options.camera.heading) * mbgl::util::DEG2RAD; + cameraOptions.angle = MAX(0, options.camera.heading); cameraOptions.zoom = MAX(0, options.zoomLevel); cameraOptions.pitch = MAX(0, options.camera.pitch); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7096c55a8c..0e95636294 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1970,7 +1970,7 @@ public: MGLMapCamera *camera; mbgl::ScreenCoordinate anchor = mbgl::ScreenCoordinate { anchorPoint.x, anchorPoint.y }; - currentCameraOptions.angle = degrees * mbgl::util::DEG2RAD; + currentCameraOptions.angle = degrees; currentCameraOptions.anchor = anchor; camera = [self cameraForCameraOptions:currentCameraOptions]; @@ -1984,7 +1984,7 @@ public: MGLMapCamera *camera; - currentCameraOptions.pitch = pitch * mbgl::util::DEG2RAD; + currentCameraOptions.pitch = pitch; camera = [self cameraForCameraOptions:currentCameraOptions]; return camera; diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index e32c576e14..5693edbd03 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -443,8 +443,8 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { mbgl::CameraOptions camera; camera.center = mbgl::LatLng { options.latitude, options.longitude }; camera.zoom = options.zoom; - camera.angle = -options.bearing * mbgl::util::DEG2RAD; - camera.pitch = options.pitch * mbgl::util::DEG2RAD; + camera.angle = options.bearing; + camera.pitch = options.pitch; if (map->getAxonometric() != options.axonometric) { map->setAxonometric(options.axonometric); diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index e1fe7f5a37..ceed411ca3 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -808,10 +808,10 @@ void QMapboxGL::jumpTo(const QMapboxGLCameraOptions& camera) mbglCamera.zoom = camera.zoom.value<double>(); } if (camera.angle.isValid()) { - mbglCamera.angle = -camera.angle.value<double>() * mbgl::util::DEG2RAD; + mbglCamera.angle = camera.angle.value<double>(); } if (camera.pitch.isValid()) { - mbglCamera.pitch = camera.pitch.value<double>() * mbgl::util::DEG2RAD; + mbglCamera.pitch = camera.pitch.value<double>(); } mbglCamera.padding = d_ptr->margins; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 9d886cb74c..1f64cf3acc 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -450,8 +450,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed } CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); - options.angle = transform.getAngle(); - options.pitch = transform.getPitch(); + options.angle = -transform.getAngle() * util::RAD2DEG; + options.pitch = transform.getPitch() * util::RAD2DEG; return options; } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index da8e243d91..21f1b70c42 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -91,8 +91,8 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim const LatLng unwrappedLatLng = camera.center.value_or(getLatLng()); const LatLng latLng = unwrappedLatLng.wrapped(); double zoom = camera.zoom.value_or(getZoom()); - double angle = camera.angle.value_or(getAngle()); - double pitch = camera.pitch.value_or(getPitch()); + double angle = camera.angle ? -*camera.angle * util::DEG2RAD : getAngle(); + double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch(); if (std::isnan(zoom)) { return; @@ -164,8 +164,8 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &animation) { const LatLng latLng = camera.center.value_or(getLatLng()).wrapped(); double zoom = camera.zoom.value_or(getZoom()); - double angle = camera.angle.value_or(getAngle()); - double pitch = camera.pitch.value_or(getPitch()); + double angle = camera.angle ? -*camera.angle * util::DEG2RAD : getAngle(); + double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch(); if (std::isnan(zoom) || state.size.isEmpty()) { return; @@ -451,7 +451,7 @@ void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& } CameraOptions camera; - camera.angle = state.angle + util::angle_between(first - center, second - center); + camera.angle = -(state.angle + util::angle_between(first - center, second - center)) * util::RAD2DEG; easeTo(camera, animation); } @@ -462,7 +462,7 @@ void Transform::setAngle(double angle, const AnimationOptions& animation) { void Transform::setAngle(double angle, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { if (std::isnan(angle)) return; CameraOptions camera; - camera.angle = angle; + camera.angle = -angle * util::RAD2DEG; camera.anchor = anchor; easeTo(camera, animation); } @@ -486,7 +486,7 @@ void Transform::setPitch(double pitch, const AnimationOptions& animation) { void Transform::setPitch(double pitch, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { if (std::isnan(pitch)) return; CameraOptions camera; - camera.pitch = pitch; + camera.pitch = pitch * util::RAD2DEG; camera.anchor = anchor; easeTo(camera, animation); } diff --git a/test/fixtures/offline_database/offline_sideload.db b/test/fixtures/offline_database/offline_sideload.db Binary files differindex 8909c402b2..6146e30872 100644 --- a/test/fixtures/offline_database/offline_sideload.db +++ b/test/fixtures/offline_database/offline_sideload.db diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index cb45c2900b..88ddfa6cee 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -81,10 +81,10 @@ TEST(Map, LatLngBoundsToCameraWithAngle) { LatLngBounds bounds = LatLngBounds::hull({15.68169,73.499857}, {53.560711, 134.77281}); - CameraOptions virtualCamera = test.map.cameraForLatLngBounds(bounds, {}, 35); + CameraOptions virtualCamera = test.map.cameraForLatLngBounds(bounds, {}, 35.0); ASSERT_TRUE(bounds.contains(*virtualCamera.center)); EXPECT_NEAR(*virtualCamera.zoom, 1.21385, 1e-5); - EXPECT_NEAR(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD, 1e-5); + EXPECT_NEAR(virtualCamera.angle.value_or(0), 35.0, 1e-5); } TEST(Map, LatLngBoundsToCameraWithAngleAndPitch) { @@ -97,8 +97,8 @@ TEST(Map, LatLngBoundsToCameraWithAngleAndPitch) { CameraOptions virtualCamera = test.map.cameraForLatLngBounds(bounds, {}, 35, 20); ASSERT_TRUE(bounds.contains(*virtualCamera.center)); EXPECT_NEAR(*virtualCamera.zoom, 13.66272, 1e-5); - ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20 * util::DEG2RAD); - EXPECT_NEAR(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD, 1e-5); + ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20.0); + EXPECT_NEAR(virtualCamera.angle.value_or(0), 35.0, 1e-5); } TEST(Map, LatLngsToCamera) { @@ -106,8 +106,8 @@ TEST(Map, LatLngsToCamera) { std::vector<LatLng> latLngs{{ 40.712730, 74.005953 }, {15.68169,73.499857}, {30.82678, 83.4082}}; - CameraOptions virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23); - EXPECT_NEAR(virtualCamera.angle.value_or(0), -23 * util::DEG2RAD, 1e-5); + CameraOptions virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23.0); + EXPECT_NEAR(virtualCamera.angle.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); @@ -119,11 +119,11 @@ TEST(Map, LatLngsToCameraWithAngleAndPitch) { std::vector<LatLng> latLngs{{ 40.712730, 74.005953 }, {15.68169,73.499857}, {30.82678, 83.4082}}; CameraOptions virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23, 20); - EXPECT_NEAR(virtualCamera.angle.value_or(0), -23 * util::DEG2RAD, 1e-5); + EXPECT_NEAR(virtualCamera.angle.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 * util::DEG2RAD); + ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20.0); } |