Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
28 changes: 14 additions & 14 deletions Sources/SwiftH3/H3Index.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

/**
Expand All @@ -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
}
Expand All @@ -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))
}

Expand All @@ -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) }
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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 }
Expand All @@ -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)
}

Expand All @@ -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!)
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftH3Tests/H3IndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
}
2 changes: 1 addition & 1 deletion Tests/SwiftH3Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XCTest
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(SwiftH3Tests.allTests),
testCase(H3IndexTests.allTests),
]
}
#endif
Loading