Skip to content

Commit

Permalink
build with Swift 5.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dastrobu committed Dec 17, 2023
1 parent 825cc83 commit 7ff24d4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand All @@ -24,6 +24,8 @@ jobs:
strategy:
matrix:
swift-version:
- "5.9"
- "5.8"
- "5.7"
- "5.6"
- "5.5"
Expand All @@ -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'
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
11 changes: 6 additions & 5 deletions Sources/vincenty/vincenty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Check warning on line 47 in Sources/vincenty/vincenty.swift

View workflow job for this annotation

GitHub Actions / lint

Vertical Whitespace Violation: Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -189,4 +191,3 @@ private func wrap2pi(_ radians: Double) -> Double {

return ((2 * a * x / p).truncatingRemainder(dividingBy: p) + p).truncatingRemainder(dividingBy: p)
}

25 changes: 11 additions & 14 deletions Tests/vincentyTests/vincentyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ private func nm<T: BinaryFloatingPoint>(fromMeters m: T) -> T {
return m / 1852.0
}


/// extension for convenience
private extension BinaryFloatingPoint {
/// degree converted to radians
Expand Down Expand Up @@ -111,32 +110,32 @@ 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

Check warning on line 130 in Tests/vincentyTests/vincentyTests.swift

View workflow job for this annotation

GitHub Actions / lint

Comma Spacing Violation: There should be no space before and one after any comma (comma)
(_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y)
XCTAssertEqual(initialTrueTrack, 3*Double.pi/2, accuracy: delta)
XCTAssertEqual(finalTrueTrack, 3*Double.pi/2, accuracy: delta)

}

/// 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)
Expand All @@ -148,23 +147,21 @@ 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)
XCTAssertEqual(initialTrueTrack.asDegrees, 036, accuracy: fmsAcc)

}


/// use geodesic as reference and test vincenty distance.
func testAgainstGeodesic() {
var x: (lat: Double, lon: Double), y: (lat: Double, lon: Double)
Expand Down

0 comments on commit 7ff24d4

Please sign in to comment.