[core] Implement LatLng::null()
This commit is contained in:
@@ -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(); }
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user