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/darwin | |
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/darwin')
-rw-r--r-- | platform/darwin/MGLGeometry_Private.h | 8 | ||||
-rw-r--r-- | platform/darwin/MGLMultiPoint.mm | 21 |
2 files changed, 12 insertions, 17 deletions
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 { |