summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/map/camera.hpp2
-rw-r--r--include/mbgl/map/map.hpp20
-rw-r--r--include/mbgl/util/geo.hpp3
-rw-r--r--src/mbgl/map/map.cpp46
-rw-r--r--src/mbgl/map/transform.cpp47
-rw-r--r--src/mbgl/map/transform.hpp18
6 files changed, 67 insertions, 69 deletions
diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp
index 20b863cf4e..53b5b590b1 100644
--- a/include/mbgl/map/camera.hpp
+++ b/include/mbgl/map/camera.hpp
@@ -17,7 +17,7 @@ struct CameraOptions {
/** Padding around the interior of the view that affects the frame of
reference for `center`. */
- optional<EdgeInsets> padding;
+ EdgeInsets padding;
/** Point of reference for `zoom` and `angle`, assuming an origin at the
top-left corner of the view. */
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 74942e211d..c39009c8da 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -82,7 +82,7 @@ public:
bool isPanning() const;
// Camera
- CameraOptions getCameraOptions(optional<EdgeInsets>) const;
+ CameraOptions getCameraOptions(const EdgeInsets&) const;
void jumpTo(const CameraOptions&);
void easeTo(const CameraOptions&, const AnimationOptions&);
void flyTo(const CameraOptions&, const AnimationOptions&);
@@ -90,10 +90,10 @@ public:
// Position
void moveBy(const ScreenCoordinate&, const AnimationOptions& = {});
void setLatLng(const LatLng&, optional<ScreenCoordinate>, const AnimationOptions& = {});
- void setLatLng(const LatLng&, optional<EdgeInsets>, const AnimationOptions& = {});
+ void setLatLng(const LatLng&, const EdgeInsets&, const AnimationOptions& = {});
void setLatLng(const LatLng&, const AnimationOptions& = {});
- LatLng getLatLng(optional<EdgeInsets> = {}) const;
- void resetPosition(optional<EdgeInsets> = {});
+ LatLng getLatLng(const EdgeInsets& = {}) const;
+ void resetPosition(const EdgeInsets& = {});
// Scale
void scaleBy(double ds, optional<ScreenCoordinate> = {}, const AnimationOptions& = {});
@@ -101,12 +101,12 @@ public:
double getScale() const;
void setZoom(double zoom, const AnimationOptions& = {});
void setZoom(double zoom, optional<ScreenCoordinate>, const AnimationOptions& = {});
- void setZoom(double zoom, optional<EdgeInsets>, const AnimationOptions& = {});
+ void setZoom(double zoom, const EdgeInsets&, const AnimationOptions& = {});
double getZoom() const;
void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {});
- void setLatLngZoom(const LatLng&, double zoom, optional<EdgeInsets>, const AnimationOptions& = {});
- CameraOptions cameraForLatLngBounds(const LatLngBounds&, optional<EdgeInsets>) const;
- CameraOptions cameraForLatLngs(const std::vector<LatLng>&, optional<EdgeInsets>) const;
+ void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const AnimationOptions& = {});
+ CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&) const;
+ CameraOptions cameraForLatLngs(const std::vector<LatLng>&, const EdgeInsets&) const;
LatLngBounds latLngBoundsForCamera(const CameraOptions&) const;
void resetZoom();
@@ -126,10 +126,10 @@ public:
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
void setBearing(double degrees, const AnimationOptions& = {});
void setBearing(double degrees, optional<ScreenCoordinate>, const AnimationOptions& = {});
- void setBearing(double degrees, optional<EdgeInsets>, const AnimationOptions& = {});
+ void setBearing(double degrees, const EdgeInsets&, const AnimationOptions& = {});
double getBearing() const;
void resetNorth(const AnimationOptions& = {{mbgl::Milliseconds(500)}});
- void resetNorth(optional<EdgeInsets>, const AnimationOptions& = {{mbgl::Milliseconds(500)}});
+ void resetNorth(const EdgeInsets&, const AnimationOptions& = {{mbgl::Milliseconds(500)}});
// Pitch
void setPitch(double pitch, const AnimationOptions& = {});
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 04aa1e1bfa..edd40e73ca 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -221,6 +221,9 @@ public:
EdgeInsets(const double t, const double l, const double b, const double r)
: top(t), left(l), bottom(b), right(r) {}
+ bool isFlush() const {
+ return top == 0 && left == 0 && bottom == 0 && right == 0;
+ }
void operator+=(const EdgeInsets& o) {
top += o.top;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index d4251ffc1e..45b2f26568 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -468,7 +468,7 @@ bool Map::isPanning() const {
#pragma mark -
-CameraOptions Map::getCameraOptions(optional<EdgeInsets> padding) const {
+CameraOptions Map::getCameraOptions(const EdgeInsets& padding) const {
return impl->transform.getCameraOptions(padding);
}
@@ -503,7 +503,7 @@ void Map::setLatLng(const LatLng& latLng, const AnimationOptions& animation) {
setLatLng(latLng, optional<ScreenCoordinate> {}, animation);
}
-void Map::setLatLng(const LatLng& latLng, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Map::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.setLatLng(latLng, padding, animation);
impl->onUpdate(Update::Repaint);
@@ -515,11 +515,11 @@ void Map::setLatLng(const LatLng& latLng, optional<ScreenCoordinate> anchor, con
impl->onUpdate(Update::Repaint);
}
-LatLng Map::getLatLng(optional<EdgeInsets> padding) const {
+LatLng Map::getLatLng(const EdgeInsets& padding) const {
return impl->transform.getLatLng(padding);
}
-void Map::resetPosition(optional<EdgeInsets> padding) {
+void Map::resetPosition(const EdgeInsets& padding) {
impl->cameraMutated = true;
CameraOptions camera;
camera.angle = 0;
@@ -552,7 +552,7 @@ double Map::getScale() const {
void Map::setZoom(double zoom, const AnimationOptions& animation) {
impl->cameraMutated = true;
- setZoom(zoom, optional<EdgeInsets> {}, animation);
+ setZoom(zoom, EdgeInsets(), animation);
}
void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
@@ -561,7 +561,7 @@ void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const Animatio
impl->onUpdate(Update::RecalculateStyle);
}
-void Map::setZoom(double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Map::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.setZoom(zoom, padding, animation);
impl->onUpdate(Update::RecalculateStyle);
@@ -576,13 +576,13 @@ void Map::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOption
setLatLngZoom(latLng, zoom, {}, animation);
}
-void Map::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeInsets> padding, const AnimationOptions& 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(Update::RecalculateStyle);
}
-CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, optional<EdgeInsets> padding) const {
+CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding) const {
return cameraForLatLngs({
bounds.northwest(),
bounds.southwest(),
@@ -591,7 +591,7 @@ CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, optional<Ed
}, padding);
}
-CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional<EdgeInsets> padding) const {
+CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding) const {
CameraOptions options;
if (latLngs.empty()) {
return options;
@@ -616,10 +616,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional
if (width > 0 || height > 0) {
double scaleX = double(getSize().width) / width;
double scaleY = double(getSize().height) / height;
- if (padding) {
- scaleX -= (padding->left + padding->right) / width;
- scaleY -= (padding->top + padding->bottom) / height;
- }
+ scaleX -= (padding.left + padding.right) / width;
+ scaleY -= (padding.top + padding.bottom) / height;
minScale = util::min(scaleX, scaleY);
}
double zoom = util::log2(getScale() * minScale);
@@ -627,17 +625,15 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional
// Calculate the center point of a virtual bounds that is extended in all directions by padding.
ScreenCoordinate centerPixel = nePixel + swPixel;
- if (padding) {
- ScreenCoordinate paddedNEPixel = {
- padding->right / minScale,
- padding->top / minScale,
- };
- ScreenCoordinate paddedSWPixel = {
- padding->left / minScale,
- padding->bottom / minScale,
- };
- centerPixel = centerPixel + paddedNEPixel - paddedSWPixel;
- }
+ ScreenCoordinate paddedNEPixel = {
+ padding.right / minScale,
+ padding.top / minScale,
+ };
+ ScreenCoordinate paddedSWPixel = {
+ padding.left / minScale,
+ padding.bottom / minScale,
+ };
+ centerPixel = centerPixel + paddedNEPixel - paddedSWPixel;
centerPixel /= 2.0;
// CameraOptions origin is at the top-left corner.
@@ -750,7 +746,7 @@ void Map::setBearing(double degrees, optional<ScreenCoordinate> anchor, const An
impl->onUpdate(Update::Repaint);
}
-void Map::setBearing(double degrees, optional<EdgeInsets> padding, const AnimationOptions& 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(Update::Repaint);
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 9febc3ab5a..eab40a6ee5 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -64,7 +64,7 @@ void Transform::resize(const Size size) {
#pragma mark - Camera
-CameraOptions Transform::getCameraOptions(optional<EdgeInsets> padding) const {
+CameraOptions Transform::getCameraOptions(const EdgeInsets& padding) const {
CameraOptions camera;
camera.center = getLatLng(padding);
camera.padding = padding;
@@ -100,7 +100,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
}
// Determine endpoints.
- optional<EdgeInsets> padding = camera.padding;
+ EdgeInsets padding = camera.padding;
LatLng startLatLng = getLatLng(padding);
// If gesture in progress, we transfer the world rounds from the end
// longitude into start, so we can guarantee the "scroll effect" of rounding
@@ -150,7 +150,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
state.pitch = util::interpolate(startPitch, pitch, t);
}
- if (padding) {
+ if (!padding.isFlush()) {
state.moveLatLng(frameLatLng, center);
}
return update;
@@ -176,7 +176,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
}
// Determine endpoints.
- optional<EdgeInsets> padding = camera.padding;
+ EdgeInsets padding = camera.padding;
LatLng startLatLng = getLatLng(padding).wrapped();
startLatLng.unwrapForShortestPath(latLng);
@@ -200,9 +200,8 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
/// w₀: Initial visible span, measured in pixels at the initial scale.
/// Known henceforth as a <i>screenful</i>.
- double w0 = padding ? std::max(state.size.width - padding->left - padding->right,
- state.size.height - padding->top - padding->bottom)
- : std::max(state.size.width, state.size.height);
+ double w0 = std::max(state.size.width - padding.left - padding.right,
+ state.size.height - padding.top - padding.bottom);
/// w₁: Final visible span, measured in pixels with respect to the initial
/// scale.
double w1 = w0 / state.zoomScale(zoom - startZoom);
@@ -311,7 +310,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
state.pitch = util::interpolate(startPitch, pitch, k);
}
- if (padding) {
+ if (!padding.isFlush()) {
state.moveLatLng(frameLatLng, center);
}
return Update::RecalculateStyle;
@@ -336,7 +335,7 @@ void Transform::setLatLng(const LatLng& latLng, const AnimationOptions& animatio
setLatLng(latLng, optional<ScreenCoordinate> {}, animation);
}
-void Transform::setLatLng(const LatLng& latLng, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Transform::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const AnimationOptions& animation) {
CameraOptions camera;
camera.center = latLng;
camera.padding = padding;
@@ -353,10 +352,10 @@ void Transform::setLatLng(const LatLng& latLng, optional<ScreenCoordinate> ancho
}
void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) {
- setLatLngZoom(latLng, zoom, optional<EdgeInsets> {}, animation);
+ setLatLngZoom(latLng, zoom, EdgeInsets(), animation);
}
-void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
if (std::isnan(zoom)) return;
CameraOptions camera;
@@ -366,19 +365,19 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeIn
easeTo(camera, animation);
}
-LatLng Transform::getLatLng(optional<EdgeInsets> padding) const {
- if (padding) {
- return screenCoordinateToLatLng(padding->getCenter(state.size.width, state.size.height));
- } else {
+LatLng Transform::getLatLng(const EdgeInsets& padding) const {
+ if (padding.isFlush()) {
return state.getLatLng();
+ } else {
+ return screenCoordinateToLatLng(padding.getCenter(state.size.width, state.size.height));
}
}
-ScreenCoordinate Transform::getScreenCoordinate(optional<EdgeInsets> padding) const {
- if (padding) {
- return padding->getCenter(state.size.width, state.size.height);
- } else {
+ScreenCoordinate Transform::getScreenCoordinate(const EdgeInsets& padding) const {
+ if (padding.isFlush()) {
return { state.size.width / 2., state.size.height / 2. };
+ } else {
+ return padding.getCenter(state.size.width, state.size.height);
}
}
@@ -403,7 +402,7 @@ void Transform::setZoom(double zoom, optional<ScreenCoordinate> anchor, const An
setScale(state.zoomScale(zoom), anchor, animation);
}
-void Transform::setZoom(double zoom, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Transform::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
setScale(state.zoomScale(zoom), padding, animation);
}
@@ -427,9 +426,9 @@ void Transform::setScale(double scale, optional<ScreenCoordinate> anchor, const
easeTo(camera, animation);
}
-void Transform::setScale(double scale, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Transform::setScale(double scale, const EdgeInsets& padding, const AnimationOptions& animation) {
optional<ScreenCoordinate> anchor;
- if (padding) anchor = getScreenCoordinate(padding);
+ if (!padding.isFlush()) anchor = getScreenCoordinate(padding);
setScale(scale, anchor, animation);
}
@@ -494,9 +493,9 @@ void Transform::setAngle(double angle, optional<ScreenCoordinate> anchor, const
easeTo(camera, animation);
}
-void Transform::setAngle(double angle, optional<EdgeInsets> padding, const AnimationOptions& animation) {
+void Transform::setAngle(double angle, const EdgeInsets& padding, const AnimationOptions& animation) {
optional<ScreenCoordinate> anchor;
- if (padding) anchor = getScreenCoordinate(padding);
+ if (!padding.isFlush()) anchor = getScreenCoordinate(padding);
setAngle(angle, anchor, animation);
}
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index f0feae0911..993f8f2c5f 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -29,7 +29,7 @@ public:
// Camera
/** Returns the current camera options. */
- CameraOptions getCameraOptions(optional<EdgeInsets>) const;
+ CameraOptions getCameraOptions(const EdgeInsets&) const;
/** Instantaneously, synchronously applies the given camera options. */
void jumpTo(const CameraOptions&);
@@ -47,13 +47,13 @@ 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&, optional<EdgeInsets>, const AnimationOptions& = {});
+ void setLatLng(const LatLng&, const AnimationOptions& = {});
+ void setLatLng(const LatLng&, const EdgeInsets&, const AnimationOptions& = {});
void setLatLng(const LatLng&, optional<ScreenCoordinate>, const AnimationOptions& = {});
void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {});
- void setLatLngZoom(const LatLng&, double zoom, optional<EdgeInsets>, const AnimationOptions& = {});
- LatLng getLatLng(optional<EdgeInsets> = {}) const;
- ScreenCoordinate getScreenCoordinate(optional<EdgeInsets> = {}) const;
+ void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const AnimationOptions& = {});
+ LatLng getLatLng(const EdgeInsets& = {}) const;
+ ScreenCoordinate getScreenCoordinate(const EdgeInsets& = {}) const;
// Bounds
@@ -84,7 +84,7 @@ public:
/** Sets the scale factor, keeping the center point fixed within the inset view.
@param scale The new scale factor.
@param padding The viewport padding that affects the fixed center point. */
- void setScale(double scale, optional<EdgeInsets> padding, const AnimationOptions& = {});
+ void setScale(double scale, const EdgeInsets& padding, const AnimationOptions& = {});
/** Sets the zoom level, keeping the given point fixed within the view.
@param zoom The new zoom level. */
void setZoom(double zoom, const AnimationOptions& = {});
@@ -96,7 +96,7 @@ public:
/** 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, optional<EdgeInsets> padding, const AnimationOptions& = {});
+ void setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& = {});
/** Returns the zoom level. */
double getZoom() const;
/** Returns the scale factor. */
@@ -118,7 +118,7 @@ public:
@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, optional<EdgeInsets> padding, const AnimationOptions& = {});
+ 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. */