From d790132eda070c652b1d3a6ac44dc5d7e66335f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sun, 20 Nov 2016 01:28:01 -0800 Subject: [ios, macos] Short-circuit redundant camera changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid canceling transitions (and triggering preexisting completion handlers) until we get a chance to ensure that a new transition really does have to begin. Consistently avoid mbgl transitions for redundant camera changes. Upon bailing, schedule the completion handler to run asynchronously on a delay equivalent to the requested animation duration. Added a “functional” equality method to MGLMapCamera that avoids trivial differences. Fixed invocations of XCTAssertEqualWithAccuracy() that incorrectly expressed the accuracy as a number of digits rather than a scalar tolerance. --- platform/darwin/src/MGLMapCamera.mm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'platform/darwin/src/MGLMapCamera.mm') diff --git a/platform/darwin/src/MGLMapCamera.mm b/platform/darwin/src/MGLMapCamera.mm index fafbefd17a..897abab780 100644 --- a/platform/darwin/src/MGLMapCamera.mm +++ b/platform/darwin/src/MGLMapCamera.mm @@ -2,6 +2,11 @@ #include +BOOL MGLEqualFloatWithAccuracy(CGFloat left, CGFloat right, CGFloat accuracy) +{ + return MAX(left, right) - MIN(left, right) <= accuracy; +} + @implementation MGLMapCamera + (BOOL)supportsSecureCoding @@ -116,6 +121,20 @@ && _pitch == otherCamera.pitch && _heading == otherCamera.heading); } +- (BOOL)isEqualToMapCamera:(MGLMapCamera *)otherCamera +{ + if (otherCamera == self) + { + return YES; + } + + return (MGLEqualFloatWithAccuracy(_centerCoordinate.latitude, otherCamera.centerCoordinate.latitude, 1e-6) + && MGLEqualFloatWithAccuracy(_centerCoordinate.longitude, otherCamera.centerCoordinate.longitude, 1e-6) + && MGLEqualFloatWithAccuracy(_altitude, otherCamera.altitude, 1e-6) + && MGLEqualFloatWithAccuracy(_pitch, otherCamera.pitch, 1) + && MGLEqualFloatWithAccuracy(_heading, otherCamera.heading, 1)); +} + - (NSUInteger)hash { return (@(_centerCoordinate.latitude).hash + @(_centerCoordinate.longitude).hash -- cgit v1.2.1