Skip to content

Commit d1169f0

Browse files
authored
Merge pull request #23 from dastrobu/build_with_Swift_5.9
build with Swift 5.9
2 parents 825cc83 + 7ff24d4 commit d1169f0

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010
- uses: norio-nomura/[email protected]
1111
macos-test:
1212
strategy:
@@ -15,7 +15,7 @@ jobs:
1515
- "5.7"
1616
runs-on: macos-latest
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919
- uses: swift-actions/setup-swift@v1
2020
with:
2121
swift-version: ${{ matrix.swift-version }}
@@ -24,6 +24,8 @@ jobs:
2424
strategy:
2525
matrix:
2626
swift-version:
27+
- "5.9"
28+
- "5.8"
2729
- "5.7"
2830
- "5.6"
2931
- "5.5"
@@ -40,5 +42,5 @@ jobs:
4042
ios-build:
4143
runs-on: macos-latest
4244
steps:
43-
- uses: actions/checkout@v3
45+
- uses: actions/checkout@v4
4446
- run: xcodebuild -scheme vincenty -destination 'platform=iOS Simulator,name=iPhone 13'

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
targets: ["vincenty"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/dastrobu/geodesic.git", from: "1.3.0"),
13+
.package(url: "https://github.com/dastrobu/geodesic.git", from: "1.4.0"),
1414
],
1515
targets: [
1616
.target(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# vincenty
22

3-
[![Swift Version](https://img.shields.io/badge/swift-5.7-blue.svg)](https://swift.org)
3+
[![Swift Version](https://img.shields.io/badge/swift-5.9-blue.svg)](https://swift.org)
44
![Platform](https://img.shields.io/badge/platform-macOS|linux--64-lightgray.svg)
55
![Build](https://github.com/dastrobu/vincenty/actions/workflows/ci.yaml/badge.svg)
66

Sources/vincenty/vincenty.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public func distance(_ x: (lat: Double, lon: Double),
4141
tol: Double = 1e-12,
4242
maxIter: UInt = 200,
4343
ellipsoid: (a: Double, f: Double) = wgs84) throws -> Double {
44-
return try solveInverse(x, y, tol: tol, maxIter: maxIter, ellipsoid: ellipsoid).distance;
44+
return try solveInverse(x, y, tol: tol, maxIter: maxIter, ellipsoid: ellipsoid).distance
4545
}
4646

4747

@@ -154,14 +154,16 @@ public func solveInverse(_ x: (lat: Double, lon: Double),
154154

155155
let distance = B * a * (sigma - delta_sigma)
156156

157-
//Azimuth calculations:
157+
// Azimuth calculations:
158158
let sinSq_sigma = q * q + p * p
159159
// note special handling of exactly antipodal points where sin²σ = 0 (due to discontinuity
160160
// atan2(0, 0) = 0 but atan2(ε, 0) = π/2 / 90°) - in which case bearing is always meridional,
161161
// due north (or due south!)
162162
// α = azimuths of the geodesic; α2 the direction P₁ P₂ produced
163-
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))
164-
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))
163+
let a1 = abs(sinSq_sigma) < Double.leastNonzeroMagnitude ? 0 :
164+
atan2(cos_u_y * sin(lambda), cos_u_x * sin_u_y - sin_u_x * cos_u_y * cos(lambda))
165+
let a2 = abs(sinSq_sigma) < Double.leastNonzeroMagnitude ? Double.pi :
166+
atan2(cos_u_x * sin(lambda), -sin_u_x * cos_u_y + cos_u_x * sin_u_y * cos(lambda))
165167

166168
let initialTrueTrack = abs(distance) < Double.leastNonzeroMagnitude ? Double.nan : wrap2pi(a1)
167169
let finalTrueTrack = abs(distance) < Double.leastNonzeroMagnitude ? Double.nan : wrap2pi(a2)
@@ -189,4 +191,3 @@ private func wrap2pi(_ radians: Double) -> Double {
189191

190192
return ((2 * a * x / p).truncatingRemainder(dividingBy: p) + p).truncatingRemainder(dividingBy: p)
191193
}
192-

Tests/vincentyTests/vincentyTests.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ private func nm<T: BinaryFloatingPoint>(fromMeters m: T) -> T {
2424
return m / 1852.0
2525
}
2626

27-
2827
/// extension for convenience
2928
private extension BinaryFloatingPoint {
3029
/// degree converted to radians
@@ -111,32 +110,32 @@ final class VincentyTests: XCTestCase {
111110
y = (lat: 0.asRad, lon: 0.5.asRad)
112111
XCTAssertEqual(try! vincenty.solveInverse(x, y).distance, 111319.491, accuracy: delta)
113112

114-
//Test Cardinals
113+
// Test Cardinals
115114
x = (lat: 0.0, lon: 0.0)
116-
y = (lat: pi/2,lon: 0.0) //north pole
115+
y = (lat: pi/2, lon: 0.0) // north pole
117116
var (_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y)
118117
XCTAssertEqual(initialTrueTrack, 0.0, accuracy: delta)
119118
XCTAssertEqual(finalTrueTrack, 0.0, accuracy: delta)
120119

121-
y = (lat: 0.0, lon: pi/2) //east
120+
y = (lat: 0.0, lon: pi/2) // east
122121
(_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y)
123122
XCTAssertEqual(initialTrueTrack, Double.pi/2, accuracy: delta)
124123
XCTAssertEqual(finalTrueTrack, Double.pi/2, accuracy: delta)
125124

126-
y = (lat: -pi/2,lon: 0.0) //south pole
125+
y = (lat: -pi/2, lon: 0.0) // south pole
127126
(_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y)
128127
XCTAssertEqual(initialTrueTrack, Double.pi, accuracy: delta)
129128
XCTAssertEqual(finalTrueTrack, Double.pi, accuracy: delta)
130129

131-
y = (lat: 0.0,lon: -pi/2) //west
130+
y = (lat: 0.0,lon: -pi/2) // west
132131
(_, azimuths: (initialTrueTrack, finalTrueTrack)) = try! vincenty.solveInverse(x, y)
133132
XCTAssertEqual(initialTrueTrack, 3*Double.pi/2, accuracy: delta)
134133
XCTAssertEqual(finalTrueTrack, 3*Double.pi/2, accuracy: delta)
135134

136135
}
137136

138137
/// Test against A330 FMS
139-
let fmsAcc = 0.49 //within half nm or degree
138+
let fmsAcc = 0.49 // within half nm or degree
140139
func testNavigationAccurracy() {
141140

142141
var x: (lat: Double, lon: Double), y: (lat: Double, lon: Double)
@@ -148,23 +147,21 @@ final class VincentyTests: XCTestCase {
148147
XCTAssertEqual(distance.inNm, 197, accuracy: fmsAcc)
149148
XCTAssertEqual(initialTrueTrack.asDegrees, 058, accuracy: fmsAcc)
150149

151-
152-
//Dacey is N5933.6 / W12604.5
150+
// Dacey is N5933.6 / W12604.5
153151
x = (lat: (59+33.6/60).asRad, lon: -(126+04.5/60).asRad)
154-
//MCT is N5321.4 / W00215.7
152+
// MCT is N5321.4 / W00215.7
155153
y = (lat: (53+21.4/60).asRad, lon: -(2+15.7/60).asRad)
156-
//TRK036T3507
154+
// TRK036T3507
157155
(distance, azimuths: (initialTrueTrack, _)) = try! vincenty.solveInverse(x, y)
158-
//XCTAssertEqual(distance.inNm, 3507, accuracy: fmsAcc) //FMS seems to be wrong in this case...
159-
//http://www.gcmap.com/dist?P=N5933.6+W12604.5+-+N5321.4+W00215.7&DU=nm&DM=&SG=450&SU=kts
156+
// XCTAssertEqual(distance.inNm, 3507, accuracy: fmsAcc) //FMS seems to be wrong in this case...
157+
// http://www.gcmap.com/dist?P=N5933.6+W12604.5+-+N5321.4+W00215.7&DU=nm&DM=&SG=450&SU=kts
160158
let gDist = geodesic.distance(x, y)
161159
print("vincenty: \(distance), geodesic: \(gDist), delta: \(fabs(distance - gDist))")
162160
XCTAssertEqual(distance, gDist, accuracy: 1e-3)
163161
XCTAssertEqual(initialTrueTrack.asDegrees, 036, accuracy: fmsAcc)
164162

165163
}
166164

167-
168165
/// use geodesic as reference and test vincenty distance.
169166
func testAgainstGeodesic() {
170167
var x: (lat: Double, lon: Double), y: (lat: Double, lon: Double)

0 commit comments

Comments
 (0)