Skip to content

Commit

Permalink
Refactoring (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
fummicc1 authored Nov 24, 2024
1 parent 56d8635 commit 2b6be6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Sources/GeoHashFramework/GeoHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,9 @@ extension GeoHash {
return result
}

public static func getBound(with precision: GeoHashBitsPrecision) -> [GeoHashCoordinate2D] {
// Initial: BottomLeft in zoom-level 0
let baseGeoCoordinate = GeoHash(
binary: String(repeating: "0", count: precision.rawValue),
precision: precision
).coordinate
public func getBound() -> [GeoHashCoordinate2D] {
let baseGeoCoordinate = coordinate
let precision = precision

let latitudeBits = precision.rawValue / 2
let longitudeBits = (precision.rawValue + 1) / 2
Expand Down Expand Up @@ -303,7 +300,11 @@ extension GeoHash {
}

public static func getBounds(with precision: GeoHashBitsPrecision) -> [[GeoHashCoordinate2D]] {
let bound = getBound(with: precision)
// Initial: BottomLeft in zoom-level 0
let bound = GeoHash(
binary: String(repeating: "0", count: precision.rawValue),
precision: precision
).getBound()

let latitudeDelta = bound[0].latitude - bound[3].latitude
let longitudeDelta = bound[1].longitude - bound[0].longitude
Expand Down
6 changes: 5 additions & 1 deletion Tests/GeoHashFrameworkTests/GeoHashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ struct GeoHashTests {

@Test
func getBound() async throws {
let actual = GeoHash.getBound(with: .exact(digits: 0))
let precision = GeoHashBitsPrecision.exact(digits: 0)
let actual = GeoHash(
binary: String(repeating: "0", count: precision.rawValue),
precision: precision
).getBound()
let expected = [
GeoHashCoordinate2D(
latitude: 90.0,
Expand Down

0 comments on commit 2b6be6d

Please sign in to comment.