diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-05-17 16:50:17 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2018-05-18 10:55:44 -0400 |
commit | 816108a6af5ada3abaa825113f51b25cf8715853 (patch) | |
tree | 29ccf6f73cd43148dd3ef9d87ff9b427e49fed51 | |
parent | be6e40eb683082cb0f3c330179ed59c92a9398aa (diff) | |
download | qtlocation-mapboxgl-upstream/jrex-11609-convertCoordinateBounds-antimeridian.tar.gz |
Switched to MGLLocationCoordinate2DIsValid for MGLMapView conversion methodsupstream/jrex-11609-convertCoordinateBounds-antimeridian
Added antimeridian tests
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 4 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewConversionTests.mm | 98 |
3 files changed, 104 insertions, 2 deletions
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 78cfff965c..eb408bc578 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -363,6 +363,7 @@ AC518E00201BB55A00EBC820 /* MGLTelemetryConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */; }; AC518E03201BB56000EBC820 /* MGLTelemetryConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */; }; AC518E04201BB56100EBC820 /* MGLTelemetryConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */; }; + CA062D6C20ADDA2C008C36F9 /* MGLMapViewConversionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CA062D6B20ADDA2C008C36F9 /* MGLMapViewConversionTests.mm */; }; CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */; }; CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */; }; CA55CD41202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -996,6 +997,7 @@ 96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationHeadingIndicator.h; sourceTree = "<group>"; }; AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLTelemetryConfig.h; sourceTree = "<group>"; }; AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLTelemetryConfig.m; sourceTree = "<group>"; }; + CA062D6B20ADDA2C008C36F9 /* MGLMapViewConversionTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLMapViewConversionTests.mm; sourceTree = "<group>"; }; CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewIntegrationTest.m; sourceTree = "<group>"; }; CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLMapViewIntegrationTest.h; sourceTree = "<group>"; }; CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLStyleLayerIntegrationTests.m; sourceTree = "<group>"; }; @@ -1825,6 +1827,7 @@ DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */, DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */, DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */, + CA062D6B20ADDA2C008C36F9 /* MGLMapViewConversionTests.mm */, 16376B481FFEED010000563E /* MGLMapViewLayoutTests.m */, 9658C154204761FC00D8A674 /* MGLMapViewScaleBarTests.m */, 35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */, @@ -2854,6 +2857,7 @@ 357579801D501E09000B822E /* MGLFillStyleLayerTests.mm in Sources */, 35D9DDE21DA25EEC00DAAD69 /* MGLCodingTests.m in Sources */, DA1F8F3D1EBD287B00367E42 /* MGLDocumentationGuideTests.swift in Sources */, + CA062D6C20ADDA2C008C36F9 /* MGLMapViewConversionTests.mm in Sources */, 3598544D1E1D38AA00B29F84 /* MGLDistanceFormatterTests.m in Sources */, 071BBB071EE77631001FB02A /* MGLImageSourceTests.m in Sources */, DA2DBBCE1D51E80400D38FF9 /* MGLStyleLayerTests.m in Sources */, diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 26b23abb4e..536f3cfdb0 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3410,7 +3410,7 @@ public: - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view { - if ( ! CLLocationCoordinate2DIsValid(coordinate)) + if ( ! MGLLocationCoordinate2DIsValid(coordinate)) { return CGPointMake(NAN, NAN); } @@ -3431,7 +3431,7 @@ public: - (CGRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable UIView *)view { - if ( ! CLLocationCoordinate2DIsValid(bounds.sw) || ! CLLocationCoordinate2DIsValid(bounds.ne)) + if ( ! MGLLocationCoordinate2DIsValid(bounds.sw) || ! MGLLocationCoordinate2DIsValid(bounds.ne)) { return CGRectNull; } diff --git a/platform/ios/test/MGLMapViewConversionTests.mm b/platform/ios/test/MGLMapViewConversionTests.mm new file mode 100644 index 0000000000..1f97583e26 --- /dev/null +++ b/platform/ios/test/MGLMapViewConversionTests.mm @@ -0,0 +1,98 @@ +#import <Mapbox/Mapbox.h> +#import <XCTest/XCTest.h> +#import "../../darwin/src/MGLGeometry_Private.h" + + +@interface MGLMapViewConversionTests : XCTestCase +@property (nonatomic) MGLMapView *mapView; +@end + +@implementation MGLMapViewConversionTests + +- (void)setUp { + [super setUp]; + self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds]; +} + +- (void)testConvertCoordinateBounds { + // Test for https://github.com/mapbox/mapbox-gl-native/issues/11609 + + CGSize viewSize = self.mapView.bounds.size; + CGFloat epsilon = 0.00001; + + MGLCoordinateBounds testBounds[] = { + {{ 35.68476,-220.24257 }, { 37.78428,-122.41310 }}, // Tokyo -> SF + {{ -34.88593094075315, 123.04687499999999 }, { 65.94647177615738, 269.296875} }, + {{ -85.051128627918402,-212.45777702685075}, { 85.051128627917535,-10.058978406935694 }} + }; + + // CLLocationCoordinate2DIsValid states: a coordinate is invalid IF: + // - Its latitude is greater than 90 degrees or less than -90 degrees. + // - Its longitude is greater than 180 degrees or less than -180 degrees. + // + // So we use MGLLocationCoordinate2DIsValid in the conversion methods that + // is a little more lenient. + + for (NSInteger test = 0; test < sizeof(testBounds)/sizeof(testBounds[0]); test++) { + + MGLCoordinateBounds bounds = testBounds[test]; + +#define ASSERT_REASON @"Unexpected result for test %ld",test + + // 0. Parameter check + XCTAssert(MGLLocationCoordinate2DIsValid(bounds.sw), ASSERT_REASON); + XCTAssert(MGLLocationCoordinate2DIsValid(bounds.ne), ASSERT_REASON); + XCTAssert(bounds.sw.longitude < bounds.ne.longitude, ASSERT_REASON); + XCTAssert(bounds.sw.latitude < bounds.ne.latitude, ASSERT_REASON); + + // Set visible bounds + [self.mapView setVisibleCoordinateBounds:bounds animated:NO]; + MGLCoordinateBounds visibleBounds = self.mapView.visibleCoordinateBounds; + + + // 1. Check the visible bounds + // Given shape of device, visible bounds should be larger (extending latitude) + // than the source. + XCTAssert(visibleBounds.ne.latitude >= bounds.ne.latitude-epsilon, ASSERT_REASON); + XCTAssert(visibleBounds.sw.latitude <= bounds.sw.latitude+epsilon, ASSERT_REASON); + XCTAssertEqualWithAccuracy(visibleBounds.ne.longitude, visibleBounds.ne.longitude, 0.00001, ASSERT_REASON); + XCTAssertEqualWithAccuracy(visibleBounds.sw.longitude, visibleBounds.sw.longitude, 0.00001, ASSERT_REASON); + + // 2. Check the individual points + CGPoint west = [self.mapView convertCoordinate:bounds.sw toPointToView:self.mapView]; + XCTAssertEqualWithAccuracy(west.x, 0.0, epsilon, ASSERT_REASON); + XCTAssert(west.y > -epsilon, ASSERT_REASON); + XCTAssert(west.y < viewSize.height+epsilon, ASSERT_REASON); + + CGPoint east = [self.mapView convertCoordinate:bounds.ne toPointToView:self.mapView]; + XCTAssertEqualWithAccuracy(east.x, viewSize.width, epsilon, ASSERT_REASON); + XCTAssert(east.y > -epsilon, ASSERT_REASON); + XCTAssert(east.y < viewSize.height+epsilon, ASSERT_REASON); + + // 3. Now check the bounds + CGRect rect = [self.mapView convertCoordinateBounds:bounds + toRectToView:self.mapView]; + + XCTAssertFalse(CGRectEqualToRect(rect, CGRectNull), ASSERT_REASON); + + // Check individual properties + XCTAssertFalse(rect.origin.x == INFINITY, ASSERT_REASON); + XCTAssertFalse(rect.origin.y == INFINITY, ASSERT_REASON); + XCTAssertFalse(rect.size.width == 0, ASSERT_REASON); + XCTAssertFalse(rect.size.height == 0, ASSERT_REASON); + + // Is the rect returned, roughly where we'd expect it? (left and right edges + // aligned with the view's) + XCTAssertEqualWithAccuracy(rect.origin.x, 0.0, epsilon, ASSERT_REASON); + XCTAssert(rect.origin.y > -epsilon, ASSERT_REASON); + XCTAssert(rect.origin.y < viewSize.height+epsilon, ASSERT_REASON); + + XCTAssertEqualWithAccuracy(rect.origin.x + rect.size.width, viewSize.width, epsilon, ASSERT_REASON); + XCTAssert(rect.size.height > -epsilon, ASSERT_REASON); + XCTAssert(rect.size.height < viewSize.height+epsilon, ASSERT_REASON); + +#undef ASSERT_REASON + } +} + +@end |