summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/geo.hpp4
-rw-r--r--src/mbgl/map/transform.cpp5
-rw-r--r--test/map/transform.cpp3
3 files changed, 10 insertions, 2 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 94fbdc3d09..0b6ee17507 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -14,11 +14,15 @@ using ScreenCoordinate = vec2<double>;
class LatLng {
public:
+ struct null {};
+
double latitude;
double longitude;
enum WrapMode : bool { Unwrapped, Wrapped };
+ LatLng(null) : latitude(std::numeric_limits<double>::quiet_NaN()), longitude(latitude) {}
+
LatLng(double lat = 0, double lon = 0, WrapMode mode = Unwrapped)
: latitude(lat), longitude(lon) { if (mode == Wrapped) wrap(); }
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 9868d96485..26245c86ee 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -651,7 +651,7 @@ void Transform::setGestureInProgress(bool inProgress) {
#pragma mark Conversion and projection
ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const {
- if (!latLng) return {};
+ if (!latLng) return ScreenCoordinate::null();
// If the center and point coordinates are not in the same side of the
// antimeridian, we need to unwrap the point longitude to make sure it can
@@ -672,7 +672,8 @@ ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const
}
LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const {
- if (!point) return {};
+ if (!point) return LatLng::null();
+
ScreenCoordinate flippedPoint = point;
flippedPoint.y = state.height - flippedPoint.y;
return state.screenCoordinateToLatLng(flippedPoint);
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index c490ca4894..d07a8d3880 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -79,6 +79,9 @@ TEST(Transform, InvalidLatLng) {
ASSERT_DOUBLE_EQ(10, transform.getLatLng().latitude);
ASSERT_DOUBLE_EQ(8, transform.getLatLng().longitude);
ASSERT_DOUBLE_EQ(4, transform.getScale());
+
+ ASSERT_FALSE(transform.latLngToScreenCoordinate(LatLng::null()));
+ ASSERT_FALSE(transform.screenCoordinateToLatLng(ScreenCoordinate::null()));
}