[core] Implement LatLng::null()

This commit is contained in:
Bruno de Oliveira Abinader
2016-03-13 19:04:59 +02:00
parent 8e30a4a080
commit fe7e208b42
3 changed files with 10 additions and 2 deletions

View File

@@ -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(); }

View File

@@ -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);

View File

@@ -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()));
}