diff --git a/.circleci/config.yml b/.circleci/config.yml index ef8efdcef..8c5a681dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,6 +68,12 @@ jobs: iOS: type: string default: "12.1" + watchOS: + type: string + default: "5.0" + tvOS: + type: string + default: "12.0" test: type: boolean default: true @@ -101,9 +107,19 @@ jobs: condition: << parameters.codecoverage >> steps: - publish-codecov + - run: + name: tvOS + command: xcodebuild -project MapboxDirections.xcodeproj -scheme 'MapboxDirections tvOS' -destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p),OS=<< parameters.tvOS >>' clean build <<# parameters.test >>test <> <<# parameters.codecoverage >>-enableCodeCoverage YES<> + - when: + condition: << parameters.codecoverage >> + steps: + - publish-codecov - run: name: macOS command: xcodebuild -project MapboxDirections.xcodeproj -scheme 'MapboxDirections Mac' clean build<<# parameters.test >> test <><<# parameters.codecoverage >>-enableCodeCoverage YES<> + - run: + name: watchOS + command: xcodebuild -project MapboxDirections.xcodeproj -scheme 'MapboxDirections watchOS' -destination 'platform=watchOS Simulator,name=Apple Watch Series 5 - 44mm,OS=<< parameters.watchOS >>' clean build - save-cache workflows: @@ -113,11 +129,17 @@ workflows: name: "Xcode_12.1" xcode: "12.0.0" iOS: "14.0" + tvOS: "14.0" + watchOS: "7.0" - build-job: name: "Xcode_11.1" xcode: "11.1.0" iOS: "13.1" + tvOS: "13.0" + watchOS: "6.0" codecoverage: true - spm-job: name: "SPM_build" xcode: "12.0.0" + - spm-linux-job: + name: "SPM_Ubuntu_build" diff --git a/CHANGELOG.md b/CHANGELOG.md index 281adedad..082d13b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,7 @@ ## main * To gain access to the Mapbox Directions and Map Matching APIs, set `MBXAccessToken` in your Info.plist. `MGLMapboxAccessToken` is still supported but is now deprecated. ([#522](https://github.com/mapbox/mapbox-directions-swift/pull/522)) -* This library requires Turf v2.0.0-alpha.2. ([#517](https://github.com/mapbox/mapbox-directions-swift/pull/517)) -* This library does not support tvOS, watchOS, or Linux. Support for these platforms will be restored before the final release. ([#517](https://github.com/mapbox/mapbox-directions-swift/pull/517)) +* This library requires Turf v2.0.0-alpha.3. ([#525](https://github.com/mapbox/mapbox-directions-swift/pull/525)) * The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519)) ## v1.2.0 diff --git a/Cartfile b/Cartfile index b857cd721..a0efe614d 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,3 @@ github "raphaelmor/Polyline" ~> 5.0 -github "mapbox/turf-swift" "v2.0.0-alpha.2" +github "mapbox/turf-swift" "v2.0.0-alpha.3" github "Udumft/SwiftCLI" "carthage-fix" diff --git a/Cartfile.resolved b/Cartfile.resolved index 71758dbb9..83330e8c6 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -2,5 +2,5 @@ binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "5.9.0" github "AliSoftware/OHHTTPStubs" "9.1.0" github "Udumft/SwiftCLI" "da19d2a16cd5aa838d8fb7256e28c171bc67dd82" github "mapbox/mapbox-events-ios" "v0.10.7" -github "mapbox/turf-swift" "v2.0.0-alpha.2" +github "mapbox/turf-swift" "v2.0.0-alpha.3" github "raphaelmor/Polyline" "v5.0.2" diff --git a/MapboxDirections.podspec b/MapboxDirections.podspec index d4bb377eb..9d32d598d 100644 --- a/MapboxDirections.podspec +++ b/MapboxDirections.podspec @@ -27,6 +27,8 @@ Pod::Spec.new do |s| # When using multiple platforms s.ios.deployment_target = "10.0" s.osx.deployment_target = "10.12" + s.watchos.deployment_target = "3.0" + s.tvos.deployment_target = "10.0" # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # @@ -44,6 +46,6 @@ Pod::Spec.new do |s| s.swift_version = "5.0" s.dependency "Polyline", "~> 5.0" - s.dependency "Turf", "~> 2.0.0-alpha.2" + s.dependency "Turf", "~> 2.0.0-alpha.3" end diff --git a/Package.resolved b/Package.resolved index b0fb876d7..f409f9e53 100644 --- a/Package.resolved +++ b/Package.resolved @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/mapbox/turf-swift.git", "state": { "branch": null, - "revision": "d347d3651823422bd7b645d8691f3816e26cac73", - "version": "2.0.0-alpha.2" + "revision": "23e72d4174eacd76cc6414f063b427d2dac81cfb", + "version": "2.0.0-alpha.3" } } ] diff --git a/Package.swift b/Package.swift index d67a27802..14b4212f6 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ import PackageDescription let package = Package( name: "MapboxDirections", platforms: [ - .macOS(.v10_12), .iOS(.v10), + .macOS(.v10_12), .iOS(.v10), .watchOS(.v3), .tvOS(.v12) ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. @@ -21,7 +21,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/raphaelmor/Polyline.git", from: "5.0.2"), - .package(name: "Turf", url: "https://github.com/mapbox/turf-swift.git", from: "2.0.0-alpha.2"), + .package(name: "Turf", url: "https://github.com/mapbox/turf-swift.git", from: "2.0.0-alpha.3"), .package(url: "https://github.com/jakeheis/SwiftCLI", from: "6.0.0") ], targets: [ diff --git a/Sources/MapboxDirections/DirectionsResult.swift b/Sources/MapboxDirections/DirectionsResult.swift index eb5a48802..f5942c50f 100644 --- a/Sources/MapboxDirections/DirectionsResult.swift +++ b/Sources/MapboxDirections/DirectionsResult.swift @@ -1,8 +1,5 @@ import Foundation import Polyline -#if canImport(CoreLocation) -import CoreLocation -#endif import Turf /** @@ -24,7 +21,7 @@ open class DirectionsResult: Codable { // MARK: Creating a Directions Result - init(legs: [RouteLeg], shape: LineString?, distance: CLLocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil) { + init(legs: [RouteLeg], shape: LineString?, distance: Turf.LocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil) { self.legs = legs self.shape = shape self.distance = distance @@ -50,7 +47,7 @@ open class DirectionsResult: Codable { throw DirectionsCodingError.missingOptions } - distance = try container.decode(CLLocationDistance.self, forKey: .distance) + distance = try container.decode(Turf.LocationDistance.self, forKey: .distance) expectedTravelTime = try container.decode(TimeInterval.self, forKey: .expectedTravelTime) typicalTravelTime = try container.decodeIfPresent(TimeInterval.self, forKey: .typicalTravelTime) @@ -134,7 +131,7 @@ open class DirectionsResult: Codable { The value of this property accounts for the distance that the user must travel to traverse the path of the route. It is the sum of the `distance` properties of the route’s legs, not the sum of the direct distances between the route’s waypoints. You should not assume that the user would travel along this distance at a fixed speed. */ - public let distance: CLLocationDistance + public let distance: Turf.LocationDistance /** The route’s expected travel time, measured in seconds. diff --git a/Sources/MapboxDirections/Extensions/Codable.swift b/Sources/MapboxDirections/Extensions/Codable.swift index 80360b3dc..6ed7afa0e 100644 --- a/Sources/MapboxDirections/Extensions/Codable.swift +++ b/Sources/MapboxDirections/Extensions/Codable.swift @@ -1,9 +1,11 @@ import Foundation -import Polyline -import Turf +import func Polyline.encodeCoordinates #if canImport(CoreLocation) -import CoreLocation +import typealias Polyline.LocationCoordinate2D +#else +import struct Polyline.LocationCoordinate2D #endif +import Turf extension LineString { /** @@ -11,10 +13,11 @@ extension LineString { */ func polylineEncodedString(precision: Double = 1e5) -> String { #if canImport(CoreLocation) - return encodeCoordinates(coordinates, precision: precision) + let coordinates = self.coordinates #else - return encodeCoordinates(coordinates.map { LocationCoordinate2D($0) }, precision: precision) + let coordinates = self.coordinates.map { Polyline.LocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude) } #endif + return encodeCoordinates(coordinates, precision: precision) } } @@ -45,7 +48,7 @@ extension PolyLineString: Codable { switch options?.shapeFormat ?? .default { case .geoJSON: let lineStringContainer = try decoder.container(keyedBy: LineStringCodingKeys.self) - let coordinates = try lineStringContainer.decode([CLLocationCoordinate2DCodable].self, forKey: .coordinates).map { $0.decodedCoordinates } + let coordinates = try lineStringContainer.decode([LocationCoordinate2DCodable].self, forKey: .coordinates).map { $0.decodedCoordinates } self = .lineString(LineString(coordinates)) case .polyline, .polyline6: let precision = options?.shapeFormat == .polyline6 ? 1e6 : 1e5 @@ -59,19 +62,18 @@ extension PolyLineString: Codable { switch self { case let .lineString(lineString): var lineStringContainer = encoder.container(keyedBy: LineStringCodingKeys.self) - try lineStringContainer.encode(lineString.coordinates.map { CLLocationCoordinate2DCodable($0) }, forKey: .coordinates) + try lineStringContainer.encode(lineString.coordinates.map { LocationCoordinate2DCodable($0) }, forKey: .coordinates) case let .polyline(encodedPolyline, precision: _): try container.encode(encodedPolyline) } } } -struct CLLocationCoordinate2DCodable: Codable { - var latitude: CLLocationDegrees - var longitude: CLLocationDegrees - var decodedCoordinates: CLLocationCoordinate2D { - return CLLocationCoordinate2D(latitude: latitude, - longitude: longitude) +struct LocationCoordinate2DCodable: Codable { + var latitude: Turf.LocationDegrees + var longitude: Turf.LocationDegrees + var decodedCoordinates: Turf.LocationCoordinate2D { + return Turf.LocationCoordinate2D(latitude: latitude, longitude: longitude) } func encode(to encoder: Encoder) throws { @@ -82,18 +84,12 @@ struct CLLocationCoordinate2DCodable: Codable { init(from decoder: Decoder) throws { var container = try decoder.unkeyedContainer() - longitude = try container.decode(CLLocationDegrees.self) - latitude = try container.decode(CLLocationDegrees.self) + longitude = try container.decode(Turf.LocationDegrees.self) + latitude = try container.decode(Turf.LocationDegrees.self) } - init(_ coordinate: CLLocationCoordinate2D) { + init(_ coordinate: Turf.LocationCoordinate2D) { latitude = coordinate.latitude longitude = coordinate.longitude } } - -extension CLLocationCoordinate2D { - var codableCoordinates: CLLocationCoordinate2DCodable { - return CLLocationCoordinate2DCodable(self) - } -} diff --git a/Sources/MapboxDirections/Extensions/CoreLocation.swift b/Sources/MapboxDirections/Extensions/CoreLocation.swift index f0e7d1606..9cd6513ee 100644 --- a/Sources/MapboxDirections/Extensions/CoreLocation.swift +++ b/Sources/MapboxDirections/Extensions/CoreLocation.swift @@ -1,10 +1,9 @@ import Foundation #if canImport(CoreLocation) import CoreLocation -#else -import Turf -import Polyline #endif +import Turf + #if canImport(CoreLocation) /** @@ -30,34 +29,10 @@ public typealias LocationSpeed = Double The accuracy of a geographical coordinate. */ public typealias LocationAccuracy = Double - -extension CLLocationCoordinate2D { - init(_ locationCoordinate2D: LocationCoordinate2D) { - self.init(latitude: locationCoordinate2D.latitude, longitude: locationCoordinate2D.longitude) - } -} - -extension LocationCoordinate2D { - init(_ clLocationCoordinate2D: CLLocationCoordinate2D) { - self.init(latitude: clLocationCoordinate2D.latitude, longitude: clLocationCoordinate2D.longitude) - } -} #endif -extension CLLocationCoordinate2D { +extension LocationCoordinate2D { internal var requestDescription: String { return "\(longitude.rounded(to: 1e6)),\(latitude.rounded(to: 1e6))" } } - -#if canImport(CoreLocation) -extension CLLocation { - /** - Initializes a CLLocation object with the given coordinate pair. - */ - internal convenience init(coordinate: CLLocationCoordinate2D) { - self.init(latitude: coordinate.latitude, longitude: coordinate.longitude) - } -} -#endif - diff --git a/Sources/MapboxDirections/Extensions/GeoJSON.swift b/Sources/MapboxDirections/Extensions/GeoJSON.swift index 4fa353cdf..ea47fbd99 100644 --- a/Sources/MapboxDirections/Extensions/GeoJSON.swift +++ b/Sources/MapboxDirections/Extensions/GeoJSON.swift @@ -1,8 +1,10 @@ import Foundation +import func Polyline.decodePolyline #if canImport(CoreLocation) -import CoreLocation +import typealias Polyline.LocationCoordinate2D +#else +import struct Polyline.LocationCoordinate2D #endif -import Polyline import Turf extension BoundingBox: CustomStringConvertible { @@ -22,7 +24,7 @@ extension LineString { } init(encodedPolyline: String, precision: Double) throws { - guard var coordinates = decodePolyline(encodedPolyline, precision: precision) as [LocationCoordinate2D]? else { + guard var coordinates = decodePolyline(encodedPolyline, precision: precision) as [Polyline.LocationCoordinate2D]? else { throw GeometryError.cannotDecodePolyline(precision: precision) } // If the polyline has zero length with both endpoints at the same coordinate, Polyline drops one of the coordinates. @@ -34,7 +36,7 @@ extension LineString { #if canImport(CoreLocation) self.init(coordinates) #else - self.init(coordinates.map { CLLocationCoordinate2D($0) }) + self.init(coordinates.map { Turf.LocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude) }) #endif } } diff --git a/Sources/MapboxDirections/Intersection.swift b/Sources/MapboxDirections/Intersection.swift index ad5569dd2..f5f8ac646 100644 --- a/Sources/MapboxDirections/Intersection.swift +++ b/Sources/MapboxDirections/Intersection.swift @@ -1,9 +1,5 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif /** A single cross street along a step. @@ -11,8 +7,8 @@ import Turf public struct Intersection { // MARK: Creating an Intersection - public init(location: CLLocationCoordinate2D, - headings: [CLLocationDirection], + public init(location: LocationCoordinate2D, + headings: [LocationDirection], approachIndex: Int, outletIndex: Int, outletIndexes: IndexSet, @@ -46,18 +42,18 @@ public struct Intersection { /** The geographic coordinates at the center of the intersection. */ - public let location: CLLocationCoordinate2D + public let location: LocationCoordinate2D // MARK: Getting the Roads that Meet at the Intersection /** - An array of `CLLocationDirection`s indicating the absolute headings of the roads that meet at the intersection. + An array of `LocationDirection`s indicating the absolute headings of the roads that meet at the intersection. A road is represented in this array by a heading indicating the direction from which the road meets the intersection. To get the direction of travel when leaving the intersection along the road, rotate the heading 180 degrees. A single road that passes through this intersection is represented by two items in this array: one for the segment that enters the intersection and one for the segment that exits it. */ - public let headings: [CLLocationDirection] + public let headings: [LocationDirection] /** The indices of the items in the `headings` array that correspond to the roads that may be used to leave the intersection. @@ -232,7 +228,7 @@ extension Intersection: Codable { func encode(to encoder: Encoder, administrativeRegionIndex: Int?, geometryIndex: Int?) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(CLLocationCoordinate2DCodable(location), forKey: .location) + try container.encode(LocationCoordinate2DCodable(location), forKey: .location) try container.encode(headings, forKey: .headings) try container.encodeIfPresent(approachIndex, forKey: .approachIndex) @@ -290,8 +286,8 @@ extension Intersection: Codable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - location = try container.decode(CLLocationCoordinate2DCodable.self, forKey: .location).decodedCoordinates - headings = try container.decode([CLLocationDirection].self, forKey: .headings) + location = try container.decode(LocationCoordinate2DCodable.self, forKey: .location).decodedCoordinates + headings = try container.decode([LocationDirection].self, forKey: .headings) if let lanes = try container.decodeIfPresent([Lane].self, forKey: .lanes) { approachLanes = lanes.map { $0.indications } diff --git a/Sources/MapboxDirections/MapMatching/Match.swift b/Sources/MapboxDirections/MapMatching/Match.swift index 089df30ae..e8b4f17b0 100644 --- a/Sources/MapboxDirections/MapMatching/Match.swift +++ b/Sources/MapboxDirections/MapMatching/Match.swift @@ -1,8 +1,4 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#endif -import Polyline import Turf /** @@ -65,7 +61,7 @@ open class Match: DirectionsResult { - parameter confidence: A number between 0 and 1 that indicates the Map Matching API’s confidence that the match is accurate. A higher confidence means the match is more likely to be accurate. - parameter weight: A `Weight` enum, which represents the weight given to a specific `Match`. */ - public init(legs: [RouteLeg], shape: LineString?, distance: CLLocationDistance, expectedTravelTime: TimeInterval, confidence: Float, weight: Weight) { + public init(legs: [RouteLeg], shape: LineString?, distance: LocationDistance, expectedTravelTime: TimeInterval, confidence: Float, weight: Weight) { self.confidence = confidence self.weight = weight super.init(legs: legs, shape: shape, distance: distance, expectedTravelTime: expectedTravelTime) diff --git a/Sources/MapboxDirections/MapMatching/MatchOptions.swift b/Sources/MapboxDirections/MapMatching/MatchOptions.swift index d86d9f90e..ac2a6f61c 100644 --- a/Sources/MapboxDirections/MapMatching/MatchOptions.swift +++ b/Sources/MapboxDirections/MapMatching/MatchOptions.swift @@ -1,9 +1,8 @@ import Foundation #if canImport(CoreLocation) import CoreLocation -#else -import Turf #endif +import Turf /** A `MatchOptions` object is a structure that specifies the criteria for results returned by the Mapbox Map Matching API. @@ -34,7 +33,7 @@ open class MatchOptions: DirectionsOptions { - parameter coordinates: An array of geographic coordinates representing locations to attempt to match against the road network. The array should contain at least two locations (the source and destination) and at most 100 locations. (Some profiles, such as `DirectionsProfileIdentifier.automobileAvoidingTraffic`, [may have lower limits](https://docs.mapbox.com/api/navigation/#directions).) Each coordinate is converted into a `Waypoint` object. - parameter profileIdentifier: A string specifying the primary mode of transportation for the routes. `DirectionsProfileIdentifier.automobile` is used by default. */ - public convenience init(coordinates: [CLLocationCoordinate2D], profileIdentifier: DirectionsProfileIdentifier? = nil) { + public convenience init(coordinates: [LocationCoordinate2D], profileIdentifier: DirectionsProfileIdentifier? = nil) { let waypoints = coordinates.map { Waypoint(coordinate: $0) } diff --git a/Sources/MapboxDirections/MapMatching/Tracepoint.swift b/Sources/MapboxDirections/MapMatching/Tracepoint.swift index 4043f5efa..8d1b4f29f 100644 --- a/Sources/MapboxDirections/MapMatching/Tracepoint.swift +++ b/Sources/MapboxDirections/MapMatching/Tracepoint.swift @@ -1,9 +1,5 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif /** A `Tracepoint` represents a location matched to the road network. @@ -18,7 +14,7 @@ public class Tracepoint: Waypoint { case countOfAlternatives = "alternatives_count" } - init(coordinate: CLLocationCoordinate2D, countOfAlternatives: Int, name: String?) { + init(coordinate: LocationCoordinate2D, countOfAlternatives: Int, name: String?) { self.countOfAlternatives = countOfAlternatives super.init(coordinate: coordinate, name: name) } diff --git a/Sources/MapboxDirections/Route.swift b/Sources/MapboxDirections/Route.swift index ed3030bdb..c0b1bba23 100644 --- a/Sources/MapboxDirections/Route.swift +++ b/Sources/MapboxDirections/Route.swift @@ -1,7 +1,4 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#endif import Turf /** @@ -20,7 +17,7 @@ open class Route: DirectionsResult { - parameter expectedTravelTime: The route’s expected travel time, measured in seconds. - parameter typicalTravelTime: The route’s typical travel time, measured in seconds. */ - public override init(legs: [RouteLeg], shape: LineString?, distance: CLLocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil) { + public override init(legs: [RouteLeg], shape: LineString?, distance: LocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil) { super.init(legs: legs, shape: shape, distance: distance, expectedTravelTime: expectedTravelTime, typicalTravelTime: typicalTravelTime) } diff --git a/Sources/MapboxDirections/RouteLeg.swift b/Sources/MapboxDirections/RouteLeg.swift index d536958e4..9cc359371 100644 --- a/Sources/MapboxDirections/RouteLeg.swift +++ b/Sources/MapboxDirections/RouteLeg.swift @@ -1,7 +1,4 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#endif import Polyline import Turf @@ -36,7 +33,7 @@ open class RouteLeg: Codable { - parameter typicalTravelTime: The route leg’s typical travel time, measured in seconds. - parameter profileIdentifier: The primary mode of transportation for the route leg. */ - public init(steps: [RouteStep], name: String, distance: CLLocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil, profileIdentifier: DirectionsProfileIdentifier) { + public init(steps: [RouteStep], name: String, distance: Turf.LocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil, profileIdentifier: DirectionsProfileIdentifier) { self.steps = steps self.name = name self.distance = distance @@ -61,7 +58,7 @@ open class RouteLeg: Codable { source = try container.decodeIfPresent(Waypoint.self, forKey: .source) destination = try container.decodeIfPresent(Waypoint.self, forKey: .destination) name = try container.decode(String.self, forKey: .name) - distance = try container.decode(CLLocationDistance.self, forKey: .distance) + distance = try container.decode(Turf.LocationDistance.self, forKey: .distance) expectedTravelTime = try container.decode(TimeInterval.self, forKey: .expectedTravelTime) typicalTravelTime = try container.decodeIfPresent(TimeInterval.self, forKey: .typicalTravelTime) @@ -175,7 +172,7 @@ open class RouteLeg: Codable { This property is set if the `RouteOptions.attributeOptions` property contains `AttributeOptions.distance`. */ - open var segmentDistances: [CLLocationDistance]? + open var segmentDistances: [Turf.LocationDistance]? /** An array containing the expected travel time (measured in seconds) between each coordinate in the route leg geometry. @@ -269,7 +266,7 @@ open class RouteLeg: Codable { The value of this property accounts for the distance that the user must travel to arrive at the destination from the source. It is not the direct distance between the source and destination, nor should not assume that the user would travel along this distance at a fixed speed. */ - public let distance: CLLocationDistance + public let distance: Turf.LocationDistance /** The route leg’s expected travel time, measured in seconds. diff --git a/Sources/MapboxDirections/RouteLegAttributes.swift b/Sources/MapboxDirections/RouteLegAttributes.swift index 0f87d6ff4..190eea721 100644 --- a/Sources/MapboxDirections/RouteLegAttributes.swift +++ b/Sources/MapboxDirections/RouteLegAttributes.swift @@ -1,9 +1,5 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif extension RouteLeg { /** @@ -15,7 +11,7 @@ extension RouteLeg { This property is set if the `RouteOptions.attributeOptions` property contains `AttributeOptions.distance`. */ - public var segmentDistances: [CLLocationDistance]? + public var segmentDistances: [LocationDistance]? /** An array containing the expected travel time (measured in seconds) between each coordinate in the route leg geometry. @@ -71,7 +67,7 @@ extension RouteLeg.Attributes: Codable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - segmentDistances = try container.decodeIfPresent([CLLocationDistance].self, forKey: .segmentDistances) + segmentDistances = try container.decodeIfPresent([LocationDistance].self, forKey: .segmentDistances) expectedSegmentTravelTimes = try container.decodeIfPresent([TimeInterval].self, forKey: .expectedSegmentTravelTimes) segmentSpeeds = try container.decodeIfPresent([LocationSpeed].self, forKey: .segmentSpeeds) segmentCongestionLevels = try container.decodeIfPresent([CongestionLevel].self, forKey: .segmentCongestionLevels) diff --git a/Sources/MapboxDirections/RouteOptions.swift b/Sources/MapboxDirections/RouteOptions.swift index 14f64f452..1b8eeb86f 100644 --- a/Sources/MapboxDirections/RouteOptions.swift +++ b/Sources/MapboxDirections/RouteOptions.swift @@ -1,9 +1,8 @@ import Foundation #if canImport(CoreLocation) import CoreLocation -#else -import Turf #endif +import Turf /** A `RouteOptions` object is a structure that specifies the criteria for results returned by the Mapbox Directions API. @@ -46,7 +45,7 @@ open class RouteOptions: DirectionsOptions { - parameter coordinates: An array of geographic coordinates representing locations that the route should visit in chronological order. The array should contain at least two locations (the source and destination) and at most 25 locations. Each coordinate is converted into a `Waypoint` object. - parameter profileIdentifier: A string specifying the primary mode of transportation for the routes. `DirectionsProfileIdentifier.automobile` is used by default. */ - public convenience init(coordinates: [CLLocationCoordinate2D], profileIdentifier: DirectionsProfileIdentifier? = nil) { + public convenience init(coordinates: [LocationCoordinate2D], profileIdentifier: DirectionsProfileIdentifier? = nil) { let waypoints = coordinates.map { Waypoint(coordinate: $0) } self.init(waypoints: waypoints, profileIdentifier: profileIdentifier) } diff --git a/Sources/MapboxDirections/RouteStep.swift b/Sources/MapboxDirections/RouteStep.swift index 1486140c2..e6fafaec0 100644 --- a/Sources/MapboxDirections/RouteStep.swift +++ b/Sources/MapboxDirections/RouteStep.swift @@ -1,7 +1,4 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#endif import Polyline import Turf @@ -460,7 +457,7 @@ open class RouteStep: Codable { - parameter instructionsSpokenAlongStep: Instructions about the next step’s maneuver, optimized for speech synthesis. - parameter instructionsDisplayedAlongStep: Instructions about the next step’s maneuver, optimized for display in real time. */ - public init(transportType: TransportType, maneuverLocation: CLLocationCoordinate2D, maneuverType: ManeuverType, maneuverDirection: ManeuverDirection? = nil, instructions: String, initialHeading: CLLocationDirection? = nil, finalHeading: CLLocationDirection? = nil, drivingSide: DrivingSide, exitCodes: [String]? = nil, exitNames: [String]? = nil, phoneticExitNames: [String]? = nil, distance: CLLocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil, names: [String]? = nil, phoneticNames: [String]? = nil, codes: [String]? = nil, destinationCodes: [String]? = nil, destinations: [String]? = nil, intersections: [Intersection]? = nil, speedLimitSignStandard: SignStandard? = nil, speedLimitUnit: UnitSpeed? = nil, instructionsSpokenAlongStep: [SpokenInstruction]? = nil, instructionsDisplayedAlongStep: [VisualInstructionBanner]? = nil, administrativeAreaContainerByIntersection: [Int?]? = nil, segmentIndicesByIntersection: [Int?]? = nil) { + public init(transportType: TransportType, maneuverLocation: Turf.LocationCoordinate2D, maneuverType: ManeuverType, maneuverDirection: ManeuverDirection? = nil, instructions: String, initialHeading: Turf.LocationDirection? = nil, finalHeading: Turf.LocationDirection? = nil, drivingSide: DrivingSide, exitCodes: [String]? = nil, exitNames: [String]? = nil, phoneticExitNames: [String]? = nil, distance: Turf.LocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil, names: [String]? = nil, phoneticNames: [String]? = nil, codes: [String]? = nil, destinationCodes: [String]? = nil, destinations: [String]? = nil, intersections: [Intersection]? = nil, speedLimitSignStandard: SignStandard? = nil, speedLimitUnit: UnitSpeed? = nil, instructionsSpokenAlongStep: [SpokenInstruction]? = nil, instructionsDisplayedAlongStep: [VisualInstructionBanner]? = nil, administrativeAreaContainerByIntersection: [Int?]? = nil, segmentIndicesByIntersection: [Int?]? = nil) { self.transportType = transportType self.maneuverLocation = maneuverLocation self.maneuverType = maneuverType @@ -534,7 +531,7 @@ open class RouteStep: Codable { try maneuver.encode(instructions, forKey: .instruction) try maneuver.encode(maneuverType, forKey: .type) try maneuver.encodeIfPresent(maneuverDirection, forKey: .direction) - try maneuver.encode(CLLocationCoordinate2DCodable(maneuverLocation), forKey: .location) + try maneuver.encode(LocationCoordinate2DCodable(maneuverLocation), forKey: .location) try maneuver.encodeIfPresent(initialHeading, forKey: .initialHeading) try maneuver.encodeIfPresent(finalHeading, forKey: .finalHeading) @@ -586,12 +583,12 @@ open class RouteStep: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) let maneuver = try container.nestedContainer(keyedBy: ManeuverCodingKeys.self, forKey: .maneuver) - maneuverLocation = try maneuver.decode(CLLocationCoordinate2DCodable.self, forKey: .location).decodedCoordinates + maneuverLocation = try maneuver.decode(LocationCoordinate2DCodable.self, forKey: .location).decodedCoordinates maneuverType = (try? maneuver.decode(ManeuverType.self, forKey: .type)) ?? .default maneuverDirection = try maneuver.decodeIfPresent(ManeuverDirection.self, forKey: .direction) - initialHeading = try maneuver.decodeIfPresent(CLLocationDirection.self, forKey: .initialHeading) - finalHeading = try maneuver.decodeIfPresent(CLLocationDirection.self, forKey: .finalHeading) + initialHeading = try maneuver.decodeIfPresent(Turf.LocationDirection.self, forKey: .initialHeading) + finalHeading = try maneuver.decodeIfPresent(Turf.LocationDirection.self, forKey: .finalHeading) if let polyLineString = try container.decodeIfPresent(PolyLineString.self, forKey: .shape) { shape = try LineString(polyLineString: polyLineString) @@ -618,7 +615,7 @@ open class RouteStep: Codable { } exitIndex = try container.decodeIfPresent(Int.self, forKey: .exitIndex) - distance = try container.decode(CLLocationDirection.self, forKey: .distance) + distance = try container.decode(Turf.LocationDirection.self, forKey: .distance) expectedTravelTime = try container.decode(TimeInterval.self, forKey: .expectedTravelTime) typicalTravelTime = try container.decodeIfPresent(TimeInterval.self, forKey: .typicalTravelTime) @@ -692,7 +689,7 @@ open class RouteStep: Codable { /** The location of the maneuver at the beginning of this step. */ - public let maneuverLocation: CLLocationCoordinate2D + public let maneuverLocation: Turf.LocationCoordinate2D /** The type of maneuver required for beginning this step. @@ -716,14 +713,14 @@ open class RouteStep: Codable { /** The user’s heading immediately before performing the maneuver. */ - public let initialHeading: CLLocationDirection? + public let initialHeading: Turf.LocationDirection? /** The user’s heading immediately after performing the maneuver. The value of this property may differ from the user’s heading after traveling along the road past the maneuver. */ - public let finalHeading: CLLocationDirection? + public let finalHeading: Turf.LocationDirection? /** Indicates what side of a bidirectional road the driver must be driving on. Also referred to as the rule of the road. @@ -773,7 +770,7 @@ open class RouteStep: Codable { The value of this property accounts for the distance that the user must travel to go from this step’s maneuver location to the next step’s maneuver location. It is not the sum of the direct distances between the route’s waypoints, nor should you assume that the user would travel along this distance at a fixed speed. */ - public let distance: CLLocationDistance + public let distance: Turf.LocationDistance /** The step’s expected travel time, measured in seconds. diff --git a/Sources/MapboxDirections/SpokenInstruction.swift b/Sources/MapboxDirections/SpokenInstruction.swift index fee33699a..c886a7e31 100644 --- a/Sources/MapboxDirections/SpokenInstruction.swift +++ b/Sources/MapboxDirections/SpokenInstruction.swift @@ -1,9 +1,5 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif /** An instruction about an upcoming `RouteStep`’s maneuver, optimized for speech synthesis. @@ -28,7 +24,7 @@ open class SpokenInstruction: Codable { - parameter text: A plain-text representation of the speech-optimized instruction. - parameter ssmlText: A formatted representation of the speech-optimized instruction. */ - public init(distanceAlongStep: CLLocationDistance, text: String, ssmlText: String) { + public init(distanceAlongStep: LocationDistance, text: String, ssmlText: String) { self.distanceAlongStep = distanceAlongStep self.text = text self.ssmlText = ssmlText @@ -41,7 +37,7 @@ open class SpokenInstruction: Codable { The distance is measured in meters from the beginning of the associated step. */ - public let distanceAlongStep: CLLocationDistance + public let distanceAlongStep: LocationDistance // MARK: Getting the Instruction to Say diff --git a/Sources/MapboxDirections/VisualInstruction.swift b/Sources/MapboxDirections/VisualInstruction.swift index f98a3b8fd..fe8ca0080 100644 --- a/Sources/MapboxDirections/VisualInstruction.swift +++ b/Sources/MapboxDirections/VisualInstruction.swift @@ -1,9 +1,5 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif /** The contents of a banner that should be displayed as added visual guidance for a route. The banner instructions are children of the steps during which they should be displayed, but they refer to the maneuver in the following step. @@ -22,7 +18,7 @@ open class VisualInstruction: Codable { /** Initializes a new visual instruction banner object that displays the given information. */ - public init(text: String?, maneuverType: ManeuverType?, maneuverDirection: ManeuverDirection?, components: [Component], degrees: CLLocationDegrees? = nil) { + public init(text: String?, maneuverType: ManeuverType?, maneuverDirection: ManeuverDirection?, components: [Component], degrees: LocationDegrees? = nil) { self.text = text self.maneuverType = maneuverType self.maneuverDirection = maneuverDirection @@ -45,7 +41,7 @@ open class VisualInstruction: Codable { maneuverType = try container.decodeIfPresent(ManeuverType.self, forKey: .maneuverType) maneuverDirection = try container.decodeIfPresent(ManeuverDirection.self, forKey: .maneuverDirection) components = try container.decode([Component].self, forKey: .components) - finalHeading = try container.decodeIfPresent(CLLocationDegrees.self, forKey: .finalHeading) + finalHeading = try container.decodeIfPresent(LocationDegrees.self, forKey: .finalHeading) } // MARK: Displaying the Instruction Text @@ -81,7 +77,7 @@ open class VisualInstruction: Codable { This property is only relevant if the `maneuverType` is any of the following values: `ManeuverType.takeRoundabout`, `ManeuverType.takeRotary`, `ManeuverType.turnAtRoundabout`, `ManeuverType.exitRoundabout`, or `ManeuverType.exitRotary`. */ - public var finalHeading: CLLocationDegrees? + public var finalHeading: LocationDegrees? } extension VisualInstruction: Equatable { diff --git a/Sources/MapboxDirections/VisualInstructionBanner.swift b/Sources/MapboxDirections/VisualInstructionBanner.swift index 9fd66a960..9d2b7c4ed 100644 --- a/Sources/MapboxDirections/VisualInstructionBanner.swift +++ b/Sources/MapboxDirections/VisualInstructionBanner.swift @@ -1,9 +1,5 @@ import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif internal extension CodingUserInfoKey { static let drivingSide = CodingUserInfoKey(rawValue: "drivingSide")! @@ -27,7 +23,7 @@ open class VisualInstructionBanner: Codable { /** Initializes a visual instruction banner with the given instructions. */ - public init(distanceAlongStep: CLLocationDistance, primary: VisualInstruction, secondary: VisualInstruction?, tertiary: VisualInstruction?, quaternary: VisualInstruction?, drivingSide: DrivingSide) { + public init(distanceAlongStep: LocationDistance, primary: VisualInstruction, secondary: VisualInstruction?, tertiary: VisualInstruction?, quaternary: VisualInstruction?, drivingSide: DrivingSide) { self.distanceAlongStep = distanceAlongStep primaryInstruction = primary secondaryInstruction = secondary @@ -48,7 +44,7 @@ open class VisualInstructionBanner: Codable { required public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - distanceAlongStep = try container.decode(CLLocationDistance.self, forKey: .distanceAlongStep) + distanceAlongStep = try container.decode(LocationDistance.self, forKey: .distanceAlongStep) primaryInstruction = try container.decode(VisualInstruction.self, forKey: .primaryInstruction) secondaryInstruction = try container.decodeIfPresent(VisualInstruction.self, forKey: .secondaryInstruction) tertiaryInstruction = try container.decodeIfPresent(VisualInstruction.self, forKey: .tertiaryInstruction) @@ -65,7 +61,7 @@ open class VisualInstructionBanner: Codable { /** The distance at which the visual instruction should be shown, measured in meters from the beginning of the step. */ - public let distanceAlongStep: CLLocationDistance + public let distanceAlongStep: LocationDistance // MARK: Getting the Instructions to Display diff --git a/Sources/MapboxDirections/Waypoint.swift b/Sources/MapboxDirections/Waypoint.swift index 8221b4ef0..1833f2d80 100644 --- a/Sources/MapboxDirections/Waypoint.swift +++ b/Sources/MapboxDirections/Waypoint.swift @@ -1,8 +1,7 @@ #if canImport(CoreLocation) import CoreLocation -#else -import Turf #endif +import Turf /** A `Waypoint` object indicates a location along a route. It may be the route’s origin or destination, or it may be another location that the route visits. A waypoint object indicates the location’s geographic location along with other optional information, such as a name or the user’s direction approaching the waypoint. You create a `RouteOptions` object using waypoint objects and also receive waypoint objects in the completion handler of the `Directions.calculate(_:completionHandler:)` method. @@ -24,15 +23,15 @@ public class Waypoint: Codable { required public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - coordinate = try container.decode(CLLocationCoordinate2DCodable.self, forKey: .coordinate).decodedCoordinates + coordinate = try container.decode(LocationCoordinate2DCodable.self, forKey: .coordinate).decodedCoordinates coordinateAccuracy = try container.decodeIfPresent(LocationAccuracy.self, forKey: .coordinateAccuracy) - targetCoordinate = try container.decodeIfPresent(CLLocationCoordinate2DCodable.self, forKey: .targetCoordinate)?.decodedCoordinates + targetCoordinate = try container.decodeIfPresent(LocationCoordinate2DCodable.self, forKey: .targetCoordinate)?.decodedCoordinates - heading = try container.decodeIfPresent(CLLocationDirection.self, forKey: .heading) + heading = try container.decodeIfPresent(LocationDirection.self, forKey: .heading) - headingAccuracy = try container.decodeIfPresent(CLLocationDirection.self, forKey: .headingAccuracy) + headingAccuracy = try container.decodeIfPresent(LocationDirection.self, forKey: .headingAccuracy) if let separates = try container.decodeIfPresent(Bool.self, forKey: .separatesLegs) { separatesLegs = separates @@ -53,9 +52,9 @@ public class Waypoint: Codable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(CLLocationCoordinate2DCodable(coordinate), forKey: .coordinate) + try container.encode(LocationCoordinate2DCodable(coordinate), forKey: .coordinate) try container.encode(coordinateAccuracy, forKey: .coordinateAccuracy) - let targetCoordinateCodable = targetCoordinate != nil ? CLLocationCoordinate2DCodable(targetCoordinate!) : nil + let targetCoordinateCodable = targetCoordinate != nil ? LocationCoordinate2DCodable(targetCoordinate!) : nil try container.encode(targetCoordinateCodable, forKey: .targetCoordinate) try container.encodeIfPresent(heading, forKey: .heading) try container.encodeIfPresent(headingAccuracy, forKey: .headingAccuracy) @@ -73,7 +72,7 @@ public class Waypoint: Codable { It is recommended that the value of this argument be greater than the `horizontalAccuracy` property of a `CLLocation` object obtained from a `CLLocationManager` object. There is a high likelihood that the user may be located some distance away from a navigable road, for instance if the user is currently on a driveway or inside a building. - parameter name: The name of the waypoint. This argument does not affect the route but may help you to distinguish one waypoint from another. */ - public init(coordinate: CLLocationCoordinate2D, coordinateAccuracy: LocationAccuracy? = nil, name: String? = nil) { + public init(coordinate: LocationCoordinate2D, coordinateAccuracy: LocationAccuracy? = nil, name: String? = nil) { self.coordinate = coordinate self.coordinateAccuracy = coordinateAccuracy self.name = name @@ -84,13 +83,13 @@ public class Waypoint: Codable { /** Initializes a new waypoint object with the given `CLLocation` object and an optional heading value and name. - - note: This initializer is intended for `CLLocation` objects created using the `CLLocation.init(latitude:longitude:)` initializer. If you intend to use a `CLLocation` object obtained from a `CLLocationManager` object, consider increasing the `horizontalAccuracy` or set it to a negative value to avoid overfitting, since the `Waypoint` class’s `coordinateAccuracy` property represents the maximum allowed deviation from the waypoint. There is a high likelihood that the user may be located some distance away from a navigable road, for instance if the user is currently on a driveway of inside a building. + - note: This initializer is intended for `CLLocation` objects created using the `CLLocation(latitude:longitude:)` initializer. If you intend to use a `CLLocation` object obtained from a `CLLocationManager` object, consider increasing the `horizontalAccuracy` or set it to a negative value to avoid overfitting, since the `Waypoint` class’s `coordinateAccuracy` property represents the maximum allowed deviation from the waypoint. There is a high likelihood that the user may be located some distance away from a navigable road, for instance if the user is currently on a driveway of inside a building. - parameter location: A `CLLocation` object representing the waypoint’s location. This initializer respects the `CLLocation` class’s `coordinate` and `horizontalAccuracy` properties, converting them into the `coordinate` and `coordinateAccuracy` properties, respectively. - - parameter heading: A `CLLocationDirection` value representing the direction from which the route must approach the waypoint in order to be considered viable. This value is stored in the `headingAccuracy` property. + - parameter heading: A `LocationDirection` value representing the direction from which the route must approach the waypoint in order to be considered viable. This value is stored in the `headingAccuracy` property. - parameter name: The name of the waypoint. This argument does not affect the route but may help you to distinguish one waypoint from another. */ - public init(location: CLLocation, heading: CLLocationDirection? = nil, name: String? = nil) { + public init(location: CLLocation, heading: LocationDirection? = nil, name: String? = nil) { coordinate = location.coordinate coordinateAccuracy = location.horizontalAccuracy if let heading = heading , heading >= 0 { @@ -102,7 +101,7 @@ public class Waypoint: Codable { /** Initializes a new waypoint object with the given `CLLocation` object and an optional `CLHeading` object and name. - - note: This initializer is intended for `CLLocation` objects created using the `CLLocation.init(latitude:longitude:)` initializer. If you intend to use a `CLLocation` object obtained from a `CLLocationManager` object, consider increasing the `horizontalAccuracy` or set it to a negative value to avoid overfitting, since the `Waypoint` class’s `coordinateAccuracy` property represents the maximum allowed deviation from the waypoint. There is a high likelihood that the user may be located some distance away from a navigable road, for instance if the user is currently on a driveway of inside a building. + - note: This initializer is intended for `CLLocation` objects created using the `CLLocation(latitude:longitude:)` initializer. If you intend to use a `CLLocation` object obtained from a `CLLocationManager` object, consider increasing the `horizontalAccuracy` or set it to a negative value to avoid overfitting, since the `Waypoint` class’s `coordinateAccuracy` property represents the maximum allowed deviation from the waypoint. There is a high likelihood that the user may be located some distance away from a navigable road, for instance if the user is currently on a driveway of inside a building. - parameter location: A `CLLocation` object representing the waypoint’s location. This initializer respects the `CLLocation` class’s `coordinate` and `horizontalAccuracy` properties, converting them into the `coordinate` and `coordinateAccuracy` properties, respectively. - parameter heading: A `CLHeading` object representing the direction from which the route must approach the waypoint in order to be considered viable. This initializer respects the `CLHeading` class’s `trueHeading` property or `magneticHeading` property, converting it into the `headingAccuracy` property. @@ -124,7 +123,7 @@ public class Waypoint: Codable { /** The geographic coordinate of the waypoint. */ - public let coordinate: CLLocationCoordinate2D + public let coordinate: LocationCoordinate2D /** The radius of uncertainty for the waypoint, measured in meters. @@ -144,7 +143,7 @@ public class Waypoint: Codable { This property corresponds to the [`waypoint_targets`](https://docs.mapbox.com/api/navigation/#retrieve-directions) query parameter in the Mapbox Directions and Map Matching APIs. */ - public var targetCoordinate: CLLocationCoordinate2D? + public var targetCoordinate: LocationCoordinate2D? // MARK: Getting the Direction of Approach @@ -161,7 +160,7 @@ public class Waypoint: Codable { By default, the value of this property is `nil`, meaning that a route is considered viable regardless of the direction of approach. */ - public var heading: CLLocationDirection? = nil + public var heading: LocationDirection? = nil /** The maximum amount, in degrees, by which a route’s approach to a waypoint may differ from `heading` in either direction in order to be considered viable. @@ -172,7 +171,7 @@ public class Waypoint: Codable { By default, the value of this property is `nil`, meaning that a route is considered viable regardless of the direction of approach. */ - public var headingAccuracy: CLLocationDirection? = nil + public var headingAccuracy: LocationDirection? = nil internal var headingDescription: String { guard let heading = heading, heading >= 0, diff --git a/Tests/MapboxDirectionsTests/DirectionsTests.swift b/Tests/MapboxDirectionsTests/DirectionsTests.swift index c8552fd11..fd2fa09d4 100644 --- a/Tests/MapboxDirectionsTests/DirectionsTests.swift +++ b/Tests/MapboxDirectionsTests/DirectionsTests.swift @@ -4,9 +4,8 @@ import OHHTTPStubs #endif #if canImport(CoreLocation) import CoreLocation -#else -import Turf #endif +import Turf @testable import MapboxDirections let BogusToken = "pk.feedCafeDadeDeadBeef-BadeBede.FadeCafeDadeDeed-BadeBede" @@ -52,7 +51,7 @@ class DirectionsTests: XCTestCase { func testGETRequest() { // Bumps right up against MaximumURLLength - let coordinates = Array(repeating: CLLocationCoordinate2D(latitude: 0, longitude: 0), count: maximumCoordinateCount) + let coordinates = Array(repeating: LocationCoordinate2D(latitude: 0, longitude: 0), count: maximumCoordinateCount) let options = RouteOptions(coordinates: coordinates) let directions = Directions(credentials: BogusCredentials) @@ -69,7 +68,7 @@ class DirectionsTests: XCTestCase { } func testPOSTRequest() { - let coordinates = Array(repeating: CLLocationCoordinate2D(latitude: 0, longitude: 0), count: maximumCoordinateCount + 1) + let coordinates = Array(repeating: LocationCoordinate2D(latitude: 0, longitude: 0), count: maximumCoordinateCount + 1) let options = RouteOptions(coordinates: coordinates) let directions = Directions(credentials: BogusCredentials) @@ -92,8 +91,8 @@ class DirectionsTests: XCTestCase { return HTTPStubsResponse(data: BadResponse.data(using: .utf8)!, statusCode: 413, headers: ["Content-Type" : "text/html"]) } let expectation = self.expectation(description: "Async callback") - let one = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)) - let two = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 2.0, longitude: 2.0)) + let one = CLLocation(latitude: 0.0, longitude: 0.0) + let two = CLLocation(latitude: 2.0, longitude: 2.0) let directions = Directions(credentials: BogusCredentials) let opts = RouteOptions(locations: [one, two]) @@ -118,8 +117,8 @@ class DirectionsTests: XCTestCase { return HTTPStubsResponse(data: message.data(using: .utf8)!, statusCode: 420, headers: ["Content-Type" : "text/plain"]) } let expectation = self.expectation(description: "Async callback") - let one = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)) - let two = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 2.0, longitude: 2.0)) + let one = CLLocation(latitude: 0.0, longitude: 0.0) + let two = CLLocation(latitude: 2.0, longitude: 2.0) let directions = Directions(credentials: BogusCredentials) let opts = RouteOptions(locations: [one, two]) @@ -165,8 +164,8 @@ class DirectionsTests: XCTestCase { } let expectation = self.expectation(description: "Async callback") - let one = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)) - let two = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 2.0, longitude: 2.0)) + let one = CLLocation(latitude: 0.0, longitude: 0.0) + let two = CLLocation(latitude: 2.0, longitude: 2.0) let directions = Directions(credentials: BogusCredentials) let opts = RouteOptions(locations: [one, two]) diff --git a/Tests/MapboxDirectionsTests/IntersectionTests.swift b/Tests/MapboxDirectionsTests/IntersectionTests.swift index 73ecd355c..043c146c4 100644 --- a/Tests/MapboxDirectionsTests/IntersectionTests.swift +++ b/Tests/MapboxDirectionsTests/IntersectionTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class IntersectionTests: XCTestCase { @@ -54,12 +50,12 @@ class IntersectionTests: XCTestCase { if let intersection = intersections?.first { XCTAssertEqual(intersection.outletRoadClasses, [.toll, .restricted]) XCTAssertEqual(intersection.headings, [80.0]) - XCTAssertEqual(intersection.location, CLLocationCoordinate2D(latitude: 52.508068, longitude: 13.426579)) + XCTAssertEqual(intersection.location, LocationCoordinate2D(latitude: 52.508068, longitude: 13.426579)) XCTAssertEqual(intersection.outletMapboxStreetsRoadClass, MapboxStreetsRoadClass.streetLimited) } intersections = [ - Intersection(location: CLLocationCoordinate2D(latitude: 52.508068, longitude: 13.426579), + Intersection(location: LocationCoordinate2D(latitude: 52.508068, longitude: 13.426579), headings: [80.0], approachIndex: -1, outletIndex: 0, @@ -72,7 +68,7 @@ class IntersectionTests: XCTestCase { restStop: nil, isUrban: nil, outletMapboxStreetsRoadClass: .streetLimited), - Intersection(location: CLLocationCoordinate2D(latitude: 52.508022, longitude: 13.426688), + Intersection(location: LocationCoordinate2D(latitude: 52.508022, longitude: 13.426688), headings: [30.0, 120.0, 300.0], approachIndex: 2, outletIndex: 1, @@ -84,7 +80,7 @@ class IntersectionTests: XCTestCase { tunnelName: nil, restStop: nil, isUrban: nil), - Intersection(location: CLLocationCoordinate2D(latitude: 39.102483, longitude: -84.503956), + Intersection(location: LocationCoordinate2D(latitude: 39.102483, longitude: -84.503956), headings: [45, 135, 255], approachIndex: 2, outletIndex: 0, diff --git a/Tests/MapboxDirectionsTests/MatchOptionsTests.swift b/Tests/MapboxDirectionsTests/MatchOptionsTests.swift index 31d658ac3..4b7f86d8d 100644 --- a/Tests/MapboxDirectionsTests/MatchOptionsTests.swift +++ b/Tests/MapboxDirectionsTests/MatchOptionsTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class MatchOptionsTests: XCTestCase { @@ -33,15 +29,15 @@ class MatchOptionsTests: XCTestCase { // MARK: API name-handling tests private static var testTracepoints: [Tracepoint] { - let one = CLLocationCoordinate2D(latitude: 39.27664, longitude:-84.41139) - let two = CLLocationCoordinate2D(latitude: 39.27277, longitude:-84.41226) + let one = LocationCoordinate2D(latitude: 39.27664, longitude:-84.41139) + let two = LocationCoordinate2D(latitude: 39.27277, longitude:-84.41226) return [one, two].map { Tracepoint(coordinate: $0, countOfAlternatives: 0, name: nil) } } func testWaypointSerialization() { - let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 39.15031, longitude: -84.47182), name: "XU") - let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 39.12971, longitude: -84.51638), name: "UC") + let origin = Waypoint(coordinate: LocationCoordinate2D(latitude: 39.15031, longitude: -84.47182), name: "XU") + let destination = Waypoint(coordinate: LocationCoordinate2D(latitude: 39.12971, longitude: -84.51638), name: "UC") let options = MatchOptions(waypoints: [origin, destination]) XCTAssertEqual(options.coordinates, "-84.47182,39.15031;-84.51638,39.12971") XCTAssertTrue(options.urlQueryItems.contains(URLQueryItem(name: "waypoint_names", value: "XU;UC"))) @@ -62,9 +58,9 @@ class MatchOptionsTests: XCTestCase { } fileprivate let testCoordinates = [ - CLLocationCoordinate2D(latitude: 52.5109, longitude: 13.4301), - CLLocationCoordinate2D(latitude: 52.5080, longitude: 13.4265), - CLLocationCoordinate2D(latitude: 52.5021, longitude: 13.4316), + LocationCoordinate2D(latitude: 52.5109, longitude: 13.4301), + LocationCoordinate2D(latitude: 52.5080, longitude: 13.4265), + LocationCoordinate2D(latitude: 52.5021, longitude: 13.4316), ] diff --git a/Tests/MapboxDirectionsTests/MatchTests.swift b/Tests/MapboxDirectionsTests/MatchTests.swift index 3bc7427b9..5a395de64 100644 --- a/Tests/MapboxDirectionsTests/MatchTests.swift +++ b/Tests/MapboxDirectionsTests/MatchTests.swift @@ -1,9 +1,8 @@ import XCTest #if canImport(CoreLocation) import CoreLocation -#else -import Turf #endif +import Turf #if !SWIFT_PACKAGE import OHHTTPStubs #endif @@ -193,9 +192,9 @@ class MatchTests: XCTestCase { let matchData = try! JSONSerialization.data(withJSONObject: matchJSON, options: []) let options = MatchOptions(coordinates: [ - CLLocationCoordinate2D(latitude: 39.09740, longitude: -84.51200), - CLLocationCoordinate2D(latitude: 39.09638, longitude: -84.51118), - CLLocationCoordinate2D(latitude: 39.09687, longitude: -84.51021), + LocationCoordinate2D(latitude: 39.09740, longitude: -84.51200), + LocationCoordinate2D(latitude: 39.09638, longitude: -84.51118), + LocationCoordinate2D(latitude: 39.09687, longitude: -84.51021), ]) options.routeShapeResolution = .none diff --git a/Tests/MapboxDirectionsTests/OfflineDirectionsTests.swift b/Tests/MapboxDirectionsTests/OfflineDirectionsTests.swift index 1a9c867df..dc51caadf 100644 --- a/Tests/MapboxDirectionsTests/OfflineDirectionsTests.swift +++ b/Tests/MapboxDirectionsTests/OfflineDirectionsTests.swift @@ -38,8 +38,8 @@ class OfflineDirectionsTests: XCTestCase { func testDownloadTiles() { let directions = Directions(credentials: BogusCredentials) - let bounds = BoundingBox(CLLocationCoordinate2D(latitude: 37.7890, longitude: -122.4337), - CLLocationCoordinate2D(latitude: 37.7881, longitude: -122.4318)) + let bounds = BoundingBox(southWest: CLLocationCoordinate2D(latitude: 37.7890, longitude: -122.4337), + northEast: CLLocationCoordinate2D(latitude: 37.7881, longitude: -122.4318)) let version = "2018-10-16" let downloadExpectation = self.expectation(description: "Download tile expectation") diff --git a/Tests/MapboxDirectionsTests/QuickLookTests.swift b/Tests/MapboxDirectionsTests/QuickLookTests.swift index 8ebafe9b5..4b0467de0 100644 --- a/Tests/MapboxDirectionsTests/QuickLookTests.swift +++ b/Tests/MapboxDirectionsTests/QuickLookTests.swift @@ -1,15 +1,12 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#endif import Turf @testable import MapboxDirections class QuickLookTests: XCTestCase { func testQuickLookURL() { let lineString = LineString([ - CLLocationCoordinate2D(latitude: 0, longitude: 0), - CLLocationCoordinate2D(latitude: 1, longitude: 1), + LocationCoordinate2D(latitude: 0, longitude: 0), + LocationCoordinate2D(latitude: 1, longitude: 1), ]) XCTAssertNil(debugQuickLookURL(illustrating: lineString)) XCTAssertEqual(debugQuickLookURL(illustrating: lineString, accessToken: BogusToken), URL(string: "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-10+3802DA-0.6(%3F%3F_ibE_ibE)/auto/680x360@2x?before_layer=building-number-label&access_token=\(BogusToken)")) diff --git a/Tests/MapboxDirectionsTests/RouteLegTests.swift b/Tests/MapboxDirectionsTests/RouteLegTests.swift index 2fa847007..becc03dfe 100644 --- a/Tests/MapboxDirectionsTests/RouteLegTests.swift +++ b/Tests/MapboxDirectionsTests/RouteLegTests.swift @@ -1,26 +1,23 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#endif import Turf @testable import MapboxDirections class RouteLegTests: XCTestCase { func testSegmentRanges() { - let departureStep = RouteStep(transportType: .automobile, maneuverLocation: CLLocationCoordinate2D(latitude: 0, longitude: 0), maneuverType: .depart, instructions: "Depart", drivingSide: .right, distance: 10, expectedTravelTime: 10) + let departureStep = RouteStep(transportType: .automobile, maneuverLocation: LocationCoordinate2D(latitude: 0, longitude: 0), maneuverType: .depart, instructions: "Depart", drivingSide: .right, distance: 10, expectedTravelTime: 10) departureStep.shape = LineString([ - CLLocationCoordinate2D(latitude: 0, longitude: 0), - CLLocationCoordinate2D(latitude: 1, longitude: 1), + LocationCoordinate2D(latitude: 0, longitude: 0), + LocationCoordinate2D(latitude: 1, longitude: 1), ]) - let turnStep = RouteStep(transportType: .automobile, maneuverLocation: CLLocationCoordinate2D(latitude: 1, longitude: 1), maneuverType: .turn, maneuverDirection: .left, instructions: "Turn left at Albuquerque", drivingSide: .right, distance: 10, expectedTravelTime: 10) + let turnStep = RouteStep(transportType: .automobile, maneuverLocation: LocationCoordinate2D(latitude: 1, longitude: 1), maneuverType: .turn, maneuverDirection: .left, instructions: "Turn left at Albuquerque", drivingSide: .right, distance: 10, expectedTravelTime: 10) turnStep.shape = LineString([ - CLLocationCoordinate2D(latitude: 1, longitude: 1), - CLLocationCoordinate2D(latitude: 2, longitude: 2), - CLLocationCoordinate2D(latitude: 3, longitude: 3), - CLLocationCoordinate2D(latitude: 4, longitude: 4), + LocationCoordinate2D(latitude: 1, longitude: 1), + LocationCoordinate2D(latitude: 2, longitude: 2), + LocationCoordinate2D(latitude: 3, longitude: 3), + LocationCoordinate2D(latitude: 4, longitude: 4), ]) let typicalTravelTime = 10.0 - let arrivalStep = RouteStep(transportType: .automobile, maneuverLocation: CLLocationCoordinate2D(latitude: 4, longitude: 4), maneuverType: .arrive, instructions: "Arrive at Elmer’s House", drivingSide: .right, distance: 0, expectedTravelTime: 0) + let arrivalStep = RouteStep(transportType: .automobile, maneuverLocation: LocationCoordinate2D(latitude: 4, longitude: 4), maneuverType: .arrive, instructions: "Arrive at Elmer’s House", drivingSide: .right, distance: 0, expectedTravelTime: 0) let leg = RouteLeg(steps: [departureStep, turnStep, arrivalStep], name: "", distance: 10, expectedTravelTime: 10, typicalTravelTime: typicalTravelTime, profileIdentifier: .automobile) leg.segmentDistances = [ 10, diff --git a/Tests/MapboxDirectionsTests/RouteOptionsTests.swift b/Tests/MapboxDirectionsTests/RouteOptionsTests.swift index 05736b816..dd6325f74 100644 --- a/Tests/MapboxDirectionsTests/RouteOptionsTests.swift +++ b/Tests/MapboxDirectionsTests/RouteOptionsTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class RouteOptionsTests: XCTestCase { @@ -39,8 +35,8 @@ class RouteOptionsTests: XCTestCase { private static var testWaypoints: [Waypoint] { return [ - Waypoint(coordinate: CLLocationCoordinate2D(latitude: 39.27664, longitude:-84.41139)), - Waypoint(coordinate: CLLocationCoordinate2D(latitude: 39.27277, longitude:-84.41226)), + Waypoint(coordinate: LocationCoordinate2D(latitude: 39.27664, longitude:-84.41139)), + Waypoint(coordinate: LocationCoordinate2D(latitude: 39.27277, longitude:-84.41226)), ] } @@ -94,7 +90,7 @@ class RouteOptionsTests: XCTestCase { } func testApproachesURLQueryParams() { - let coordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) + let coordinate = LocationCoordinate2D(latitude: 0, longitude: 0) let wp1 = Waypoint(coordinate: coordinate, coordinateAccuracy: 0) wp1.allowsArrivingOnOppositeSide = false let waypoints = [ @@ -111,7 +107,7 @@ class RouteOptionsTests: XCTestCase { } func testMissingApproaches() { - let coordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) + let coordinate = LocationCoordinate2D(latitude: 0, longitude: 0) let waypoints = [ Waypoint(coordinate: coordinate, coordinateAccuracy: 0), Waypoint(coordinate: coordinate, coordinateAccuracy: 0), @@ -126,8 +122,8 @@ class RouteOptionsTests: XCTestCase { } func testDecimalPrecision() { - let start = CLLocationCoordinate2D(latitude: 9.945497000000003, longitude: 53.03218800000006) - let end = CLLocationCoordinate2D(latitude: 10.945497000000003, longitude: 54.03218800000006) + let start = LocationCoordinate2D(latitude: 9.945497000000003, longitude: 53.03218800000006) + let end = LocationCoordinate2D(latitude: 10.945497000000003, longitude: 54.03218800000006) let answer = [start.requestDescription, end.requestDescription] let correct = ["53.032188,9.945497", "54.032188,10.945497"] @@ -135,9 +131,9 @@ class RouteOptionsTests: XCTestCase { } func testWaypointSerialization() { - let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 39.15031, longitude: -84.47182), name: "XU") - let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 39.12971, longitude: -84.51638), name: "UC") - destination.targetCoordinate = CLLocationCoordinate2D(latitude: 39.13115, longitude: -84.51619) + let origin = Waypoint(coordinate: LocationCoordinate2D(latitude: 39.15031, longitude: -84.47182), name: "XU") + let destination = Waypoint(coordinate: LocationCoordinate2D(latitude: 39.12971, longitude: -84.51638), name: "UC") + destination.targetCoordinate = LocationCoordinate2D(latitude: 39.13115, longitude: -84.51619) let options = RouteOptions(waypoints: [origin, destination]) XCTAssertEqual(options.coordinates, "-84.47182,39.15031;-84.51638,39.12971") XCTAssertTrue(options.urlQueryItems.contains(URLQueryItem(name: "waypoint_names", value: "XU;UC"))) @@ -146,9 +142,9 @@ class RouteOptionsTests: XCTestCase { } fileprivate let testCoordinates = [ - CLLocationCoordinate2D(latitude: 52.5109, longitude: 13.4301), - CLLocationCoordinate2D(latitude: 52.5080, longitude: 13.4265), - CLLocationCoordinate2D(latitude: 52.5021, longitude: 13.4316), + LocationCoordinate2D(latitude: 52.5109, longitude: 13.4301), + LocationCoordinate2D(latitude: 52.5080, longitude: 13.4265), + LocationCoordinate2D(latitude: 52.5021, longitude: 13.4316), ] var testRouteOptions: RouteOptions { diff --git a/Tests/MapboxDirectionsTests/RouteRefreshTests.swift b/Tests/MapboxDirectionsTests/RouteRefreshTests.swift index db76c715f..3ff8a6a6a 100644 --- a/Tests/MapboxDirectionsTests/RouteRefreshTests.swift +++ b/Tests/MapboxDirectionsTests/RouteRefreshTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif #if !SWIFT_PACKAGE import OHHTTPStubs #endif @@ -199,7 +195,7 @@ class RouteRefreshTests: XCTestCase { let annotationJSON = legJSON["annotation"] as? [String: Any] XCTAssertNotNil(annotationJSON) if let annotationJSON = annotationJSON { - XCTAssertEqual(annotationJSON["distance"] as? [CLLocationDistance], [0]) + XCTAssertEqual(annotationJSON["distance"] as? [LocationDistance], [0]) XCTAssertEqual(annotationJSON["duration"] as? [TimeInterval], [0]) XCTAssertEqual(annotationJSON["speed"] as? [LocationSpeed], [0]) XCTAssertEqual(annotationJSON["congestion"] as? [String], ["severe"]) diff --git a/Tests/MapboxDirectionsTests/RouteResponseTests.swift b/Tests/MapboxDirectionsTests/RouteResponseTests.swift index 12757f1c5..cb31b40b9 100644 --- a/Tests/MapboxDirectionsTests/RouteResponseTests.swift +++ b/Tests/MapboxDirectionsTests/RouteResponseTests.swift @@ -1,15 +1,11 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class RouteResponseTests: XCTestCase { func testRouteResponseEncodingAndDecoding() { - let originCoordinate = CLLocationCoordinate2D(latitude: 39.15031, longitude: -84.47182) + let originCoordinate = LocationCoordinate2D(latitude: 39.15031, longitude: -84.47182) let originWaypoint = Waypoint(coordinate: originCoordinate, name: "Test waypoint") originWaypoint.targetCoordinate = originCoordinate originWaypoint.coordinateAccuracy = 1.0 diff --git a/Tests/MapboxDirectionsTests/RouteStepTests.swift b/Tests/MapboxDirectionsTests/RouteStepTests.swift index 78a4a4dfb..a1b6c2e4b 100644 --- a/Tests/MapboxDirectionsTests/RouteStepTests.swift +++ b/Tests/MapboxDirectionsTests/RouteStepTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class RoadTests: XCTestCase { @@ -138,7 +134,7 @@ class RouteStepTests: XCTestCase { XCTAssertEqual(step.shape?.coordinates.last?.longitude ?? 0, -122.220021, accuracy: 1e-5) XCTAssertEqual(step.finalHeading, 73) XCTAssertEqual(step.initialHeading, 60) - XCTAssertEqual(step.maneuverLocation, CLLocationCoordinate2D(latitude: -122.220291, longitude: 37.854109)) + XCTAssertEqual(step.maneuverLocation, LocationCoordinate2D(latitude: -122.220291, longitude: 37.854109)) XCTAssertEqual(step.maneuverDirection, .slightRight) XCTAssertEqual(step.maneuverType, .reachFork) XCTAssertEqual(step.instructions, "Keep right onto CA 24") @@ -153,8 +149,8 @@ class RouteStepTests: XCTestCase { func testCoding() { let options = RouteOptions(coordinates: [ - CLLocationCoordinate2D(latitude: 52.50881, longitude: 13.42467), - CLLocationCoordinate2D(latitude: 52.506794, longitude: 13.42326), + LocationCoordinate2D(latitude: 52.50881, longitude: 13.42467), + LocationCoordinate2D(latitude: 52.506794, longitude: 13.42326), ]) options.shapeFormat = .polyline @@ -260,10 +256,10 @@ class RouteStepTests: XCTestCase { func testEncodingPronunciations() { let options = RouteOptions(coordinates: [ - CLLocationCoordinate2D(latitude: 0, longitude: 0), - CLLocationCoordinate2D(latitude: 1, longitude: 1), + LocationCoordinate2D(latitude: 0, longitude: 0), + LocationCoordinate2D(latitude: 1, longitude: 1), ]) - let step = RouteStep(transportType: .automobile, maneuverLocation: CLLocationCoordinate2D(latitude: 0, longitude: 0), maneuverType: .turn, maneuverDirection: .left, instructions: "", initialHeading: 0, finalHeading: 0, drivingSide: .right, distance: 10, expectedTravelTime: 10, names: ["iPhone X", "iPhone XS"], phoneticNames: ["ˈaɪˌfoʊ̯n ˈtɛn", "ˈaɪˌfoʊ̯n ˈtɛnz"]) + let step = RouteStep(transportType: .automobile, maneuverLocation: LocationCoordinate2D(latitude: 0, longitude: 0), maneuverType: .turn, maneuverDirection: .left, instructions: "", initialHeading: 0, finalHeading: 0, drivingSide: .right, distance: 10, expectedTravelTime: 10, names: ["iPhone X", "iPhone XS"], phoneticNames: ["ˈaɪˌfoʊ̯n ˈtɛn", "ˈaɪˌfoʊ̯n ˈtɛnz"]) let encoder = JSONEncoder() encoder.userInfo[.options] = options @@ -284,7 +280,7 @@ class RouteStepTests: XCTestCase { let typicalTravelTime = 2.5 let route = RouteStep(transportType: .automobile, - maneuverLocation: CLLocationCoordinate2D(latitude: 0, longitude: 0), + maneuverLocation: LocationCoordinate2D(latitude: 0, longitude: 0), maneuverType: .turn, instructions: "", drivingSide: .left, @@ -300,8 +296,8 @@ class RouteStepTests: XCTestCase { let filePath = URL(fileURLWithPath: path!) let data = try! Data(contentsOf: filePath) let options = RouteOptions(coordinates: [ - CLLocationCoordinate2D(latitude: 37.78, longitude: -122.42), - CLLocationCoordinate2D(latitude: 38.91, longitude: -77.03), + LocationCoordinate2D(latitude: 37.78, longitude: -122.42), + LocationCoordinate2D(latitude: 38.91, longitude: -77.03), ]) let decoder = JSONDecoder() diff --git a/Tests/MapboxDirectionsTests/RouteTests.swift b/Tests/MapboxDirectionsTests/RouteTests.swift index 94aede0aa..12d54754d 100644 --- a/Tests/MapboxDirectionsTests/RouteTests.swift +++ b/Tests/MapboxDirectionsTests/RouteTests.swift @@ -1,10 +1,6 @@ import XCTest import Foundation -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class RouteTests: XCTestCase { @@ -30,8 +26,8 @@ class RouteTests: XCTestCase { let routeData = try! JSONSerialization.data(withJSONObject: routeJSON, options: []) let options = RouteOptions(coordinates: [ - CLLocationCoordinate2D(latitude: 39.73843005470756, longitude: -105.08198579860195), - CLLocationCoordinate2D(latitude: 39.662569, longitude: -104.954255), + LocationCoordinate2D(latitude: 39.73843005470756, longitude: -105.08198579860195), + LocationCoordinate2D(latitude: 39.662569, longitude: -104.954255), ], profileIdentifier: .automobileAvoidingTraffic) options.routeShapeResolution = .none @@ -111,8 +107,8 @@ class RouteTests: XCTestCase { ] let options = RouteOptions(coordinates: [ - CLLocationCoordinate2D(latitude: 39.73843, longitude: -105.081986), - CLLocationCoordinate2D(latitude: 39.662569, longitude: -104.954255), + LocationCoordinate2D(latitude: 39.73843, longitude: -105.081986), + LocationCoordinate2D(latitude: 39.662569, longitude: -104.954255), ]) options.locale = Locale(identifier: "he") diff --git a/Tests/MapboxDirectionsTests/SpokenInstructionTests.swift b/Tests/MapboxDirectionsTests/SpokenInstructionTests.swift index 195ce0f20..652f63b52 100644 --- a/Tests/MapboxDirectionsTests/SpokenInstructionTests.swift +++ b/Tests/MapboxDirectionsTests/SpokenInstructionTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class SpokenInstructionTests: XCTestCase { @@ -18,12 +14,12 @@ class SpokenInstructionTests: XCTestCase { XCTAssertNoThrow(instruction = try JSONDecoder().decode(SpokenInstruction.self, from: instructionData)) XCTAssertNotNil(instruction) if let instruction = instruction { - XCTAssertEqual(instruction.distanceAlongStep, instructionJSON["distanceAlongGeometry"] as! CLLocationDistance) + XCTAssertEqual(instruction.distanceAlongStep, instructionJSON["distanceAlongGeometry"] as! LocationDistance) XCTAssertEqual(instruction.text, instructionJSON["announcement"] as! String) XCTAssertEqual(instruction.ssmlText, instructionJSON["ssmlAnnouncement"] as! String) } - instruction = SpokenInstruction(distanceAlongStep: instructionJSON["distanceAlongGeometry"] as! CLLocationDistance, + instruction = SpokenInstruction(distanceAlongStep: instructionJSON["distanceAlongGeometry"] as! LocationDistance, text: instructionJSON["announcement"] as! String, ssmlText: instructionJSON["ssmlAnnouncement"] as! String) let encoder = JSONEncoder() diff --git a/Tests/MapboxDirectionsTests/WalkingOptionsTests.swift b/Tests/MapboxDirectionsTests/WalkingOptionsTests.swift index eb0bd22cb..f9b431266 100644 --- a/Tests/MapboxDirectionsTests/WalkingOptionsTests.swift +++ b/Tests/MapboxDirectionsTests/WalkingOptionsTests.swift @@ -1,17 +1,13 @@ import XCTest import MapboxDirections -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class WalkingOptionsTests: XCTestCase { func testURLQueryParams() { let waypoints = [ - Waypoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 1)), - Waypoint(coordinate: CLLocationCoordinate2D(latitude: 2, longitude: 3)) + Waypoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 1)), + Waypoint(coordinate: LocationCoordinate2D(latitude: 2, longitude: 3)) ] let options = RouteOptions(waypoints: waypoints, profileIdentifier: DirectionsProfileIdentifier.walking) diff --git a/Tests/MapboxDirectionsTests/WaypointTests.swift b/Tests/MapboxDirectionsTests/WaypointTests.swift index b2fbdef27..c6fef077c 100644 --- a/Tests/MapboxDirectionsTests/WaypointTests.swift +++ b/Tests/MapboxDirectionsTests/WaypointTests.swift @@ -1,9 +1,5 @@ import XCTest -#if canImport(CoreLocation) -import CoreLocation -#else import Turf -#endif @testable import MapboxDirections class WaypointTests: XCTestCase { @@ -29,8 +25,8 @@ class WaypointTests: XCTestCase { XCTAssertTrue(waypoint.separatesLegs) } - waypoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), coordinateAccuracy: 5, name: "White House") - waypoint?.targetCoordinate = CLLocationCoordinate2D(latitude: 38.8952261, longitude: -77.0327882) + waypoint = Waypoint(coordinate: LocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), coordinateAccuracy: 5, name: "White House") + waypoint?.targetCoordinate = LocationCoordinate2D(latitude: 38.8952261, longitude: -77.0327882) waypoint?.heading = 90 waypoint?.headingAccuracy = 10 waypoint?.allowsArrivingOnOppositeSide = false @@ -46,18 +42,18 @@ class WaypointTests: XCTestCase { XCTAssertNotNil(encodedWaypointJSON) // Verify then remove keys that wouldn’t be part of a Waypoint object in the Directions API response. - XCTAssertEqual(encodedWaypointJSON?["headingAccuracy"] as? CLLocationDirection, waypoint?.headingAccuracy) + XCTAssertEqual(encodedWaypointJSON?["headingAccuracy"] as? LocationDirection, waypoint?.headingAccuracy) encodedWaypointJSON?.removeValue(forKey: "headingAccuracy") XCTAssertEqual(encodedWaypointJSON?["coordinateAccuracy"] as? LocationAccuracy, waypoint?.coordinateAccuracy) encodedWaypointJSON?.removeValue(forKey: "coordinateAccuracy") XCTAssertEqual(encodedWaypointJSON?["allowsArrivingOnOppositeSide"] as? Bool, waypoint?.allowsArrivingOnOppositeSide) encodedWaypointJSON?.removeValue(forKey: "allowsArrivingOnOppositeSide") - XCTAssertEqual(encodedWaypointJSON?["heading"] as? CLLocationDirection, waypoint?.heading) + XCTAssertEqual(encodedWaypointJSON?["heading"] as? LocationDirection, waypoint?.heading) encodedWaypointJSON?.removeValue(forKey: "heading") XCTAssertEqual(encodedWaypointJSON?["separatesLegs"] as? Bool, waypoint?.separatesLegs) encodedWaypointJSON?.removeValue(forKey: "separatesLegs") - let targetCoordinateJSON = encodedWaypointJSON?["targetCoordinate"] as? [CLLocationDegrees] + let targetCoordinateJSON = encodedWaypointJSON?["targetCoordinate"] as? [LocationDegrees] XCTAssertNotNil(targetCoordinateJSON) XCTAssertEqual(targetCoordinateJSON?.count, 2) XCTAssertEqual(targetCoordinateJSON?[0] ?? 0, waypoint?.targetCoordinate?.longitude ?? 0, accuracy: 1e-5) @@ -69,10 +65,10 @@ class WaypointTests: XCTestCase { } func testSeparatesLegs() { - let one = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 1, longitude: 1)) - let two = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 2, longitude: 2)) - let three = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 3, longitude: 3)) - let four = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 4, longitude: 4)) + let one = Waypoint(coordinate: LocationCoordinate2D(latitude: 1, longitude: 1)) + let two = Waypoint(coordinate: LocationCoordinate2D(latitude: 2, longitude: 2)) + let three = Waypoint(coordinate: LocationCoordinate2D(latitude: 3, longitude: 3)) + let four = Waypoint(coordinate: LocationCoordinate2D(latitude: 4, longitude: 4)) let routeOptions = RouteOptions(waypoints: [one, two, three, four]) let matchOptions = MatchOptions(waypoints: [one, two, three, four], profileIdentifier: nil) @@ -92,7 +88,7 @@ class WaypointTests: XCTestCase { } func testHeading() { - let waypoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: -180, longitude: -180)) + let waypoint = Waypoint(coordinate: LocationCoordinate2D(latitude: -180, longitude: -180)) XCTAssertEqual(waypoint.headingDescription, "") waypoint.heading = 0 @@ -109,40 +105,40 @@ class WaypointTests: XCTestCase { } func testEquality() { - let left = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), coordinateAccuracy: nil, name: nil) + let left = Waypoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), coordinateAccuracy: nil, name: nil) XCTAssertEqual(left, left) - var right = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 1, longitude: 1), coordinateAccuracy: nil, name: nil) + var right = Waypoint(coordinate: LocationCoordinate2D(latitude: 1, longitude: 1), coordinateAccuracy: nil, name: nil) XCTAssertNotEqual(left, right) - right = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), coordinateAccuracy: 0, name: nil) + right = Waypoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), coordinateAccuracy: 0, name: nil) XCTAssertNotEqual(left, right) - right = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), coordinateAccuracy: nil, name: "") + right = Waypoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), coordinateAccuracy: nil, name: "") XCTAssertNotEqual(left, right) } func testTracepointEquality() { - let left = Tracepoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 0, name: nil) + let left = Tracepoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 0, name: nil) XCTAssertEqual(left, left) - let right = Tracepoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 0, name: nil) + let right = Tracepoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 0, name: nil) XCTAssertEqual(left, right) // FIXME: Only Waypoint.==(_:_:) ever gets called: . This will be moot once Tracepoint becomes a struct that doesn’t inherit from Waypoint: . -// right = Tracepoint(coordinate: CLLocationCoordinate2D(latitude: 1, longitude: 1), countOfAlternatives: 0, name: nil) +// right = Tracepoint(coordinate: LocationCoordinate2D(latitude: 1, longitude: 1), countOfAlternatives: 0, name: nil) // XCTAssertNotEqual(left, right) // -// right = Tracepoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 1, name: nil) +// right = Tracepoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 1, name: nil) // XCTAssertNotEqual(left, right) // -// right = Tracepoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 0, name: "") +// right = Tracepoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0), countOfAlternatives: 0, name: "") // XCTAssertNotEqual(left, right) } func testAccuracies() { - let from = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0)) - let to = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0)) + let from = Waypoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0)) + let to = Waypoint(coordinate: LocationCoordinate2D(latitude: 0, longitude: 0)) let options = RouteOptions(waypoints: [from, to]) XCTAssertNil(options.bearings) XCTAssertNil(options.radiuses)