Skip to content

Commit

Permalink
Revert GeoCoordinate to plain protocol
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Mueller <mmlr@gmx.net>
  • Loading branch information
mmllr committed Jan 18, 2021
1 parent 3db9f77 commit 38221b6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Sources/GPXKit/ArrayExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
import MapKit
import CoreLocation

public extension Array where Element: GeoCoordinate, Element.ValueType == Double {
public extension Array where Element: GeoCoordinate {
var polyLine: MKPolyline {
let coords = map(CLLocationCoordinate2D.init)
return MKPolyline(coordinates: coords, count: coords.count)
Expand Down
2 changes: 1 addition & 1 deletion Sources/GPXKit/CoreLocationSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public extension TrackGraph {
}

public extension CLLocationCoordinate2D {
init<Coord: GeoCoordinate>(_ coord: Coord) where Coord.ValueType == Double {
init(_ coord: GeoCoordinate) {
self.init(latitude: coord.latitude, longitude: coord.longitude)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/GPXKit/DistanceCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ private let pi = Double.pi
// https://www.movable-type.co.uk/scripts/latlong-vincenty.html
// https://github.com/dastrobu/vincenty/blob/master/Sources/vincenty/vincenty.swift
extension GeoCoordinate {
public func distanceVincenty(to: Self,
public func distanceVincenty(to: GeoCoordinate,
tol: Double = 1e-12,
maxIter: UInt = 200,
ellipsoid: (a: Double, f: Double) = wgs84) throws -> Double where Self.ValueType == Double {
ellipsoid: (a: Double, f: Double) = wgs84) throws -> Double {
assert(tol > 0, "tol '\(tol)' ≤ 0")

// validate lat and lon values
Expand Down Expand Up @@ -129,7 +129,7 @@ extension GeoCoordinate {
return B * a * (sigma - delta_sigma)
}

func calculateSimpleDistance(to: Self) -> Double where Self.ValueType == Double {
func calculateSimpleDistance(to: GeoCoordinate) -> Double {
// https://www.movable-type.co.uk/scripts/latlong.html
let R = 6371e3 // metres
let φ1 = latitude.degreesToRadians
Expand Down
2 changes: 1 addition & 1 deletion Sources/GPXKit/Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public extension GeoCoordinate {
func distance(to: Self) -> Double where Self.ValueType == Double {
func distance(to: GeoCoordinate) -> Double {
guard let dist = try? distanceVincenty(to: to) else { return calculateSimpleDistance(to: to) }
return dist
}
Expand Down
7 changes: 3 additions & 4 deletions Sources/GPXKit/GPXKit.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Foundation

public protocol GeoCoordinate: Equatable {
associatedtype ValueType: FloatingPoint
var latitude: ValueType { get}
var longitude: ValueType { get }
public protocol GeoCoordinate {
var latitude: Double { get}
var longitude: Double { get }
}

public struct Coordinate: Equatable, Hashable, GeoCoordinate {
Expand Down
10 changes: 5 additions & 5 deletions Tests/GPXKitTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ extension XCTest {
""", file: file, line: line)
}

func assertGeoCoordinateEqual<T: GeoCoordinate>(
_ expected: T,
_ actual: T,
func assertGeoCoordinateEqual(
_ expected: GeoCoordinate,
_ actual: GeoCoordinate,
accuracy: Double = 0.0001,
file: StaticString = #filePath,
line: UInt = #line
) where T.ValueType == Double {
) {
XCTAssertEqual(expected.latitude,
actual.latitude,
accuracy: accuracy,
Expand All @@ -144,7 +144,7 @@ extension XCTest {
accuracy: Double = 0.00001,
file: StaticString = #filePath,
line: UInt = #line
) where T.Element: GeoCoordinate, T.Element.ValueType == Double {
) where T.Element: GeoCoordinate {
XCTAssertEqual(expected.count, acutal.count)
zip(expected, acutal).forEach { lhs, rhs in
assertGeoCoordinateEqual(lhs, rhs, accuracy: accuracy, file: file, line: line)
Expand Down

0 comments on commit 38221b6

Please sign in to comment.