From 7ff24d4dfa2714d66f256cd095860581da8b2b66 Mon Sep 17 00:00:00 2001 From: Daniel Strobusch <1847260+dastrobu@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:33:17 +0100 Subject: [PATCH] build with Swift 5.9 --- .github/workflows/ci.yaml | 8 +++++--- Package.swift | 2 +- README.md | 2 +- Sources/vincenty/vincenty.swift | 11 ++++++----- Tests/vincentyTests/vincentyTests.swift | 25 +++++++++++-------------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 721e867..365252b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: norio-nomura/action-swiftlint@3.2.1 macos-test: strategy: @@ -15,7 +15,7 @@ jobs: - "5.7" runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: swift-actions/setup-swift@v1 with: swift-version: ${{ matrix.swift-version }} @@ -24,6 +24,8 @@ jobs: strategy: matrix: swift-version: + - "5.9" + - "5.8" - "5.7" - "5.6" - "5.5" @@ -40,5 +42,5 @@ jobs: ios-build: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: xcodebuild -scheme vincenty -destination 'platform=iOS Simulator,name=iPhone 13' diff --git a/Package.swift b/Package.swift index f7b7ada..5db85df 100644 --- a/Package.swift +++ b/Package.swift @@ -10,7 +10,7 @@ let package = Package( targets: ["vincenty"]), ], dependencies: [ - .package(url: "https://github.com/dastrobu/geodesic.git", from: "1.3.0"), + .package(url: "https://github.com/dastrobu/geodesic.git", from: "1.4.0"), ], targets: [ .target( diff --git a/README.md b/README.md index 1baaa9d..85cfb02 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # vincenty -[![Swift Version](https://img.shields.io/badge/swift-5.7-blue.svg)](https://swift.org) +[![Swift Version](https://img.shields.io/badge/swift-5.9-blue.svg)](https://swift.org) ![Platform](https://img.shields.io/badge/platform-macOS|linux--64-lightgray.svg) ![Build](https://github.com/dastrobu/vincenty/actions/workflows/ci.yaml/badge.svg) diff --git a/Sources/vincenty/vincenty.swift b/Sources/vincenty/vincenty.swift index 550c501..de5a5e3 100644 --- a/Sources/vincenty/vincenty.swift +++ b/Sources/vincenty/vincenty.swift @@ -41,7 +41,7 @@ public func distance(_ x: (lat: Double, lon: Double), tol: Double = 1e-12, maxIter: UInt = 200, ellipsoid: (a: Double, f: Double) = wgs84) throws -> Double { - return try solveInverse(x, y, tol: tol, maxIter: maxIter, ellipsoid: ellipsoid).distance; + return try solveInverse(x, y, tol: tol, maxIter: maxIter, ellipsoid: ellipsoid).distance } @@ -154,14 +154,16 @@ public func solveInverse(_ x: (lat: Double, lon: Double), let distance = B * a * (sigma - delta_sigma) - //Azimuth calculations: + // Azimuth calculations: let sinSq_sigma = q * q + p * p // note special handling of exactly antipodal points where sin²σ = 0 (due to discontinuity // atan2(0, 0) = 0 but atan2(ε, 0) = π/2 / 90°) - in which case bearing is always meridional, // due north (or due south!) // α = azimuths of the geodesic; α2 the direction P₁ P₂ produced - let a1 = abs(sinSq_sigma) < Double.leastNonzeroMagnitude ? 0 : atan2(cos_u_y * sin(lambda), cos_u_x * sin_u_y - sin_u_x * cos_u_y * cos(lambda)) - let a2 = abs(sinSq_sigma) < Double.leastNonzeroMagnitude ? Double.pi : atan2(cos_u_x * sin(lambda), -sin_u_x * cos_u_y + cos_u_x * sin_u_y * cos(lambda)) + let a1 = abs(sinSq_sigma) < Double.leastNonzeroMagnitude ? 0 : + atan2(cos_u_y * sin(lambda), cos_u_x * sin_u_y - sin_u_x * cos_u_y * cos(lambda)) + let a2 = abs(sinSq_sigma) < Double.leastNonzeroMagnitude ? Double.pi : + atan2(cos_u_x * sin(lambda), -sin_u_x * cos_u_y + cos_u_x * sin_u_y * cos(lambda)) let initialTrueTrack = abs(distance) < Double.leastNonzeroMagnitude ? Double.nan : wrap2pi(a1) let finalTrueTrack = abs(distance) < Double.leastNonzeroMagnitude ? Double.nan : wrap2pi(a2) @@ -189,4 +191,3 @@ private func wrap2pi(_ radians: Double) -> Double { return ((2 * a * x / p).truncatingRemainder(dividingBy: p) + p).truncatingRemainder(dividingBy: p) } - diff --git a/Tests/vincentyTests/vincentyTests.swift b/Tests/vincentyTests/vincentyTests.swift index 87bff5d..292c75d 100644 --- a/Tests/vincentyTests/vincentyTests.swift +++ b/Tests/vincentyTests/vincentyTests.swift @@ -24,7 +24,6 @@ private func nm(fromMeters m: T) -> T { return m / 1852.0 } - /// extension for convenience private extension BinaryFloatingPoint { /// degree converted to radians @@ -111,24 +110,24 @@ final class VincentyTests: XCTestCase { y = (lat: 0.asRad, lon: 0.5.asRad) XCTAssertEqual(try! vincenty.solveInverse(x, y).distance, 111319.491, accuracy: delta) - //Test Cardinals + // Test Cardinals x = (lat: 0.0, lon: 0.0) - y = (lat: pi/2,lon: 0.0) //north pole + y = (lat: pi/2, lon: 0.0) // north pole var (_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y) XCTAssertEqual(initialTrueTrack, 0.0, accuracy: delta) XCTAssertEqual(finalTrueTrack, 0.0, accuracy: delta) - y = (lat: 0.0, lon: pi/2) //east + y = (lat: 0.0, lon: pi/2) // east (_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y) XCTAssertEqual(initialTrueTrack, Double.pi/2, accuracy: delta) XCTAssertEqual(finalTrueTrack, Double.pi/2, accuracy: delta) - y = (lat: -pi/2,lon: 0.0) //south pole + y = (lat: -pi/2, lon: 0.0) // south pole (_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y) XCTAssertEqual(initialTrueTrack, Double.pi, accuracy: delta) XCTAssertEqual(finalTrueTrack, Double.pi, accuracy: delta) - y = (lat: 0.0,lon: -pi/2) //west + y = (lat: 0.0,lon: -pi/2) // west (_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y) XCTAssertEqual(initialTrueTrack, 3*Double.pi/2, accuracy: delta) XCTAssertEqual(finalTrueTrack, 3*Double.pi/2, accuracy: delta) @@ -136,7 +135,7 @@ final class VincentyTests: XCTestCase { } /// Test against A330 FMS - let fmsAcc = 0.49 //within half nm or degree + let fmsAcc = 0.49 // within half nm or degree func testNavigationAccurracy() { var x: (lat: Double, lon: Double), y: (lat: Double, lon: Double) @@ -148,15 +147,14 @@ final class VincentyTests: XCTestCase { XCTAssertEqual(distance.inNm, 197, accuracy: fmsAcc) XCTAssertEqual(initialTrueTrack.asDegrees, 058, accuracy: fmsAcc) - - //Dacey is N5933.6 / W12604.5 + // Dacey is N5933.6 / W12604.5 x = (lat: (59+33.6/60).asRad, lon: -(126+04.5/60).asRad) - //MCT is N5321.4 / W00215.7 + // MCT is N5321.4 / W00215.7 y = (lat: (53+21.4/60).asRad, lon: -(2+15.7/60).asRad) - //TRK036T3507 + // TRK036T3507 (distance, azimuths: (initialTrueTrack, _)) = try! vincenty.solveInverse(x, y) - //XCTAssertEqual(distance.inNm, 3507, accuracy: fmsAcc) //FMS seems to be wrong in this case... - //http://www.gcmap.com/dist?P=N5933.6+W12604.5+-+N5321.4+W00215.7&DU=nm&DM=&SG=450&SU=kts + // XCTAssertEqual(distance.inNm, 3507, accuracy: fmsAcc) //FMS seems to be wrong in this case... + // http://www.gcmap.com/dist?P=N5933.6+W12604.5+-+N5321.4+W00215.7&DU=nm&DM=&SG=450&SU=kts let gDist = geodesic.distance(x, y) print("vincenty: \(distance), geodesic: \(gDist), delta: \(fabs(distance - gDist))") XCTAssertEqual(distance, gDist, accuracy: 1e-3) @@ -164,7 +162,6 @@ final class VincentyTests: XCTestCase { } - /// use geodesic as reference and test vincenty distance. func testAgainstGeodesic() { var x: (lat: Double, lon: Double), y: (lat: Double, lon: Double)