From ebcfaef52a902db341012cd805cbe5d9e5b7cdfb Mon Sep 17 00:00:00 2001 From: Justin Hwang Date: Thu, 19 Nov 2026 14:14:49 -0500 Subject: [PATCH] cli: add edgeToVertexes Expose edgeToVertexes, added to the library in 4.6.0, as an h3 CLI subcommand. It takes a directed edge and prints its start and end vertexes, in the same formats as directedEdgeToCells. Closes #1324 Co-Authored-By: Claude Code --- CHANGELOG.md | 2 ++ src/apps/filters/h3.c | 23 +++++++++++++++++++++++ tests/cli/edgeToVertexes.txt | 10 ++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/cli/edgeToVertexes.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index be038a3ef..24938bb89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The public API of this library consists of the functions declared in file [h3api.h.in](./src/h3lib/include/h3api.h.in). ## [Unreleased] +### Added +- Added `edgeToVertexes` to H3 CLI. (#1324) ## [4.6.0] - 2026-11-18 ### Added diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 97300fd8f..2131c740b 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -2412,6 +2412,28 @@ SUBCOMMAND(cellToVertexes, return E_SUCCESS; } +SUBCOMMAND(edgeToVertexes, + "Returns the start, end pair of vertexes from the directed edge") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); + DEFINE_CELL_ARG(cell, cellArg); + Arg *args[] = {&edgeToVertexesArg, &cellArg, &helpArg, &formatArg}; + PARSE_SUBCOMMAND(argc, argv, args); + H3Index out[2] = {0}; + H3Error err = H3_EXPORT(edgeToVertexes)(cell, &out[0], &out[1]); + if (err != E_SUCCESS) { + return err; + } + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[\"%" PRIx64 "\", \"%" PRIx64 "\"]\n", out[0], out[1]); + } else if (strcmp(format, "newline") == 0) { + printf("%" PRIx64 "\n%" PRIx64 "\n", out[0], out[1]); + } else { + return E_FAILED; + } + return E_SUCCESS; +} + SUBCOMMAND(vertexToLatLng, "Returns the lat, lng pair for the given vertex") { DEFINE_FORMAT_ARG( "'json' for [lat, lng], 'wkt' for a WKT POINT, 'newline' for " @@ -3107,6 +3129,7 @@ SUBCOMMAND_INDEX(directedEdgeToBoundary) /// Vertex subcommands SUBCOMMAND_INDEX(cellToVertex) SUBCOMMAND_INDEX(cellToVertexes) +SUBCOMMAND_INDEX(edgeToVertexes) SUBCOMMAND_INDEX(vertexToLatLng) SUBCOMMAND_INDEX(isValidVertex) diff --git a/tests/cli/edgeToVertexes.txt b/tests/cli/edgeToVertexes.txt new file mode 100644 index 000000000..03a0c9dfe --- /dev/null +++ b/tests/cli/edgeToVertexes.txt @@ -0,0 +1,10 @@ +add_h3_cli_test( + testCliEdgeToVertexes "edgeToVertexes -c 115283473fffffff" + "[\"255283463fffffff\", \"22528340ffffffff\"]") +add_h3_cli_test( + testCliEdgeToVertexesNewline + "edgeToVertexes -c 115283473fffffff -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" + "255283463fffffff,22528340ffffffff,") +add_h3_cli_test( + testCliNotEdgeToVertexes "edgeToVertexes -c 85283473fffffff 2>&1" + "Error 6: Directed edge argument was not valid")