Skip to content

Commit

Permalink
feat: added vertex to lat lng method
Browse files Browse the repository at this point in the history
  • Loading branch information
mojixcoder committed Aug 17, 2024
1 parent 04a1868 commit 4b62928
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func ExampleLatLngToCell() {
| `directedEdgeToBoundary` | `DirectedEdge#Boundary` |
| `cellToVertex` | `CellToVertex` |
| `cellToVertexes` | `cellToVertexes` |
| `vertexToLatLng` | TODO |
| `vertexToLatLng` | `VertexToLatLng` |
| `isValidVertex` | `IsValidVertex` |
| `gridDistance` | `GridDistance`, `Cell#GridDistance` |
| `gridPathCells` | `GridPath`, `Cell#GridPath` |
Expand Down
7 changes: 7 additions & 0 deletions h3.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@ func CellToVertexes(c Cell) []Cell {
return cellsFromC(out, true, false)
}

func VertexToLatLng(vertex Cell) LatLng {
var out C.LatLng
C.vertexToLatLng(C.H3Index(vertex), &out)

return latLngFromC(out)
}

func IsValidVertex(c Cell) bool {
return C.isValidVertex(C.H3Index(c)) == 1
}
Expand Down
19 changes: 19 additions & 0 deletions h3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,25 @@ func TestCellToVertexes(t *testing.T) {
}
}

func TestVertexToLatLng(t *testing.T) {

Check failure on line 666 in h3_test.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

TestVertexToLatLng's subtests should call t.Parallel (tparallel)
t.Parallel()

testCases := []struct {
vertex Cell
expectedLatLng LatLng
}{
{vertex: CellToVertex(validCell, 0), expectedLatLng: LatLng{Lat: 67.22475, Lng: -168.52301}},
{vertex: -1, expectedLatLng: LatLng{}}, // Invalid vertex.
}

for i, tc := range testCases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
latLng := VertexToLatLng(tc.vertex)
assertEqualLatLng(t, tc.expectedLatLng, latLng)
})
}
}

func TestIsValidVertex(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 4b62928

Please sign in to comment.