[ios, macos] Streamlined coordinate validation
Replaced preflight checks in MGLLatLngFromLocationCoordinate2D() with a try-catch block that relays exceptions raised by mbgl. De-inlined the function because it’s no longer trivial.
This commit is contained in:
committed by
John Firebaugh
parent
16a2839e23
commit
ab6185fdc3
@@ -32,6 +32,15 @@ CGRect MGLExtendRect(CGRect rect, CGPoint point) {
|
||||
return rect;
|
||||
}
|
||||
|
||||
mbgl::LatLng MGLLatLngFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
|
||||
try {
|
||||
return mbgl::LatLng(coordinate.latitude, coordinate.longitude);
|
||||
} catch (std::domain_error &error) {
|
||||
[NSException raise:NSInvalidArgumentException format:@"%s", error.what()];
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
MGL_EXPORT
|
||||
CLLocationDistance MGLAltitudeForZoomLevel(double zoomLevel, CGFloat pitch, CLLocationDegrees latitude, CGSize size) {
|
||||
CLLocationDistance metersPerPixel = mbgl::Projection::getMetersPerPixelAtLatitude(latitude, zoomLevel);
|
||||
|
||||
@@ -12,21 +12,7 @@
|
||||
/// the given point.
|
||||
CGRect MGLExtendRect(CGRect rect, CGPoint point);
|
||||
|
||||
NS_INLINE mbgl::LatLng MGLLatLngFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
|
||||
if (std::isnan(coordinate.latitude)) {
|
||||
[NSException raise:NSInvalidArgumentException format:@"latitude must not be NaN"];
|
||||
}
|
||||
if (std::isnan(coordinate.longitude)) {
|
||||
[NSException raise:NSInvalidArgumentException format:@"longitude must not be NaN"];
|
||||
}
|
||||
if (std::abs(coordinate.latitude) > 90.0) {
|
||||
[NSException raise:NSInvalidArgumentException format:@"latitude must be between -90 and 90"];
|
||||
}
|
||||
if (!std::isfinite(coordinate.longitude)) {
|
||||
[NSException raise:NSInvalidArgumentException format:@"longitude must not be infinite"];
|
||||
}
|
||||
return mbgl::LatLng(coordinate.latitude, coordinate.longitude);
|
||||
}
|
||||
mbgl::LatLng MGLLatLngFromLocationCoordinate2D(CLLocationCoordinate2D coordinate);
|
||||
|
||||
NS_INLINE mbgl::Point<double> MGLPointFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
|
||||
return mbgl::Point<double>(coordinate.longitude, coordinate.latitude);
|
||||
|
||||
Reference in New Issue
Block a user