Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turf v2.0.0-alpha.3 #525

Merged
merged 3 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.test >> <<# parameters.codecoverage >>-enableCodeCoverage YES<</ parameters.codecoverage >>
- when:
condition: << parameters.codecoverage >>
steps:
- publish-codecov
- run:
name: macOS
command: xcodebuild -project MapboxDirections.xcodeproj -scheme 'MapboxDirections Mac' clean build<<# parameters.test >> test <</ parameters.test >><<# parameters.codecoverage >>-enableCodeCoverage YES<</ parameters.codecoverage >>
- 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:
Expand All @@ -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"
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 3 additions & 1 deletion MapboxDirections.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand All @@ -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
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: [
Expand Down
9 changes: 3 additions & 6 deletions Sources/MapboxDirections/DirectionsResult.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import Foundation
import Polyline
#if canImport(CoreLocation)
import CoreLocation
#endif
import Turf

/**
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
40 changes: 18 additions & 22 deletions Sources/MapboxDirections/Extensions/Codable.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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 {
/**
Returns a string representation of the line string in [Polyline Algorithm Format](https://developers.google.com/maps/documentation/utilities/polylinealgorithm).
*/
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)
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
}
}
31 changes: 3 additions & 28 deletions Sources/MapboxDirections/Extensions/CoreLocation.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Foundation
#if canImport(CoreLocation)
import CoreLocation
#else
import Turf
import Polyline
#endif
import Turf


#if canImport(CoreLocation)
/**
Expand All @@ -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

10 changes: 6 additions & 4 deletions Sources/MapboxDirections/Extensions/GeoJSON.swift
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.
Expand All @@ -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
}
}
Expand Down
20 changes: 8 additions & 12 deletions Sources/MapboxDirections/Intersection.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import Foundation
#if canImport(CoreLocation)
import CoreLocation
#else
import Turf
#endif

/**
A single cross street along a step.
*/
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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand Down
Loading