summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmark/util/tilecover.benchmark.cpp7
-rw-r--r--include/mbgl/map/camera.hpp7
-rw-r--r--src/mbgl/map/map.cpp90
-rw-r--r--src/mbgl/map/transform.cpp96
-rw-r--r--src/mbgl/map/transform.hpp40
-rw-r--r--src/mbgl/map/transform_state.cpp19
-rw-r--r--test/map/transform.test.cpp175
-rw-r--r--test/style/source.test.cpp2
-rw-r--r--test/util/tile_cover.test.cpp8
9 files changed, 132 insertions, 312 deletions
diff --git a/benchmark/util/tilecover.benchmark.cpp b/benchmark/util/tilecover.benchmark.cpp
index 186de6f216..03c9149d9e 100644
--- a/benchmark/util/tilecover.benchmark.cpp
+++ b/benchmark/util/tilecover.benchmark.cpp
@@ -22,11 +22,8 @@ static void TileCoverPitchedViewport(benchmark::State& state) {
Transform transform;
transform.resize({ 512, 512 });
// slightly offset center so that tile order is better defined
- transform.setLatLng({ 0.1, -0.1 });
- transform.setZoom(8);
- transform.setAngle(5.0);
- transform.setPitch(40.0 * M_PI / 180.0);
-
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 0.1, -0.1 }).withZoom(8.0).withAngle(5.0).withPitch(40.0));
+
std::size_t length = 0;
while (state.KeepRunning()) {
auto tiles = util::tileCover(transform.getState(), 8);
diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp
index d5563b5ccf..69d699a4e4 100644
--- a/include/mbgl/map/camera.hpp
+++ b/include/mbgl/map/camera.hpp
@@ -15,6 +15,13 @@ namespace mbgl {
center point when both are set.
*/
struct CameraOptions {
+ CameraOptions& withCenter(const optional<LatLng>& o) { center = o; return *this; }
+ CameraOptions& withPadding(const EdgeInsets& p) { padding = p; return *this; }
+ CameraOptions& withAnchor(const optional<ScreenCoordinate>& o) { anchor = o; return *this; }
+ CameraOptions& withZoom(const optional<double>& o) { zoom = o; return *this; }
+ CameraOptions& withAngle(const optional<double>& o) { angle = o; return *this; }
+ CameraOptions& withPitch(const optional<double>& o) { pitch = o; return *this; }
+
/** Coordinate at the center of the map. */
optional<LatLng> center;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 983d43eed3..c963140652 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -303,14 +303,11 @@ void Map::moveBy(const ScreenCoordinate& point, const AnimationOptions& animatio
}
void Map::setLatLng(const LatLng& latLng, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- setLatLng(latLng, animation);
+ easeTo(CameraOptions().withCenter(latLng), animation);
}
void Map::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setLatLng(latLng, padding, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withCenter(latLng).withPadding(padding), animation);
}
LatLng Map::getLatLng(const EdgeInsets& padding) const {
@@ -319,34 +316,22 @@ LatLng Map::getLatLng(const EdgeInsets& padding) const {
void Map::resetPosition(const EdgeInsets& padding) {
impl->cameraMutated = true;
- CameraOptions camera;
- camera.angle = 0;
- camera.pitch = 0;
- camera.center = LatLng(0, 0);
- camera.padding = padding;
- camera.zoom = 0;
- impl->transform.jumpTo(camera);
+ impl->transform.jumpTo(CameraOptions().withCenter(LatLng()).withPadding(padding).withZoom(0.0).withAngle(0.0).withPitch(0.0));
impl->onUpdate();
}
-
#pragma mark - Zoom
void Map::setZoom(double zoom, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- setZoom(zoom, EdgeInsets(), animation);
+ easeTo(CameraOptions().withZoom(zoom), animation);
}
void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setZoom(zoom, anchor, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withZoom(zoom).withAnchor(anchor), animation);
}
void Map::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setZoom(zoom, padding, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withZoom(zoom).withPadding(padding), animation);
}
double Map::getZoom() const {
@@ -354,14 +339,11 @@ double Map::getZoom() const {
}
void Map::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- setLatLngZoom(latLng, zoom, {}, animation);
+ easeTo(CameraOptions().withCenter(latLng).withZoom(zoom), animation);
}
void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setLatLngZoom(latLng, zoom, padding, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withCenter(latLng).withZoom(zoom).withPadding(padding), animation);
}
CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const {
@@ -374,9 +356,8 @@ CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeI
}
CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transform& transform, const EdgeInsets& padding) {
- CameraOptions options;
if (latLngs.empty()) {
- return options;
+ return CameraOptions();
}
Size size = transform.getState().getSize();
// Calculate the bounds of the possibly rotated shape with respect to the viewport.
@@ -421,33 +402,24 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo
// CameraOptions origin is at the top-left corner.
centerPixel.y = viewportHeight - centerPixel.y;
- options.center = transform.screenCoordinateToLatLng(centerPixel);
- options.zoom = zoom;
- return options;
+ return CameraOptions().withCenter(transform.screenCoordinateToLatLng(centerPixel)).withZoom(zoom);
}
CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const {
-
+
if (!bearing && !pitch) {
return mbgl::cameraForLatLngs(latLngs, impl->transform, padding);
}
-
+
Transform transform(impl->transform.getState());
-
- if (bearing) {
- double angle = -*bearing * util::DEG2RAD; // Convert to radians
- transform.setAngle(angle);
- }
- if (pitch) {
- double pitchAsRadian = *pitch * util::DEG2RAD; // Convert to radians
- transform.setPitch(pitchAsRadian);
+
+ if (bearing || pitch) {
+ transform.jumpTo(CameraOptions().withAngle(bearing).withPitch(pitch));
}
-
- CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding);
- options.angle = -transform.getAngle() * util::RAD2DEG;
- options.pitch = transform.getPitch() * util::RAD2DEG;
-
- return options;
+
+ return mbgl::cameraForLatLngs(latLngs, transform, padding)
+ .withAngle(-transform.getAngle() * util::RAD2DEG)
+ .withPitch(transform.getPitch() * util::RAD2DEG);
}
CameraOptions Map::cameraForGeometry(const Geometry<double>& geometry, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const {
@@ -551,20 +523,15 @@ void Map::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second
}
void Map::setBearing(double degrees, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- setBearing(degrees, EdgeInsets(), animation);
+ easeTo(CameraOptions().withAngle(degrees), animation);
}
void Map::setBearing(double degrees, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setAngle(-degrees * util::DEG2RAD, anchor, animation);
- impl->onUpdate();
+ return easeTo(CameraOptions().withAngle(degrees).withAnchor(anchor), animation);
}
void Map::setBearing(double degrees, const EdgeInsets& padding, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setAngle(-degrees * util::DEG2RAD, padding, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withAngle(degrees).withPadding(padding), animation);
}
double Map::getBearing() const {
@@ -572,22 +539,17 @@ double Map::getBearing() const {
}
void Map::resetNorth(const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setAngle(0, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withAngle(0.0), animation);
}
#pragma mark - Pitch
void Map::setPitch(double pitch, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- setPitch(pitch, {}, animation);
+ easeTo(CameraOptions().withPitch(pitch), animation);
}
void Map::setPitch(double pitch, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setPitch(pitch * util::DEG2RAD, anchor, animation);
- impl->onUpdate();
+ easeTo(CameraOptions().withPitch(pitch).withAnchor(anchor), animation);
}
double Map::getPitch() const {
@@ -762,7 +724,7 @@ void Map::Impl::onUpdate() {
if (mode != MapMode::Continuous && !stillImageRequest) {
return;
}
-
+
TimePoint timePoint = mode == MapMode::Continuous ? Clock::now() : Clock::time_point::max();
transform.updateTransitions(timePoint);
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 452cb19a09..5854eaea37 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -88,7 +88,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
double angle = camera.angle ? -*camera.angle * util::DEG2RAD : getAngle();
double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch();
- if (std::isnan(zoom)) {
+ if (std::isnan(zoom) || std::isnan(angle) || std::isnan(pitch)) {
return;
}
@@ -161,7 +161,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
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()) {
+ if (std::isnan(zoom) || std::isnan(angle) || std::isnan(pitch) || state.size.isEmpty()) {
return;
}
@@ -311,42 +311,9 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
#pragma mark - Position
void Transform::moveBy(const ScreenCoordinate& offset, const AnimationOptions& animation) {
- ScreenCoordinate centerOffset = {
- offset.x,
- -offset.y,
- };
+ ScreenCoordinate centerOffset = { offset.x, -offset.y, };
ScreenCoordinate centerPoint = getScreenCoordinate() - centerOffset;
-
- CameraOptions camera;
- camera.center = state.screenCoordinateToLatLng(centerPoint);
- easeTo(camera, animation);
-}
-
-void Transform::setLatLng(const LatLng& latLng, const AnimationOptions& animation) {
- CameraOptions camera;
- camera.center = latLng;
- easeTo(camera, animation);
-}
-
-void Transform::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const AnimationOptions& animation) {
- CameraOptions camera;
- camera.center = latLng;
- camera.padding = padding;
- easeTo(camera, animation);
-}
-
-void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) {
- setLatLngZoom(latLng, zoom, EdgeInsets(), animation);
-}
-
-void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- if (std::isnan(zoom)) return;
-
- CameraOptions camera;
- camera.center = latLng;
- camera.padding = padding;
- camera.zoom = zoom;
- easeTo(camera, animation);
+ easeTo(CameraOptions().withCenter(state.screenCoordinateToLatLng(centerPoint)), animation);
}
LatLng Transform::getLatLng(const EdgeInsets& padding) const {
@@ -368,26 +335,6 @@ ScreenCoordinate Transform::getScreenCoordinate(const EdgeInsets& padding) const
#pragma mark - Zoom
-void Transform::setZoom(double zoom, const AnimationOptions& animation) {
- CameraOptions camera;
- camera.zoom = zoom;
- easeTo(camera, animation);
-}
-
-void Transform::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- CameraOptions camera;
- camera.zoom = zoom;
- camera.anchor = anchor;
- easeTo(camera, animation);
-}
-
-void Transform::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- CameraOptions camera;
- camera.zoom = zoom;
- if (!padding.isFlush()) camera.anchor = getScreenCoordinate(padding);
- easeTo(camera, animation);
-}
-
double Transform::getZoom() const {
return state.getZoom();
}
@@ -437,27 +384,8 @@ void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate&
center.y = first.y + std::sin(rotateAngle) * heightOffset;
}
- CameraOptions camera;
- camera.angle = -(state.angle + util::angle_between(first - center, second - center)) * util::RAD2DEG;
- easeTo(camera, animation);
-}
-
-void Transform::setAngle(double angle, const AnimationOptions& animation) {
- setAngle(angle, optional<ScreenCoordinate> {}, animation);
-}
-
-void Transform::setAngle(double angle, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- if (std::isnan(angle)) return;
- CameraOptions camera;
- camera.angle = -angle * util::RAD2DEG;
- camera.anchor = anchor;
- easeTo(camera, animation);
-}
-
-void Transform::setAngle(double angle, const EdgeInsets& padding, const AnimationOptions& animation) {
- optional<ScreenCoordinate> anchor;
- if (!padding.isFlush()) anchor = getScreenCoordinate(padding);
- setAngle(angle, anchor, animation);
+ const double angle = -(state.angle + util::angle_between(first - center, second - center)) * util::RAD2DEG;
+ easeTo(CameraOptions().withAngle(angle), animation);
}
double Transform::getAngle() const {
@@ -466,18 +394,6 @@ double Transform::getAngle() const {
#pragma mark - Pitch
-void Transform::setPitch(double pitch, const AnimationOptions& animation) {
- setPitch(pitch, optional<ScreenCoordinate> {}, animation);
-}
-
-void Transform::setPitch(double pitch, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- if (std::isnan(pitch)) return;
- CameraOptions camera;
- camera.pitch = pitch * util::RAD2DEG;
- camera.anchor = anchor;
- easeTo(camera, animation);
-}
-
double Transform::getPitch() const {
return state.pitch;
}
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 96573b1519..e872ed444b 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -46,10 +46,6 @@ public:
@param offset The distance to pan the map by, measured in pixels from
top to bottom and from left to right. */
void moveBy(const ScreenCoordinate& offset, const AnimationOptions& = {});
- void setLatLng(const LatLng&, const AnimationOptions& = {});
- void setLatLng(const LatLng&, const EdgeInsets&, const AnimationOptions& = {});
- void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {});
- void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const AnimationOptions& = {});
LatLng getLatLng(const EdgeInsets& = {}) const;
ScreenCoordinate getScreenCoordinate(const EdgeInsets& = {}) const;
@@ -63,53 +59,19 @@ public:
// Zoom
- /** Sets the zoom level, keeping the given point fixed within the view.
- @param zoom The new zoom level. */
- void setZoom(double zoom, const AnimationOptions& = {});
- /** Sets the zoom level, keeping the given point fixed within the view.
- @param zoom The new zoom level.
- @param anchor A point relative to the top-left corner of the view.
- If unspecified, the center point is fixed within the view. */
- void setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
- /** Sets the zoom level, keeping the center point fixed within the inset view.
- @param zoom The new zoom level.
- @param padding The viewport padding that affects the fixed center point. */
- void setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& = {});
/** Returns the zoom level. */
double getZoom() const;
// Angle
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
- /** Sets the angle of rotation.
- @param angle The new angle of rotation, measured in radians
- counterclockwise from true north. */
- void setAngle(double angle, const AnimationOptions& = {});
- /** Sets the angle of rotation, keeping the given point fixed within the view.
- @param angle The new angle of rotation, measured in radians
- counterclockwise from true north.
- @param anchor A point relative to the top-left corner of the view. */
- void setAngle(double angle, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
- /** Sets the angle of rotation, keeping the center point fixed within the inset view.
- @param angle The new angle of rotation, measured in radians
- counterclockwise from true north.
- @param padding The viewport padding that affects the fixed center point. */
- void setAngle(double angle, const EdgeInsets& padding, const AnimationOptions& = {});
/** Returns the angle of rotation.
@return The angle of rotation, measured in radians counterclockwise from
true north. */
double getAngle() const;
// Pitch
- /** Sets the pitch angle.
- @param angle The new pitch angle, measured in radians toward the
- horizon. */
- void setPitch(double pitch, const AnimationOptions& = {});
- /** Sets the pitch angle, keeping the given point fixed within the view.
- @param angle The new pitch angle, measured in radians toward the
- horizon.
- @param anchor A point relative to the top-left corner of the view. */
- void setPitch(double pitch, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
+
double getPitch() const;
// North Orientation
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 4de795d469..554a72cf4a 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -133,21 +133,20 @@ ViewportMode TransformState::getViewportMode() const {
#pragma mark - Camera options
CameraOptions TransformState::getCameraOptions(const EdgeInsets& padding) const {
- CameraOptions camera;
-
+ LatLng center;
if (padding.isFlush()) {
- camera.center = getLatLng();
+ center = getLatLng();
} else {
ScreenCoordinate point = padding.getCenter(size.width, size.height);
point.y = size.height - point.y;
- camera.center = screenCoordinateToLatLng(point).wrapped();
+ center = screenCoordinateToLatLng(point).wrapped();
}
- camera.padding = padding;
- camera.zoom = getZoom();
- camera.angle = -angle * util::RAD2DEG;
- camera.pitch = pitch * util::RAD2DEG;
-
- return camera;
+ return CameraOptions()
+ .withCenter(center)
+ .withPadding(padding)
+ .withZoom(getZoom())
+ .withAngle(-angle * util::RAD2DEG)
+ .withPitch(pitch * util::RAD2DEG);
}
#pragma mark - Position
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp
index 06df34c4c4..eb511a82da 100644
--- a/test/map/transform.test.cpp
+++ b/test/map/transform.test.cpp
@@ -14,46 +14,46 @@ TEST(Transform, InvalidZoom) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(0, transform.getZoom());
- transform.setZoom(1);
+ transform.jumpTo(CameraOptions().withZoom(1.0));
+
ASSERT_DOUBLE_EQ(1, transform.getZoom());
const double invalid = NAN;
- transform.setZoom(invalid);
+ transform.jumpTo(CameraOptions().withZoom(invalid));
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());
- transform.setLatLngZoom({ 0, 0 }, invalid);
+ transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(invalid));
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());
- transform.setZoom(transform.getState().getMaxZoom() + 0.1);
+ transform.jumpTo(CameraOptions().withZoom(transform.getState().getMaxZoom() + 0.1));
ASSERT_DOUBLE_EQ(transform.getZoom(), transform.getState().getMaxZoom());
- CameraOptions cameraOptions;
- cameraOptions.center = LatLng { util::LATITUDE_MAX, util::LONGITUDE_MAX };
- cameraOptions.zoom = transform.getState().getMaxZoom();
-
// Executing flyTo with an empty size causes frameZoom to be NaN.
- transform.flyTo(cameraOptions);
+ transform.flyTo(CameraOptions()
+ .withCenter(LatLng{ util::LATITUDE_MAX, util::LONGITUDE_MAX })
+ .withZoom(transform.getState().getMaxZoom()));
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_DOUBLE_EQ(transform.getZoom(), transform.getState().getMaxZoom());
// Executing flyTo with maximum zoom level to the same zoom level causes
// frameZoom to be bigger than maximum zoom.
transform.resize(Size { 100, 100 });
- transform.flyTo(cameraOptions);
+ transform.flyTo(CameraOptions()
+ .withCenter(LatLng{ util::LATITUDE_MAX, util::LONGITUDE_MAX })
+ .withZoom(transform.getState().getMaxZoom()));
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_TRUE(transform.getState().valid());
ASSERT_DOUBLE_EQ(transform.getState().getMaxZoom(), transform.getZoom());
}
-
TEST(Transform, InvalidBearing) {
Transform transform;
@@ -61,28 +61,26 @@ TEST(Transform, InvalidBearing) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(0, transform.getZoom());
- transform.setZoom(1);
- transform.setAngle(2);
-
+ transform.jumpTo(CameraOptions().withZoom(1.0).withAngle(2.0));
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());
- ASSERT_DOUBLE_EQ(2, transform.getAngle());
+ ASSERT_NEAR(-2.0 * util::DEG2RAD, transform.getAngle(), 1e-15);
const double invalid = NAN;
- transform.setAngle(invalid);
+ transform.jumpTo(CameraOptions().withAngle(invalid));
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());
- ASSERT_DOUBLE_EQ(2, transform.getAngle());
+ ASSERT_NEAR(-2.0 * util::DEG2RAD, transform.getAngle(), 1e-15);
}
TEST(Transform, IntegerZoom) {
Transform transform;
auto checkIntegerZoom = [&transform](uint8_t zoomInt, double zoom) {
- transform.setZoom(zoom);
+ transform.jumpTo(CameraOptions().withZoom(zoom));
ASSERT_NEAR(transform.getZoom(), zoom, 0.0001);
ASSERT_EQ(transform.getState().getIntegerZoom(), zoomInt);
ASSERT_NEAR(transform.getState().getZoomFraction(), zoom - zoomInt, 0.0001);
@@ -104,9 +102,9 @@ TEST(Transform, PerspectiveProjection) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setZoom(10);
- transform.setPitch(0.9);
- transform.setLatLng(LatLng(38, -77));
+
+ // 0.9 rad ~ 51.5662 deg
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 38.0, -77.0 }).withZoom(10.0).withPitch(51.5662));
// expected values are from mapbox-gl-js
@@ -134,9 +132,9 @@ TEST(Transform, PerspectiveProjection) {
TEST(Transform, UnwrappedLatLng) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setZoom(10);
- transform.setPitch(0.9);
- transform.setLatLng(LatLng(38, -77));
+
+ // 0.9 rad ~ 51.5662 deg
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 38.0, -77.0 }).withZoom(10.0).withPitch(51.5662));
const TransformState& state = transform.getState();
@@ -162,39 +160,29 @@ TEST(Transform, UnwrappedLatLng) {
}
TEST(Transform, ConstrainHeightOnly) {
- LatLng loc;
-
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setZoom(util::MAX_ZOOM);
- transform.setLatLng(LatLngBounds::world().southwest());
- loc = transform.getLatLng();
- ASSERT_NEAR(-util::LATITUDE_MAX, loc.latitude(), 0.001);
- ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(loc.longitude()), 0.001);
+ transform.jumpTo(CameraOptions().withCenter(LatLngBounds::world().southwest()).withZoom(util::MAX_ZOOM));
+ ASSERT_NEAR(-util::LATITUDE_MAX, transform.getLatLng().latitude(), 0.001);
+ ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(transform.getLatLng().longitude()), 0.001);
- transform.setLatLng(LatLngBounds::world().northeast());
- loc = transform.getLatLng();
- ASSERT_NEAR(util::LATITUDE_MAX, loc.latitude(), 0.001);
- ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(loc.longitude()), 0.001);
+ transform.jumpTo(CameraOptions().withCenter(LatLngBounds::world().northeast()));
+ ASSERT_NEAR(util::LATITUDE_MAX, transform.getLatLng().latitude(), 0.001);
+ ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(transform.getLatLng().longitude()), 0.001);
}
TEST(Transform, ConstrainWidthAndHeight) {
- LatLng loc;
-
Transform transform(MapObserver::nullObserver(), ConstrainMode::WidthAndHeight);
transform.resize({ 1000, 1000 });
- transform.setZoom(util::MAX_ZOOM);
- transform.setLatLng(LatLngBounds::world().southwest());
- loc = transform.getLatLng();
- ASSERT_NEAR(-util::LATITUDE_MAX, loc.latitude(), 0.001);
- ASSERT_NEAR(-util::LONGITUDE_MAX, loc.longitude(), 0.001);
+ transform.jumpTo(CameraOptions().withCenter(LatLngBounds::world().southwest()).withZoom(util::MAX_ZOOM));
+ ASSERT_NEAR(-util::LATITUDE_MAX, transform.getLatLng().latitude(), 0.001);
+ ASSERT_NEAR(-util::LONGITUDE_MAX, transform.getLatLng().longitude(), 0.001);
- transform.setLatLng(LatLngBounds::world().northeast());
- loc = transform.getLatLng();
- ASSERT_NEAR(util::LATITUDE_MAX, loc.latitude(), 0.001);
- ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(loc.longitude()), 0.001);
+ transform.jumpTo(CameraOptions().withCenter(LatLngBounds::world().northeast()));
+ ASSERT_NEAR(util::LATITUDE_MAX, transform.getLatLng().latitude(), 0.001);
+ ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(transform.getLatLng().longitude()), 0.001);
}
TEST(Transform, Anchor) {
@@ -202,97 +190,90 @@ TEST(Transform, Anchor) {
transform.resize({ 1000, 1000 });
const LatLng latLng { 10, -100 };
- transform.setLatLngZoom(latLng, 10);
+ const ScreenCoordinate anchorPoint = { 150, 150 };
+ transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(10.0));
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(10, transform.getZoom());
ASSERT_DOUBLE_EQ(0, transform.getAngle());
- const optional<ScreenCoordinate> invalidAnchorPoint {};
- const ScreenCoordinate anchorPoint = { 150, 150 };
-
const LatLng anchorLatLng = transform.getState().screenCoordinateToLatLng(anchorPoint);
ASSERT_NE(latLng.latitude(), anchorLatLng.latitude());
ASSERT_NE(latLng.longitude(), anchorLatLng.longitude());
- transform.setLatLngZoom(latLng, 2);
- transform.setZoom(3);
+ transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(3.0));
ASSERT_DOUBLE_EQ(3, transform.getZoom());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.setZoom(3.5, invalidAnchorPoint);
+ transform.jumpTo(CameraOptions().withZoom(3.5));
ASSERT_DOUBLE_EQ(3.5, transform.getZoom());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.setZoom(5.5, anchorPoint);
+ transform.jumpTo(CameraOptions().withZoom(5.5).withAnchor(anchorPoint));
ASSERT_DOUBLE_EQ(5.5, transform.getZoom());
ASSERT_NE(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_NE(latLng.longitude(), transform.getLatLng().longitude());
- transform.setLatLngZoom(latLng, 10);
- transform.setZoom(3);
+ transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(3.0));
ASSERT_DOUBLE_EQ(3, transform.getZoom());
ASSERT_NEAR(latLng.latitude(), transform.getLatLng().latitude(), 0.000001);
ASSERT_NEAR(latLng.longitude(), transform.getLatLng().longitude(), 0.000001);
- transform.setZoom(5, invalidAnchorPoint);
+ transform.jumpTo(CameraOptions().withZoom(5.0));
ASSERT_DOUBLE_EQ(5, transform.getZoom());
ASSERT_NEAR(latLng.latitude(), transform.getLatLng().latitude(), 0.000001);
ASSERT_NEAR(latLng.longitude(), transform.getLatLng().longitude(), 0.000001);
- transform.setZoom(7, anchorPoint);
+ transform.jumpTo(CameraOptions().withZoom(7.0).withAnchor(anchorPoint));
ASSERT_DOUBLE_EQ(7, transform.getZoom());
ASSERT_NE(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_NE(latLng.longitude(), transform.getLatLng().longitude());
- transform.setLatLngZoom(latLng, 10);
- transform.setZoom(2);
+ transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(2.0));
ASSERT_DOUBLE_EQ(2, transform.getZoom());
ASSERT_NEAR(latLng.latitude(), transform.getLatLng().latitude(), 0.000001);
ASSERT_NEAR(latLng.longitude(), transform.getLatLng().longitude(), 0.000001);
- transform.setZoom(4, invalidAnchorPoint);
+ transform.jumpTo(CameraOptions().withZoom(4.0));
ASSERT_DOUBLE_EQ(4, transform.getZoom());
ASSERT_NEAR(latLng.latitude(), transform.getLatLng().latitude(), 0.000001);
ASSERT_NEAR(latLng.longitude(), transform.getLatLng().longitude(), 0.000001);
- transform.setZoom(8, anchorPoint);
+ transform.jumpTo(CameraOptions().withZoom(8.0).withAnchor(anchorPoint));
ASSERT_DOUBLE_EQ(8, transform.getZoom());
ASSERT_NE(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_NE(latLng.longitude(), transform.getLatLng().longitude());
- transform.setLatLngZoom(latLng, 10);
- transform.setAngle(M_PI_4);
+ transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(10.0).withAngle(-45.0));
ASSERT_NEAR(M_PI_4, transform.getAngle(), 0.000001);
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.setAngle(0, invalidAnchorPoint);
+ transform.jumpTo(CameraOptions().withAngle(0.0));
ASSERT_DOUBLE_EQ(0, transform.getAngle());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.setAngle(45 * util::DEG2RAD, anchorPoint);
- ASSERT_NEAR(45 / util::RAD2DEG, transform.getAngle(), 0.000001);
+ transform.jumpTo(CameraOptions().withAngle(45.0).withAnchor(anchorPoint));
+ ASSERT_NEAR(-45.0 * util::DEG2RAD, transform.getAngle(), 0.000001);
ASSERT_NEAR(anchorLatLng.latitude(), transform.getLatLng().latitude(), 1);
ASSERT_NEAR(anchorLatLng.longitude(), transform.getLatLng().longitude(), 1);
- transform.setLatLngZoom(latLng, 10);
- transform.setPitch(10 * util::DEG2RAD);
- ASSERT_DOUBLE_EQ(10 / util::RAD2DEG, transform.getPitch());
+ transform.jumpTo(CameraOptions().withCenter(latLng).withZoom(10.0).withPitch(10.0));
+ ASSERT_DOUBLE_EQ(10.0 * util::DEG2RAD, transform.getPitch());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.setPitch(15 * util::DEG2RAD, invalidAnchorPoint);
- ASSERT_DOUBLE_EQ(15 / util::RAD2DEG, transform.getPitch());
+ transform.jumpTo(CameraOptions().withPitch(15.0));
+ ASSERT_DOUBLE_EQ(15.0 * util::DEG2RAD, transform.getPitch());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.setPitch(20 * util::DEG2RAD, anchorPoint);
- ASSERT_DOUBLE_EQ(20 / util::RAD2DEG, transform.getPitch());
+ transform.jumpTo(CameraOptions().withPitch(20.0).withAnchor(anchorPoint));
+ ASSERT_DOUBLE_EQ(20.0 * util::DEG2RAD, transform.getPitch());
ASSERT_NEAR(anchorLatLng.latitude(), transform.getLatLng().latitude(), 1);
ASSERT_NEAR(anchorLatLng.longitude(), transform.getLatLng().longitude(), 1);
}
@@ -304,7 +285,7 @@ TEST(Transform, Padding) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- transform.setLatLngZoom({ 10, -100 }, 10);
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 10, -100 }).withZoom(10.0));
const LatLng trueCenter = transform.getLatLng();
ASSERT_DOUBLE_EQ(10, trueCenter.latitude());
@@ -327,7 +308,8 @@ TEST(Transform, Padding) {
TEST(Transform, MoveBy) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setLatLngZoom({ 0, 0 }, 10);
+
+ transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(10.0));
LatLng trueCenter = transform.getLatLng();
ASSERT_DOUBLE_EQ(0, trueCenter.latitude());
@@ -354,7 +336,8 @@ TEST(Transform, MoveBy) {
TEST(Transform, Antimeridian) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setLatLngZoom({ 0, 0 }, 1);
+
+ transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(1.0));
// San Francisco
const LatLng coordinateSanFrancisco { 37.7833, -122.4167 };
@@ -362,7 +345,7 @@ TEST(Transform, Antimeridian) {
ASSERT_NEAR(151.79409149185352, pixelSF.x, 1e-2);
ASSERT_NEAR(383.76774094913071, pixelSF.y, 1e-2);
- transform.setLatLng({ 0, -181 });
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 0.0, -181.0 }));
ScreenCoordinate pixelSFLongest = transform.latLngToScreenCoordinate(coordinateSanFrancisco);
ASSERT_NEAR(-357.36306616412816, pixelSFLongest.x, 1e-2);
@@ -374,19 +357,19 @@ TEST(Transform, Antimeridian) {
ASSERT_NEAR(666.63617954008976, pixelSFShortest.x, 1e-2);
ASSERT_DOUBLE_EQ(pixelSF.y, pixelSFShortest.y);
- transform.setLatLng({ 0, 179 });
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 0.0, 179.0 }));
pixelSFShortest = transform.latLngToScreenCoordinate(coordinateSanFrancisco);
ASSERT_DOUBLE_EQ(pixelSFLongest.x, pixelSFShortest.x);
ASSERT_DOUBLE_EQ(pixelSFLongest.y, pixelSFShortest.y);
// Waikiri
const LatLng coordinateWaikiri{ -16.9310, 179.9787 };
- transform.setLatLngZoom(coordinateWaikiri, 10);
+ transform.jumpTo(CameraOptions().withCenter(coordinateWaikiri).withZoom(10.0));
ScreenCoordinate pixelWaikiri = transform.latLngToScreenCoordinate(coordinateWaikiri);
ASSERT_NEAR(500, pixelWaikiri.x, 1e-2);
ASSERT_NEAR(500, pixelWaikiri.y, 1e-2);
- transform.setLatLng({ coordinateWaikiri.latitude(), 180.0213 });
+ transform.jumpTo(CameraOptions().withCenter(LatLng { coordinateWaikiri.latitude(), 180.0213 }));
ScreenCoordinate pixelWaikiriLongest = transform.latLngToScreenCoordinate(coordinateWaikiri);
ASSERT_NEAR(524725.96438108233, pixelWaikiriLongest.x, 1e-2);
ASSERT_DOUBLE_EQ(pixelWaikiri.y, pixelWaikiriLongest.y);
@@ -401,7 +384,7 @@ TEST(Transform, Antimeridian) {
ASSERT_NEAR(coordinateWaikiri.latitude(), coordinateFromPixel.latitude(), 0.000001);
ASSERT_NEAR(coordinateWaikiri.longitude(), coordinateFromPixel.longitude(), 0.000001);
- transform.setLatLng({ coordinateWaikiri.latitude(), -179.9787 });
+ transform.jumpTo(CameraOptions().withCenter(LatLng { coordinateWaikiri.latitude(), 180.0213 }));
pixelWaikiriShortest = transform.latLngToScreenCoordinate(coordinateWaikiri);
ASSERT_DOUBLE_EQ(pixelWaikiriLongest.x, pixelWaikiriShortest.x);
ASSERT_DOUBLE_EQ(pixelWaikiriLongest.y, pixelWaikiriShortest.y);
@@ -416,20 +399,14 @@ TEST(Transform, Camera) {
transform.resize({ 1000, 1000 });
const LatLng latLng1 { 45, 135 };
- CameraOptions cameraOptions1;
- cameraOptions1.zoom = 20;
- cameraOptions1.center = latLng1;
+ CameraOptions cameraOptions1 = CameraOptions().withCenter(latLng1).withZoom(20.0);
transform.jumpTo(cameraOptions1);
-
ASSERT_DOUBLE_EQ(latLng1.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng1.longitude(), transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(20, transform.getZoom());
const LatLng latLng2 { -45, -135 };
- CameraOptions cameraOptions2;
- cameraOptions2.zoom = 10;
- cameraOptions2.center = latLng2;
-
+ CameraOptions cameraOptions2 = CameraOptions().withCenter(latLng2).withZoom(10.0);
transform.jumpTo(cameraOptions2);
ASSERT_DOUBLE_EQ(latLng2.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng2.longitude(), transform.getLatLng().longitude());
@@ -570,7 +547,8 @@ TEST(Transform, LatLngBounds) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setLatLngZoom({ 0, 0 }, transform.getState().getMaxZoom());
+
+ transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(transform.getState().getMaxZoom()));
// Default bounds.
ASSERT_EQ(transform.getState().getLatLngBounds(), optional<LatLngBounds> {});
@@ -584,7 +562,7 @@ TEST(Transform, LatLngBounds) {
ASSERT_EQ(transform.getState().getLatLngBounds(), optional<LatLngBounds> {});
}
- transform.setLatLng(sanFrancisco);
+ transform.jumpTo(CameraOptions().withCenter(sanFrancisco));
ASSERT_EQ(transform.getLatLng(), sanFrancisco);
// Single location.
@@ -592,17 +570,17 @@ TEST(Transform, LatLngBounds) {
ASSERT_EQ(transform.getLatLng(), sanFrancisco);
transform.setLatLngBounds(LatLngBounds::hull({ -90.0, -180.0 }, { 0.0, 180.0 }));
- transform.setLatLng(sanFrancisco);
+ transform.jumpTo(CameraOptions().withCenter(sanFrancisco));
ASSERT_EQ(transform.getLatLng().latitude(), 0.0);
ASSERT_EQ(transform.getLatLng().longitude(), sanFrancisco.longitude());
transform.setLatLngBounds(LatLngBounds::hull({ -90.0, 0.0 }, { 90.0, 180.0 }));
- transform.setLatLng(sanFrancisco);
+ transform.jumpTo(CameraOptions().withCenter(sanFrancisco));
ASSERT_EQ(transform.getLatLng().latitude(), sanFrancisco.latitude());
ASSERT_EQ(transform.getLatLng().longitude(), 0.0);
transform.setLatLngBounds(LatLngBounds::hull({ -90.0, 0.0 }, { 0.0, 180.0 }));
- transform.setLatLng(sanFrancisco);
+ transform.jumpTo(CameraOptions().withCenter(sanFrancisco));
ASSERT_EQ(transform.getLatLng().latitude(), 0.0);
ASSERT_EQ(transform.getLatLng().longitude(), 0.0);
}
@@ -610,17 +588,18 @@ TEST(Transform, LatLngBounds) {
TEST(Transform, PitchBounds) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setLatLngZoom({ 0, 0 }, transform.getState().getMaxZoom());
+
+ transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(transform.getState().getMaxZoom()));
ASSERT_DOUBLE_EQ(transform.getState().getPitch() * util::RAD2DEG, 0.0);
ASSERT_DOUBLE_EQ(transform.getState().getMinPitch() * util::RAD2DEG, 0.0);
ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch() * util::RAD2DEG, 60.0);
transform.setMinPitch(45.0 * util::DEG2RAD);
- transform.setPitch(0.0 * util::DEG2RAD);
+ transform.jumpTo(CameraOptions().withPitch(0));
ASSERT_NEAR(transform.getState().getPitch() * util::RAD2DEG, 45.0, 1e-5);
transform.setMaxPitch(55.0 * util::DEG2RAD);
- transform.setPitch(60.0 * util::DEG2RAD);
+ transform.jumpTo(CameraOptions().withPitch(60.0));
ASSERT_NEAR(transform.getState().getPitch() * util::RAD2DEG, 55.0, 1e-5);
}
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index abd4350231..9bc955fd08 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -76,7 +76,7 @@ public:
Log::setObserver(std::make_unique<Log::NullObserver>());
transform.resize({ 512, 512 });
- transform.setLatLngZoom({0, 0}, 0);
+ transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(0.0));
transformState = transform.getState();
}
diff --git a/test/util/tile_cover.test.cpp b/test/util/tile_cover.test.cpp
index 72d77450a4..326e3da69a 100644
--- a/test/util/tile_cover.test.cpp
+++ b/test/util/tile_cover.test.cpp
@@ -34,13 +34,11 @@ TEST(TileCover, Pitch) {
Transform transform;
transform.resize({ 512, 512 });
// slightly offset center so that tile order is better defined
- transform.setLatLng({ 0.1, -0.1 });
- transform.setZoom(2);
- transform.setAngle(5.0);
- transform.setPitch(40.0 * M_PI / 180.0);
+
+ transform.jumpTo(CameraOptions().withCenter(LatLng { 0.1, -0.1, }).withZoom(2.0).withAngle(5.0).withPitch(40.0));
EXPECT_EQ((std::vector<UnwrappedTileID>{
- { 2, 1, 2 }, { 2, 1, 1 }, { 2, 2, 2 }, { 2, 2, 1 }, { 2, 3, 2 }
+ { 2, 1, 1 }, { 2, 2, 1 }, { 2, 1, 2 }, { 2, 2, 2 }
}),
util::tileCover(transform.getState(), 2));
}