From 0314a46ee411b97810d49908ab110bbef049e7b7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 16 Mar 2016 17:45:00 -0700 Subject: [core] Tighten LatLng and other geo.hpp classes * Remove LatLng::null and enforce invariants * Remove unnecessary operator bool() --- src/mbgl/map/map.cpp | 4 ++-- src/mbgl/map/transform.cpp | 35 +++++++++++++---------------------- 2 files changed, 15 insertions(+), 24 deletions(-) (limited to 'src/mbgl') diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 8957f3272e..60113b5733 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -616,7 +616,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, optional if (width > 0 || height > 0) { double scaleX = double(getSize().width) / width; double scaleY = double(getSize().height) / height; - if (padding && *padding) { + if (padding) { scaleX -= (padding->left + padding->right) / width; scaleY -= (padding->top + padding->bottom) / height; } @@ -627,7 +627,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, optional // Calculate the center point of a virtual bounds that is extended in all directions by padding. ScreenCoordinate centerPixel = nePixel + swPixel; - if (padding && *padding) { + if (padding) { ScreenCoordinate paddedNEPixel = { padding->right / minScale, padding->top / minScale, diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index d325271388..71d216f1ed 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -93,13 +93,12 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim double angle = camera.angle.value_or(getAngle()); double pitch = camera.pitch.value_or(getPitch()); - if (!latLng || std::isnan(zoom)) { + if (std::isnan(zoom)) { return; } // Determine endpoints. - EdgeInsets padding; - if (camera.padding) padding = *camera.padding; + optional 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 @@ -168,13 +167,12 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima double angle = camera.angle.value_or(getAngle()); double pitch = camera.pitch.value_or(getPitch()); - if (!latLng || std::isnan(zoom)) { + if (std::isnan(zoom)) { return; } // Determine endpoints. - EdgeInsets padding; - if (camera.padding) padding = *camera.padding; + optional padding = camera.padding; LatLng startLatLng = getLatLng(padding).wrapped(); startLatLng.unwrapForShortestPath(latLng); @@ -198,9 +196,9 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima /// w₀: Initial visible span, measured in pixels at the initial scale. /// Known henceforth as a screenful. - double w0 = padding ? std::max(state.size.width, state.size.height) - : std::max(state.size.width - padding.left - padding.right, - state.size.height - padding.top - padding.bottom); + 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); /// w₁: Final visible span, measured in pixels with respect to the initial /// scale. double w1 = w0 / state.zoomScale(zoom - startZoom); @@ -335,7 +333,6 @@ void Transform::setLatLng(const LatLng& latLng, const AnimationOptions& animatio } void Transform::setLatLng(const LatLng& latLng, optional padding, const AnimationOptions& animation) { - if (!latLng) return; CameraOptions camera; camera.center = latLng; camera.padding = padding; @@ -343,26 +340,20 @@ void Transform::setLatLng(const LatLng& latLng, optional padding, co } void Transform::setLatLng(const LatLng& latLng, optional anchor, const AnimationOptions& animation) { - if (!latLng) return; CameraOptions camera; camera.center = latLng; if (anchor) { - EdgeInsets padding; - padding.top = anchor->y; - padding.left = anchor->x; - padding.bottom = state.size.height - anchor->y; - padding.right = state.size.width - anchor->x; - if (padding) camera.padding = padding; + camera.padding = EdgeInsets(anchor->y, anchor->x, state.size.height - anchor->y, state.size.width - anchor->x); } easeTo(camera, animation); } void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) { - setLatLngZoom(latLng, zoom, EdgeInsets {}, animation); + setLatLngZoom(latLng, zoom, optional {}, animation); } void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional padding, const AnimationOptions& animation) { - if (!latLng || std::isnan(zoom)) return; + if (std::isnan(zoom)) return; CameraOptions camera; camera.center = latLng; @@ -372,7 +363,7 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional padding) const { - if (padding && *padding) { + if (padding) { return screenCoordinateToLatLng(padding->getCenter(state.size.width, state.size.height)); } else { return state.getLatLng(); @@ -380,7 +371,7 @@ LatLng Transform::getLatLng(optional padding) const { } ScreenCoordinate Transform::getScreenCoordinate(optional padding) const { - if (padding && *padding) { + if (padding) { return padding->getCenter(state.size.width, state.size.height); } else { return { state.size.width / 2., state.size.height / 2. }; @@ -483,7 +474,7 @@ void Transform::setAngle(double angle, optional anchor, const void Transform::setAngle(double angle, optional padding, const AnimationOptions& animation) { optional anchor; - if (padding && *padding) anchor = getScreenCoordinate(padding); + if (padding) anchor = getScreenCoordinate(padding); setAngle(angle, anchor, animation); } -- cgit v1.2.1