diff --git a/Package.resolved b/Package.resolved index 7968d2a..a23d698 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,9 +5,9 @@ "package": "Ch3", "repositoryURL": "https://github.com/bdotdub/Ch3.git", "state": { - "branch": null, - "revision": "c9bb49bc6801e745f0c7ac135855cda09dbb4536", - "version": "3.6.0" + "branch": "v4.2.1", + "revision": "0000000000000000000000000000000000000000", + "version": null } } ] diff --git a/Package.swift b/Package.swift index 38bd5fe..4fce829 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.5 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -11,7 +11,7 @@ let package = Package( targets: ["SwiftH3"]), ], dependencies: [ - .package(url: "https://github.com/bdotdub/Ch3.git", from: "3.6.0") + .package(url: "https://github.com/bdotdub/Ch3.git", branch: "v4.2.1") ], targets: [ .target( diff --git a/Sources/SwiftH3/H3Index.swift b/Sources/SwiftH3/H3Index.swift index 4b4effe..6060608 100644 --- a/Sources/SwiftH3/H3Index.swift +++ b/Sources/SwiftH3/H3Index.swift @@ -25,8 +25,8 @@ public struct H3Index { - resolution: The resolution */ public init(coordinate: H3Coordinate, resolution: Int32) { - var coord = GeoCoord(lat: degsToRads(coordinate.lat), lon: degsToRads(coordinate.lon)) - self.value = geoToH3(&coord, Int32(resolution)) + var coord = LatLng(lat: degsToRads(coordinate.lat), lon: degsToRads(coordinate.lon)) + self.value = latLngToCell(&coord, Int32(resolution)) } /** @@ -38,7 +38,7 @@ public struct H3Index { public init(string: String) { var value: UInt64 = 0 string.withCString { ptr in - value = stringToH3(ptr) + value = stringToCell(ptr) } self.value = value } @@ -51,18 +51,18 @@ extension H3Index { /// The resolution of the index public var resolution: Int { - return Int(h3GetResolution(value)) + return Int(cellToResolution(value)) } /// Indicates whether this is a valid H3 index public var isValid: Bool { - return h3IsValid(value) == 1 + return isValidCell(value) == 1 } /// The coordinate that this index represents public var coordinate: H3Coordinate { - var coord = GeoCoord() - h3ToGeo(value, &coord) + var coord = LatLng() + cellToLatLng(value, &coord) return H3Coordinate(lat: radsToDegs(coord.lat), lon: radsToDegs(coord.lon)) } @@ -80,9 +80,9 @@ extension H3Index { - Returns: A list of indices. Can be empty. */ public func kRingIndices(ringK: Int32) -> [H3Index] { - var indices = [UInt64](repeating: 0, count: Int(maxKringSize(ringK))) + var indices = [UInt64](repeating: 0, count: Int(maxGridDiskSize(ringK))) indices.withUnsafeMutableBufferPointer { ptr in - kRing(value, ringK, ptr.baseAddress) + gridDisk(value, ringK, ptr.baseAddress) } return indices.map { H3Index($0) } } @@ -111,7 +111,7 @@ extension H3Index { /// - Returns: The parent index at that resolution. /// Can be nil if invalid public func parent(at resolution: Int) -> H3Index? { - let val = h3ToParent(value, Int32(resolution)) + let val = cellToParent(value, Int32(resolution)) return val == H3Index.invalidIndex ? nil : H3Index(val) } @@ -123,10 +123,10 @@ extension H3Index { public func children(at resolution: Int) -> [H3Index] { var children = [UInt64]( repeating: 0, - count: Int(maxH3ToChildrenSize(value, Int32(resolution))) + count: Int(maxCellToChildrenSize(value, Int32(resolution))) ) children.withUnsafeMutableBufferPointer { ptr in - h3ToChildren(value, Int32(resolution), ptr.baseAddress) + cellToChildren(value, Int32(resolution), ptr.baseAddress) } return children .filter { $0 != 0 } @@ -140,7 +140,7 @@ extension H3Index { /// - Returns: The center child index at that resolution. /// Can be nil if invalid public func centerChild(at resolution: Int) -> H3Index? { - let index = h3ToCenterChild(value, Int32(resolution)) + let index = cellToCenterChild(value, Int32(resolution)) return index == H3Index.invalidIndex ? nil : H3Index(index) } @@ -151,7 +151,7 @@ extension H3Index: CustomStringConvertible { /// String description of the index public var description: String { let cString = strdup("") - h3ToString(value, cString, 17) + cellToString(value, cString, 17) return String(cString: cString!) } diff --git a/Tests/SwiftH3Tests/H3IndexTests.swift b/Tests/SwiftH3Tests/H3IndexTests.swift index 2523e72..bd19129 100644 --- a/Tests/SwiftH3Tests/H3IndexTests.swift +++ b/Tests/SwiftH3Tests/H3IndexTests.swift @@ -117,7 +117,14 @@ final class H3IndexTests: XCTestCase { ("testStringToH3Index", testStringToH3Index), ("testCoordToH3Index", testCoordToH3Index), ("testIsValid", testIsValid), + ("testH3IndexToString", testH3IndexToString), ("testResolution", testResolution), ("testToCoord", testToCoord), + ("testKRingIndices", testKRingIndices), + ("testParent", testParent), + ("testDirectParent", testDirectParent), + ("testChildren", testChildren), + ("testCenterChild", testCenterChild), + ("testDirectCenterChild", testDirectCenterChild), ] } diff --git a/Tests/SwiftH3Tests/XCTestManifests.swift b/Tests/SwiftH3Tests/XCTestManifests.swift index e5add71..55e2ab0 100644 --- a/Tests/SwiftH3Tests/XCTestManifests.swift +++ b/Tests/SwiftH3Tests/XCTestManifests.swift @@ -3,7 +3,7 @@ import XCTest #if !canImport(ObjectiveC) public func allTests() -> [XCTestCaseEntry] { return [ - testCase(SwiftH3Tests.allTests), + testCase(H3IndexTests.allTests), ] } #endif