From ab6185fdc343448d3b6cbfc5e2bc91b5242fdf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 6 Apr 2017 08:28:28 -0700 Subject: [ios, macos] Streamlined coordinate validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- platform/darwin/src/MGLGeometry.mm | 9 +++++++++ platform/darwin/src/MGLGeometry_Private.h | 16 +--------------- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'platform/darwin') 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 MGLPointFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) { return mbgl::Point(coordinate.longitude, coordinate.latitude); -- cgit v1.2.1