diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-02-21 22:47:15 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-02-21 22:47:15 -0800 |
commit | 2f388d663505255e967597c52656cc076e20d95c (patch) | |
tree | 157ec4c96a5d6f7c67367f96b73957870ee78edb /platform/darwin/src | |
parent | b512af6a6682bf133d8d580cccb309f671f287f6 (diff) | |
parent | df6a06bd07bda3207b31d86dd66a7468cc33c440 (diff) | |
download | qtlocation-mapboxgl-2f388d663505255e967597c52656cc076e20d95c.tar.gz |
Merge branch 'release-ios-v3.4.0' into 1ec5-release-ios-v3.4.2
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLMapCamera.h | 14 | ||||
-rw-r--r-- | platform/darwin/src/MGLMapCamera.mm | 19 |
2 files changed, 33 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLMapCamera.h b/platform/darwin/src/MGLMapCamera.h index a76405df6f..7ce5927d1d 100644 --- a/platform/darwin/src/MGLMapCamera.h +++ b/platform/darwin/src/MGLMapCamera.h @@ -67,6 +67,20 @@ MGL_EXPORT pitch:(CGFloat)pitch heading:(CLLocationDirection)heading; +/** + Returns a Boolean value indicating whether the given camera is functionally + equivalent to the receiver. + + Unlike `-isEqual:`, this method returns `YES` if the difference between the + coordinates, altitudes, pitches, or headings of the two camera objects is + negligible. + + @param otherCamera The camera with which to compare the receiver. + @return A Boolean value indicating whether the two cameras are functionally + equivalent. + */ +- (BOOL)isEqualToMapCamera:(MGLMapCamera *)otherCamera; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLMapCamera.mm b/platform/darwin/src/MGLMapCamera.mm index 260ea31bbd..613124da66 100644 --- a/platform/darwin/src/MGLMapCamera.mm +++ b/platform/darwin/src/MGLMapCamera.mm @@ -2,6 +2,11 @@ #include <mbgl/util/projection.hpp> +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 |