Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
refs #5983: abstract reusable convenience converter
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Aug 17, 2016
1 parent 3c28a22 commit 8e7cced
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
10 changes: 10 additions & 0 deletions platform/darwin/src/MGLGeometry_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ NS_INLINE mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBo
MGLLatLngFromLocationCoordinate2D(coordinateBounds.ne));
}

NS_INLINE CLLocationCoordinate2D* MGLLocationCoordinatesFromCoordinateBounds(MGLCoordinateBounds coordinateBounds) {
CLLocationCoordinate2D coordinates[] = {
{coordinateBounds.ne.latitude, coordinateBounds.sw.longitude},
coordinateBounds.sw,
{coordinateBounds.sw.latitude, coordinateBounds.ne.longitude},
coordinateBounds.ne,
};
return coordinates;
}

#if TARGET_OS_IPHONE
NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(UIEdgeInsets insets) {
return { insets.top, insets.left, insets.bottom, insets.right };
Expand Down
23 changes: 5 additions & 18 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2340,12 +2340,8 @@ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEd
edgePadding:insets
direction:self.direction]) return;

CLLocationCoordinate2D coordinates[] = {
{bounds.ne.latitude, bounds.sw.longitude},
bounds.sw,
{bounds.sw.latitude, bounds.ne.longitude},
bounds.ne,
};
CLLocationCoordinate2D *coordinates = MGLLocationCoordinatesFromCoordinateBounds(bounds);

[self setVisibleCoordinates:coordinates
count:sizeof(coordinates) / sizeof(coordinates[0])
edgePadding:insets
Expand All @@ -2358,12 +2354,8 @@ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEd
edgePadding:insets
direction:direction]) return;

CLLocationCoordinate2D coordinates[] = {
{bounds.ne.latitude, bounds.sw.longitude},
bounds.sw,
{bounds.sw.latitude, bounds.ne.longitude},
bounds.ne,
};
CLLocationCoordinate2D *coordinates = MGLLocationCoordinatesFromCoordinateBounds(bounds);

[self setVisibleCoordinates:coordinates
count:sizeof(coordinates) / sizeof(coordinates[0])
edgePadding:insets
Expand Down Expand Up @@ -2792,12 +2784,7 @@ - (BOOL)viewportWouldChangeWithCenterCoordinate:(CLLocationCoordinate2D)centerCo

- (BOOL)viewportWouldChangeWithVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction
{
CLLocationCoordinate2D coordinates[] = {
{bounds.ne.latitude, bounds.sw.longitude},
bounds.sw,
{bounds.sw.latitude, bounds.ne.longitude},
bounds.ne,
};
CLLocationCoordinate2D *coordinates = MGLLocationCoordinatesFromCoordinateBounds(bounds);

const mbgl::CameraOptions cameraOptions = [self cameraOptionsForVisibleCoordinates:coordinates
count:sizeof(coordinates) / sizeof(coordinates[0])
Expand Down

0 comments on commit 8e7cced

Please sign in to comment.