diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-04-06 08:28:28 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-04-06 09:22:51 -0700 |
commit | ab6185fdc343448d3b6cbfc5e2bc91b5242fdf9f (patch) | |
tree | 71bf3a090c01570dc7f28899928dade0ed1424f0 /platform | |
parent | 16a2839e23d42d4640ef028d62dc01322a0d2e5a (diff) | |
download | qtlocation-mapboxgl-ab6185fdc343448d3b6cbfc5e2bc91b5242fdf9f.tar.gz |
[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.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/src/MGLGeometry.mm | 9 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeometry_Private.h | 16 |
2 files changed, 10 insertions, 15 deletions
diff --git a/platform/darwin/src/MGLGeometry.mm b/platform/darwin/src/MGLGeometry.mm index 8c0c5f9cb7..1540a3a741 100644 --- a/platform/darwin/src/MGLGeometry.mm +++ b/platform/darwin/src/MGLGeometry.mm @@ -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); diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h index d72e4959c9..3e029e8ee0 100644 --- a/platform/darwin/src/MGLGeometry_Private.h +++ b/platform/darwin/src/MGLGeometry_Private.h @@ -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); |