Skip to content

Commit

Permalink
All remaining subcommands for the h3 cli program (#924)
Browse files Browse the repository at this point in the history
* areNeighborCells

* cellsToDirectedEdge

* isValidDirectedEdge

* getDirectedEdgeOrigin

* getDirectedEdgeDestination

* directedEdgeToCells

* originToDirectedEdges

* directedEdgeToBoundary

* cellToVertex

* cellToVertexes

* vertexToLatLng

* isValidVertex

* degsToRads radsToDegs

* getHexagonAreaAvgKm2

* getHexagonAreaAvgM2

* cellAreaRads2

* cellAreaKm2

* cellAreaM2

* getHexagonEdgeLengthAvgKm

* getHexagonEdgeLengthAvgM

* edgeLengthKm

* edgeLengthM

* edgeLengthRads

* getNumCells

* getRes0Cells

* getPentagons

* pentagonCount

* greatCircleDistanceKm

* greatCircleDistanceM

* greatCircleDistanceRads

* describeH3Error

* Add some forgotten free() calls

* Fix missing free()s in error paths

* Add some rounding to a test that's failing on MacOS on ARM

* Update src/apps/filters/h3.c

Co-authored-by: Isaac Brodsky <isaac@isaacbrodsky.com>

* Apply suggestions from code review

Co-authored-by: Isaac Brodsky <isaac@isaacbrodsky.com>

* BUFFER_SIZE for a few more constants

---------

Co-authored-by: Isaac Brodsky <isaac@isaacbrodsky.com>
  • Loading branch information
dfellis and isaacbrodsky authored Oct 16, 2024
1 parent 33681ff commit a434272
Show file tree
Hide file tree
Showing 34 changed files with 913 additions and 0 deletions.
843 changes: 843 additions & 0 deletions src/apps/filters/h3.c

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/cli/areNeighborCells.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_h3_cli_test(testCliAreNeighborCells "areNeighborCells -o 85283473fffffff -d 85283477fffffff" "true")
add_h3_cli_test(testCliAreNotNeighborCells "areNeighborCells -o 85283473fffffff -d 85283472fffffff" "false")
add_h3_cli_test(testCliAreNeighborNotCells "areNeighborCells -o 85283473fffffff -d 852834727fffffff 2>&1" "Error 5: Cell argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/cellAreaKm2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliCellAreaKm2 "cellAreaKm2 -c 85283473fffffff" "265.0925581283")
add_h3_cli_test(testCliNotCellAreaKm2 "cellAreaKm2 -c 115283473fffffff 2>&1" "Error 5: Cell argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/cellAreaM2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliCellAreaM2 "cellAreaM2 -c 85283473fffffff | xargs printf '%.3f'" "265092558.128")
add_h3_cli_test(testCliNotCellAreaM2 "cellAreaM2 -c 115283473fffffff 2>&1" "Error 5: Cell argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/cellAreaRads2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliCellAreaRads2 "cellAreaRads2 -c 85283473fffffff" "0.0000065310")
add_h3_cli_test(testCliNotCellAreaRads2 "cellAreaRads2 -c 115283473fffffff 2>&1" "Error 5: Cell argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/cellToVertex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliCellToVertex "cellToVertex -c 85283473fffffff -v 0" "22528340bfffffff")
add_h3_cli_test(testCliNotCellToVertex "cellToVertex -c 115283473fffffff -v 0 2>&1" "Error 5: Cell argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/cellToVertexes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliCellToVertexes "cellToVertexes -c 85283473fffffff" "[22528340bfffffff, 235283447fffffff, 205283463fffffff, 255283463fffffff, 22528340ffffffff, 23528340bfffffff]")
add_h3_cli_test(testCliNotCellToVertexes "cellToVertexes -c 115283473fffffff 2>&1" "Error 5: Cell argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/cellsToDirectedEdge.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliCellsToDirectedEdge "cellsToDirectedEdge -o 85283473fffffff -d 85283477fffffff" "115283473fffffff")
add_h3_cli_test(testCliCellsNotToDirectedEdge "cellsToDirectedEdge -o 85283473fffffff -d 85283472fffffff 2>&1" "Error 11: Cell arguments were not neighbors")
1 change: 1 addition & 0 deletions tests/cli/degsToRads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_h3_cli_test(testCliDegsToRads "degsToRads -d 180" "3.1415926536")
4 changes: 4 additions & 0 deletions tests/cli/describeH3Error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_h3_cli_test(testCliDescribeH3Error0 "describeH3Error -e 0" "Success")
add_h3_cli_test(testCliDescribeH3Error10 "describeH3Error -e 10" "Duplicate input")
add_h3_cli_test(testCliDescribeH3Error13 "describeH3Error -e 13" "Memory allocation failed")
add_h3_cli_test(testCliDescribeH3Error100 "describeH3Error -e 100" "Invalid error code")
2 changes: 2 additions & 0 deletions tests/cli/directedEdgeToBoundary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliDirectedEdgeToBoundary "directedEdgeToBoundary -c 115283473fffffff" "POLYGON((-122.0377349643 37.4201286777, -122.0904289290 37.3375560844, -122.0377349643 37.4201286777))")
add_h3_cli_test(testCliNotDirectedEdgeToBoundary "directedEdgeToBoundary -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/directedEdgeToCells.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliDirectedEdgeToCells "directedEdgeToCells -c 115283473fffffff" "[85283473fffffff, 85283477fffffff]")
add_h3_cli_test(testCliNotDirectedEdgeToCells "directedEdgeToCells -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/edgeLengthKm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliEdgeLengthKm "edgeLengthKm -c 115283473fffffff" "10.2947360862")
add_h3_cli_test(testCliNotEdgeLengthKm "edgeLengthKm -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/edgeLengthM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliEdgeLengthM "edgeLengthM -c 115283473fffffff" "10294.7360861995")
add_h3_cli_test(testCliNotEdgeLengthM "edgeLengthM -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/edgeLengthRads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliEdgeLengthRads "edgeLengthRads -c 115283473fffffff" "0.0016158726")
add_h3_cli_test(testCliNotEdgeLengthRads "edgeLengthRads -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/getDirectedEdgeDestination.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetDirectedEdgeDestination "getDirectedEdgeDestination -c 115283473fffffff" "85283477fffffff")
add_h3_cli_test(testCliDoNotGetDirectedEdgeDestination "getDirectedEdgeDestination -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/getDirectedEdgeOrigin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetDirectedEdgeOrigin "getDirectedEdgeOrigin -c 115283473fffffff" "85283473fffffff")
add_h3_cli_test(testCliDoNotGetDirectedEdgeOrigin "getDirectedEdgeOrigin -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid")
2 changes: 2 additions & 0 deletions tests/cli/getHexagonAreaAvgKm2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetHexagonAreaAvgKm2 "getHexagonAreaAvgKm2 -r 0" "4357449.4160783831")
add_h3_cli_test(testCliDontGetHexagonAreaAvgKm2 "getHexagonAreaAvgKm2 -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range")
2 changes: 2 additions & 0 deletions tests/cli/getHexagonAreaAvgM2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetHexagonAreaAvgM2 "getHexagonAreaAvgM2 -r 0" "4357449416078.3901367188")
add_h3_cli_test(testCliDontGetHexagonAreaAvgM2 "getHexagonAreaAvgM2 -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range")
2 changes: 2 additions & 0 deletions tests/cli/getHexagonEdgeLengthAvgKm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetHexagonEdgeLengthAvgKm "getHexagonEdgeLengthAvgKm -r 0" "1281.2560110000")
add_h3_cli_test(testCliDontGetHexagonEdgeLengthAvgKm "getHexagonEdgeLengthAvgKm -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range")
2 changes: 2 additions & 0 deletions tests/cli/getHexagonEdgeLengthAvgM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetHexagonEdgeLengthAvgM "getHexagonEdgeLengthAvgM -r 0" "1281256.0109999999")
add_h3_cli_test(testCliDontGetHexagonEdgeLengthAvgM "getHexagonEdgeLengthAvgM -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range")
2 changes: 2 additions & 0 deletions tests/cli/getNumCells.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetNumCells "getNumCells -r 0" "122")
add_h3_cli_test(testCliDontGetNumCells "getNumCells -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range")
2 changes: 2 additions & 0 deletions tests/cli/getPentagons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliGetPentagons "getPentagons -r 0" "[8009fffffffffff, 801dfffffffffff, 8031fffffffffff, 804dfffffffffff, 8063fffffffffff, 8075fffffffffff, 807ffffffffffff, 8091fffffffffff, 80a7fffffffffff, 80c3fffffffffff, 80d7fffffffffff, 80ebfffffffffff]")
add_h3_cli_test(testCliDontGetPentagons "getPentagons -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range")
1 change: 1 addition & 0 deletions tests/cli/getRes0Cells.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_h3_cli_test(testCliGetRes0Cells "getRes0Cells" "[8001fffffffffff, 8003fffffffffff, 8005fffffffffff, 8007fffffffffff, 8009fffffffffff, 800bfffffffffff, 800dfffffffffff, 800ffffffffffff, 8011fffffffffff, 8013fffffffffff, 8015fffffffffff, 8017fffffffffff, 8019fffffffffff, 801bfffffffffff, 801dfffffffffff, 801ffffffffffff, 8021fffffffffff, 8023fffffffffff, 8025fffffffffff, 8027fffffffffff, 8029fffffffffff, 802bfffffffffff, 802dfffffffffff, 802ffffffffffff, 8031fffffffffff, 8033fffffffffff, 8035fffffffffff, 8037fffffffffff, 8039fffffffffff, 803bfffffffffff, 803dfffffffffff, 803ffffffffffff, 8041fffffffffff, 8043fffffffffff, 8045fffffffffff, 8047fffffffffff, 8049fffffffffff, 804bfffffffffff, 804dfffffffffff, 804ffffffffffff, 8051fffffffffff, 8053fffffffffff, 8055fffffffffff, 8057fffffffffff, 8059fffffffffff, 805bfffffffffff, 805dfffffffffff, 805ffffffffffff, 8061fffffffffff, 8063fffffffffff, 8065fffffffffff, 8067fffffffffff, 8069fffffffffff, 806bfffffffffff, 806dfffffffffff, 806ffffffffffff, 8071fffffffffff, 8073fffffffffff, 8075fffffffffff, 8077fffffffffff, 8079fffffffffff, 807bfffffffffff, 807dfffffffffff, 807ffffffffffff, 8081fffffffffff, 8083fffffffffff, 8085fffffffffff, 8087fffffffffff, 8089fffffffffff, 808bfffffffffff, 808dfffffffffff, 808ffffffffffff, 8091fffffffffff, 8093fffffffffff, 8095fffffffffff, 8097fffffffffff, 8099fffffffffff, 809bfffffffffff, 809dfffffffffff, 809ffffffffffff, 80a1fffffffffff, 80a3fffffffffff, 80a5fffffffffff, 80a7fffffffffff, 80a9fffffffffff, 80abfffffffffff, 80adfffffffffff, 80affffffffffff, 80b1fffffffffff, 80b3fffffffffff, 80b5fffffffffff, 80b7fffffffffff, 80b9fffffffffff, 80bbfffffffffff, 80bdfffffffffff, 80bffffffffffff, 80c1fffffffffff, 80c3fffffffffff, 80c5fffffffffff, 80c7fffffffffff, 80c9fffffffffff, 80cbfffffffffff, 80cdfffffffffff, 80cffffffffffff, 80d1fffffffffff, 80d3fffffffffff, 80d5fffffffffff, 80d7fffffffffff, 80d9fffffffffff, 80dbfffffffffff, 80ddfffffffffff, 80dffffffffffff, 80e1fffffffffff, 80e3fffffffffff, 80e5fffffffffff, 80e7fffffffffff, 80e9fffffffffff, 80ebfffffffffff, 80edfffffffffff, 80effffffffffff, 80f1fffffffffff, 80f3fffffffffff]")
4 changes: 4 additions & 0 deletions tests/cli/greatCircleDistanceKm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_h3_cli_test(testCliGreatCircleDistanceKmArg "greatCircleDistanceKm -c '[[0, 1], [1, 2]]'" "157.2495585118")
add_h3_cli_test(testCliGreatCircleDistanceKmFile "greatCircleDistanceKm -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157.2495585118")
add_h3_cli_test(testCliGreatCircleDistanceKmStdin "greatCircleDistanceKm -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157.2495585118")
add_h3_cli_test(testCliGreatCircleDistanceKmBadArg "greatCircleDistanceKm -c '[[0, 1]]' 2>&1" "Only two pairs of coordinates should be provided.")
4 changes: 4 additions & 0 deletions tests/cli/greatCircleDistanceM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_h3_cli_test(testCliGreatCircleDistanceMArg "greatCircleDistanceM -c '[[0, 1], [1, 2]]'" "157249.5585117787")
add_h3_cli_test(testCliGreatCircleDistanceMFile "greatCircleDistanceM -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157249.5585117787")
add_h3_cli_test(testCliGreatCircleDistanceMStdin "greatCircleDistanceM -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157249.5585117787")
add_h3_cli_test(testCliGreatCircleDistanceMBadArg "greatCircleDistanceM -c '[[0, 1]]' 2>&1" "Only two pairs of coordinates should be provided.")
4 changes: 4 additions & 0 deletions tests/cli/greatCircleDistanceRads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_h3_cli_test(testCliGreatCircleDistanceRadsArg "greatCircleDistanceRads -c '[[0, 1], [1, 2]]'" "0.0246820564")
add_h3_cli_test(testCliGreatCircleDistanceRadsFile "greatCircleDistanceRads -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "0.0246820564")
add_h3_cli_test(testCliGreatCircleDistanceRadsStdin "greatCircleDistanceRads -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "0.0246820564")
add_h3_cli_test(testCliGreatCircleDistanceRadsBadArg "greatCircleDistanceRads -c '[[0, 1]]' 2>&1" "Only two pairs of coordinates should be provided.")
2 changes: 2 additions & 0 deletions tests/cli/isValidDirectedEdge.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliIsValidDirectedEdge "isValidDirectedEdge -c 115283473fffffff" "true")
add_h3_cli_test(testCliIsNotValidDirectedEdge "isValidDirectedEdge -c 85283473fffffff" "false")
2 changes: 2 additions & 0 deletions tests/cli/isValidVertex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliIsValidVertex "isValidVertex -c 22528340bfffffff" "true")
add_h3_cli_test(testCliIsNotValidVertex "isValidVertex -c 85283473fffffff" "false")
2 changes: 2 additions & 0 deletions tests/cli/originToDirectedEdges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliOriginToDirectedEdges "originToDirectedEdges -c 85283473fffffff" "[115283473fffffff, 125283473fffffff, 135283473fffffff, 145283473fffffff, 155283473fffffff, 165283473fffffff]")
add_h3_cli_test(testCliNotOriginToDirectedEdges "originToDirectedEdges -c 115283473fffffff 2>&1" "Error 5: Cell argument was not valid")
1 change: 1 addition & 0 deletions tests/cli/pentagonCount.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_h3_cli_test(testCliPentagonCount "pentagonCount" "12")
1 change: 1 addition & 0 deletions tests/cli/radsToDegs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_h3_cli_test(testCliRadsToDegs "radsToDegs -r 3.1415926536" "180.0000000006")
2 changes: 2 additions & 0 deletions tests/cli/vertexToLatLng.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_h3_cli_test(testCliVertexToLatLng "vertexToLatLng -c 22528340bfffffff" "POINT(-121.9150803271 37.2713558667)")
add_h3_cli_test(testCliNotVertexToLatLng "vertexToLatLng -c 85283473fffffff 2>&1" "Error 8: Vertex argument was not valid")
1 change: 1 addition & 0 deletions tests/inputfiles/great_circle_distance.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[0, 1], [1, 2]]

0 comments on commit a434272

Please sign in to comment.