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/osx/src/MGLMapView.mm | |
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/osx/src/MGLMapView.mm')
-rw-r--r-- | platform/osx/src/MGLMapView.mm | 22 |
1 files changed, 11 insertions, 11 deletions
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; |