From 78126f3b6b303febe4a0de2a08509816e75bbf21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Thu, 2 Jul 2015 12:21:49 -0700 Subject: [PATCH] Refactored -[MGLMapView direction] Fixed a bug in which -[MGLMapView direction] could return 360 instead of 0. Switched to mbgl::util::wrap() for clarity. -updateCompass now relies on -direction to avoid code duplication. --- platform/ios/MGLMapView.mm | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index cd6ab6ad9..d0739e401 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -15,6 +15,7 @@ #include #include #include +#include #include #import "MapboxGL.h" @@ -1568,12 +1569,7 @@ mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBounds coord - (CLLocationDirection)direction { - double direction = _mbglMap->getBearing(); - - while (direction > 360) direction -= 360; - while (direction < 0) direction += 360; - - return direction; + return mbgl::util::wrap(_mbglMap->getBearing(), 0., 360.); } - (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated @@ -2624,9 +2620,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng) - (void)updateCompass { - double degrees = _mbglMap->getBearing() * -1; - while (degrees >= 360) degrees -= 360; - while (degrees < 0) degrees += 360; + CLLocationDirection degrees = -self.direction; self.compassView.transform = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(degrees));