From 6cb4eca9fb20baf235b38cb8c3632d0422c3a129 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Fri, 14 Feb 2025 15:45:28 +1100 Subject: [PATCH 1/2] Add `GeoJSON.LineString(encodedPolyline: String)` --- .../GeoJSON+LineString+DecodePolyline.swift | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Sources/GeoJSONKitTurf/GeoJSON+LineString+DecodePolyline.swift diff --git a/Sources/GeoJSONKitTurf/GeoJSON+LineString+DecodePolyline.swift b/Sources/GeoJSONKitTurf/GeoJSON+LineString+DecodePolyline.swift new file mode 100644 index 0000000..a48cd98 --- /dev/null +++ b/Sources/GeoJSONKitTurf/GeoJSON+LineString+DecodePolyline.swift @@ -0,0 +1,63 @@ +// +// GeoJSON+LineString+DecodePolylineString.swift +// +// Created by Adrian Schoenig on 18/2/17. +// +// +import Foundation + +import GeoJSONKit + +extension GeoJSON.LineString { + public init(encodedPolyline: String) { + let bytes = encodedPolyline.utf8CString + let length = bytes.count - 1 // ignore 0 at end + var idx = 0 + + var array: [GeoJSON.Position] = [] + + var latitude = 0.0 + var longitude = 0.0 + while idx < length { + var byte = 0 + var res = 0 + var shift = 0 + + repeat { + if idx > length { + break + } + byte = Int(bytes[idx]) - 63 + idx += 1 + res |= (byte & 0x1F) << shift + shift += 5 + } while byte >= 0x20 + + let deltaLat = ((res & 1) != 0 ? ~(res >> 1) : (res >> 1)); + latitude += Double(deltaLat) + + shift = 0 + res = 0 + + repeat { + if idx > length { + break + } + byte = Int(bytes[idx]) - 0x3F + idx += 1 + res |= (byte & 0x1F) << shift + shift += 5 + } while byte >= 0x20 + + let deltaLon = ((res & 1) != 0 ? ~(res >> 1) : (res >> 1)); + longitude += Double(deltaLon) + + let finalLat = latitude * 1E-5 + let finalLon = longitude * 1E-5 + let coordinate = GeoJSON.Position(latitude: finalLat, longitude: finalLon) + array.append(coordinate) + } + + self.init(positions: array) + } +} From 6772767369b03fb5c676fec6aebe7d8c92db0242 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Fri, 14 Feb 2025 15:46:36 +1100 Subject: [PATCH 2/2] Update GHA, test newer Swifts --- .github/workflows/swift.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index c17258c..cc16b7e 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -10,7 +10,7 @@ jobs: macos: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: swift build - name: Test @@ -21,12 +21,12 @@ jobs: strategy: matrix: - swift: ["5.9.1", "5.7.3"] + swift: ["6.0", "5.10", "5.9", "5.8"] container: image: swift:${{ matrix.swift }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: swift build - name: Test