diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-02 15:04:21 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-02 23:04:18 -0800 |
commit | 37c27f3a8f55ae74d7da9b5f45fa577de3af7f21 (patch) | |
tree | 88d479ad1d4a3559844c3fd8c82ab4a33c4bc55b /platform | |
parent | 032c8fba3c8e3c122dd399b5c9341d92ad9d286f (diff) | |
download | qtlocation-mapboxgl-37c27f3a8f55ae74d7da9b5f45fa577de3af7f21.tar.gz |
[core] Improve LatLngBounds API
* Use "named constructors": empty, world, hull
* Make the two-argument constructor lenient (i.e., it is a hull operation)
* Add various accessors
* Enforce a single empty representation
Diffstat (limited to 'platform')
-rwxr-xr-x | platform/android/src/jni.cpp | 5 | ||||
-rw-r--r-- | platform/darwin/MGLGeometry_Private.h | 8 | ||||
-rw-r--r-- | platform/darwin/MGLMultiPoint.mm | 21 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 24 | ||||
-rw-r--r-- | platform/osx/src/MGLMapView.mm | 22 |
5 files changed, 37 insertions, 43 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 228d758f3b..4e76095a06 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -1182,10 +1182,9 @@ jlongArray JNICALL nativeGetAnnotationsInBounds(JNIEnv *env, jobject obj, jlong return nullptr; } - mbgl::LatLngBounds bounds({ swLat, swLon }, { neLat, neLon }); - // assume only points for now - std::vector<uint32_t> annotations = nativeMapView->getMap().getPointAnnotationsInBounds(bounds); + std::vector<uint32_t> annotations = nativeMapView->getMap().getPointAnnotationsInBounds( + mbgl::LatLngBounds::hull({ swLat, swLon }, { neLat, neLon })); return std_vector_uint_to_jobject(env, annotations); } diff --git a/platform/darwin/MGLGeometry_Private.h b/platform/darwin/MGLGeometry_Private.h index bf5bc4e0ff..72123827df 100644 --- a/platform/darwin/MGLGeometry_Private.h +++ b/platform/darwin/MGLGeometry_Private.h @@ -21,13 +21,13 @@ NS_INLINE CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng } NS_INLINE MGLCoordinateBounds MGLCoordinateBoundsFromLatLngBounds(mbgl::LatLngBounds latLngBounds) { - return MGLCoordinateBoundsMake(MGLLocationCoordinate2DFromLatLng(latLngBounds.sw), - MGLLocationCoordinate2DFromLatLng(latLngBounds.ne)); + return MGLCoordinateBoundsMake(MGLLocationCoordinate2DFromLatLng(latLngBounds.southwest()), + MGLLocationCoordinate2DFromLatLng(latLngBounds.northeast())); } NS_INLINE mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBounds coordinateBounds) { - return mbgl::LatLngBounds(MGLLatLngFromLocationCoordinate2D(coordinateBounds.sw), - MGLLatLngFromLocationCoordinate2D(coordinateBounds.ne)); + return mbgl::LatLngBounds::hull(MGLLatLngFromLocationCoordinate2D(coordinateBounds.sw), + MGLLatLngFromLocationCoordinate2D(coordinateBounds.ne)); } NS_INLINE BOOL MGLCoordinateInCoordinateBounds(CLLocationCoordinate2D coordinate, MGLCoordinateBounds coordinateBounds) { diff --git a/platform/darwin/MGLMultiPoint.mm b/platform/darwin/MGLMultiPoint.mm index fd27cf7819..3cd0f0c117 100644 --- a/platform/darwin/MGLMultiPoint.mm +++ b/platform/darwin/MGLMultiPoint.mm @@ -16,7 +16,7 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) { { CLLocationCoordinate2D *_coords; size_t _count; - mbgl::LatLngBounds _bounds; + MGLCoordinateBounds _bounds; } - (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords @@ -28,13 +28,16 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) { { _count = count; _coords = (CLLocationCoordinate2D *)malloc(_count * sizeof(CLLocationCoordinate2D)); - _bounds = mbgl::LatLngBounds::getExtendable(); + + mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); for (NSUInteger i = 0; i < _count; i++) { _coords[i] = coords[i]; - _bounds.extend(mbgl::LatLng(coords[i].latitude, coords[i].longitude)); + bounds.extend(mbgl::LatLng(coords[i].latitude, coords[i].longitude)); } + + _bounds = MGLCoordinateBoundsFromLatLngBounds(bounds); } return self; @@ -93,20 +96,12 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) { - (MGLCoordinateBounds)overlayBounds { - return { - CLLocationCoordinate2DMake(_bounds.sw.latitude, _bounds.sw.longitude), - CLLocationCoordinate2DMake(_bounds.ne.latitude, _bounds.ne.longitude) - }; + return _bounds; } - (BOOL)intersectsOverlayBounds:(MGLCoordinateBounds)overlayBounds { - mbgl::LatLngBounds area( - mbgl::LatLng(overlayBounds.sw.latitude, overlayBounds.sw.longitude), - mbgl::LatLng(overlayBounds.ne.latitude, overlayBounds.ne.longitude) - ); - - return _bounds.intersects(area); + return MGLLatLngBoundsFromCoordinateBounds(_bounds).intersects(MGLLatLngBoundsFromCoordinateBounds(overlayBounds)); } - (void)addShapeAnnotationObjectToCollection:(std::vector<mbgl::ShapeAnnotation> &)shapes withDelegate:(id <MGLMultiPointDelegate>)delegate { diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index c9d3145e2e..fdecf2b243 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2177,8 +2177,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) /// Converts a geographic bounding box to a rectangle in the view’s coordinate /// system. - (CGRect)convertLatLngBounds:(mbgl::LatLngBounds)bounds toRectToView:(nullable UIView *)view { - CGRect rect = { [self convertLatLng:bounds.sw toPointToView:view], CGSizeZero }; - rect = MGLExtendRect(rect, [self convertLatLng:bounds.ne toPointToView:view]); + CGRect rect = { [self convertLatLng:bounds.southwest() toPointToView:view], CGSizeZero }; + rect = MGLExtendRect(rect, [self convertLatLng:bounds.northeast() toPointToView:view]); return rect; } @@ -2186,7 +2186,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) /// bounding box. - (mbgl::LatLngBounds)convertRect:(CGRect)rect toLatLngBoundsFromView:(nullable UIView *)view { - mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable(); + mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); bounds.extend([self convertPoint:rect.origin toLatLngFromView:view]); bounds.extend([self convertPoint:{ CGRectGetMaxX(rect), CGRectGetMinY(rect) } toLatLngFromView:view]); bounds.extend([self convertPoint:{ CGRectGetMaxX(rect), CGRectGetMaxY(rect) } toLatLngFromView:view]); @@ -2195,26 +2195,26 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) // The world is wrapping if a point just outside the bounds is also within // the rect. mbgl::LatLng outsideLatLng; - if (bounds.sw.longitude > -180) + if (bounds.west() > -180) { outsideLatLng = { - (bounds.sw.latitude + bounds.ne.latitude) / 2, - bounds.sw.longitude - 1, + (bounds.south() + bounds.north()) / 2, + bounds.west() - 1, }; } - else if (bounds.ne.longitude < 180) + else if (bounds.east() < 180) { outsideLatLng = { - (bounds.sw.latitude + bounds.ne.latitude) / 2, - bounds.ne.longitude + 1, + (bounds.south() + bounds.north()) / 2, + bounds.east() + 1, }; } // If the world is wrapping, extend the bounds to cover all longitudes. if (CGRectContainsPoint(rect, [self convertLatLng:outsideLatLng toPointToView:view])) { - bounds.sw.longitude = -180; - bounds.ne.longitude = 180; + bounds.extend(mbgl::LatLng(bounds.south(), -180)); + bounds.extend(mbgl::LatLng(bounds.south(), 180)); } return bounds; @@ -2965,7 +2965,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) { if ( ! annotations || ! annotations.count) return; - mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable(); + mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); for (id <MGLAnnotation> annotation in annotations) { diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 96144d964f..3a92c1901d 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -2180,8 +2180,8 @@ public: /// Converts a geographic bounding box to a rectangle in the view’s coordinate /// system. - (NSRect)convertLatLngBounds:(mbgl::LatLngBounds)bounds toRectToView:(nullable NSView *)view { - NSRect rect = { [self convertLatLng:bounds.sw toPointToView:view], NSZeroSize }; - rect = MGLExtendRect(rect, [self convertLatLng:bounds.ne toPointToView:view]); + NSRect rect = { [self convertLatLng:bounds.southwest() toPointToView:view], NSZeroSize }; + rect = MGLExtendRect(rect, [self convertLatLng:bounds.northeast() toPointToView:view]); return rect; } @@ -2192,7 +2192,7 @@ public: /// Converts a rectangle in the given view’s coordinate system to a geographic /// bounding box. - (mbgl::LatLngBounds)convertRect:(NSRect)rect toLatLngBoundsFromView:(nullable NSView *)view { - mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable(); + mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); bounds.extend([self convertPoint:rect.origin toLatLngFromView:view]); bounds.extend([self convertPoint:{ NSMaxX(rect), NSMinY(rect) } toLatLngFromView:view]); bounds.extend([self convertPoint:{ NSMaxX(rect), NSMaxY(rect) } toLatLngFromView:view]); @@ -2201,22 +2201,22 @@ public: // The world is wrapping if a point just outside the bounds is also within // the rect. mbgl::LatLng outsideLatLng; - if (bounds.sw.longitude > -180) { + if (bounds.west() > -180) { outsideLatLng = { - (bounds.sw.latitude + bounds.ne.latitude) / 2, - bounds.sw.longitude - 1, + (bounds.south() + bounds.north()) / 2, + bounds.west() - 1, }; - } else if (bounds.ne.longitude < 180) { + } else if (bounds.northeast().longitude < 180) { outsideLatLng = { - (bounds.sw.latitude + bounds.ne.latitude) / 2, - bounds.ne.longitude + 1, + (bounds.south() + bounds.north()) / 2, + bounds.east() + 1, }; } // If the world is wrapping, extend the bounds to cover all longitudes. if (NSPointInRect([self convertLatLng:outsideLatLng toPointToView:view], rect)) { - bounds.sw.longitude = -180; - bounds.ne.longitude = 180; + bounds.extend(mbgl::LatLng(bounds.south(), -180)); + bounds.extend(mbgl::LatLng(bounds.south(), 180)); } return bounds; |