Skip to content

Add edgeToVertexes function - #1272

Open
maringantis wants to merge 1 commit into
uber:masterfrom
maringantis:feat/h3-edge-to-vertexes
Open

maringantis wants to merge 1 commit into
uber:masterfrom
maringantis:feat/h3-edge-to-vertexes

Conversation

@maringantis

@maringantis maringantis commented Oct 18, 2026 •

Copy link
Copy Markdown

Summary

Adds H3Error edgeToVertexes(H3Index edge, H3Index *v1, H3Index *v2), which returns the two vertex H3Indexes at the ends of a directed edge.

Today, getting an edge's two vertexes requires manually reconstructing them via cellToVertexes/directedEdgeToBoundary. This function makes that a single call, as requested in #1071 (and the older duplicate, #421).

The signature matches what @nrabinowitz scoped in the #421 thread, where edgeToVertexes was called out as something that "should be dead simple" to implement (as opposed to the harder vertexesToDirectedEdge inverse, which is out of scope here).

Implementation

edgeToVertexes lives in src/h3lib/lib/vertex.c, next to cellToVertex/cellToVertexes, and reuses the same vertex-selection logic already used by directedEdgeToBoundary:

  1. Validate the edge with isValidDirectedEdge.
  2. Get the edge's origin cell and direction.
  3. Find the start vertex number for that direction via the existing (internal) vertexNumForDirection.
  4. The end vertex number is the next one in CCW order (mod 5 for pentagons, mod 6 for hexagons).
  5. Convert both vertex numbers to H3 vertex indexes via the existing cellToVertex.

The function is declared in src/h3lib/include/h3api.h.in with a @defgroup edgeToVertexes doc block, following the same convention as the neighboring cellToVertex/cellToVertexes declarations. Because make binding-functions derives its list of public API functions from these @defgroup markers, the new function is automatically picked up there for language bindings - no separate export list needed.

Tests

Added to src/apps/testapps/testVertex.c:

  • edgeToVertexes: a valid hexagon edge returns two valid, distinct vertexes that belong to the origin cell's vertex set and match the first/last points of directedEdgeToBoundary.
  • edgeToVertexes_pentagon: exercises all of a pentagon's valid edges.
  • edgeToVertexes_invalid: H3_NULL, a cell passed in place of an edge, an edge with an invalid direction digit, and a pentagon's deleted K-axis edge all return E_DIR_EDGE_INVALID.

Also added a call into the existing fuzzerVertexes harness.

Formatting / CI note

A prior automated attempt at this (#1086, now closed/abandoned) implemented essentially the same idea but was never merged after a CI formatting nit from @isaacbrodsky (clang-format-14 vs. a different local version). To avoid repeating that, I built with clang-format-14 (via Homebrew's llvm@14, matching the version CI installs) and ran make format until it was a no-op before committing - no further formatting diffs remain.

Test plan

  • cmake configure + make build the full project cleanly with no new warnings
  • make format (clang-format-14) produces no diff
  • ctest run for testVertex, testVertexInternal, testVertexExhaustive, testDirectedEdge, testDirectedEdgeExhaustive - all pass
  • Broader ctest run confirms no regressions outside of pre-existing, unrelated environment-specific CLI test failures (not touched by this change)

Closes #1071. Also resolves #421.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05ec6b8c-a5d5-4962-b0c3-9038d4b6aad4
📥 Commits

Reviewing files that changed from the base of the PR and between eb4309a and 4b4996c.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a793ee2d-2957-4b0c-a001-c7b93e2ad2ef
📥 Commits

Reviewing files that changed from the base of the PR and between 28d83cd and dc8b3dc.

📒 Files selected for processing: 5
  • CHANGELOG.md
  • src/apps/fuzzers/fuzzerVertexes.c
  • src/apps/testapps/testVertex.c
  • src/h3lib/include/h3api.h.in
  • src/h3lib/lib/vertex.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The change adds the public edgeToVertexes API. It returns the start and end vertex indexes for a directed edge and propagates validation and conversion errors. Tests cover ordinary edges, pentagon edges, and invalid inputs.

Changes

Directed edge endpoint vertices

Layer / File(s) Summary
Add the edge vertex API
src/h3lib/include/h3api.h.in, src/h3lib/lib/vertex.c
The public API accepts a directed edge and two output pointers. The implementation validates the edge, calculates adjacent vertex numbers with wraparound, and converts them to vertex indexes.
Exercise and document edge vertex lookup
src/apps/testapps/testVertex.c, src/apps/fuzzers/fuzzerVertexes.c, CHANGELOG.md
Tests check ordinary and pentagon edges, plus invalid inputs. The fuzzer calls the new API, and the Unreleased changelog lists it.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to dc8b3

The directed-edge endpoint API appears ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed The PR implements the requested edgeToVertexes(H3Index edge, H3Index *v1, H3Index *v2) API for directed edges [#1071] [#421]. vertex.c validates the directed edge, obtains its origin and direction…
Out of Scope Changes check Passed The reported changes remain connected to [#1071] and [#421]. The public declaration and changelog document the new API. The tests and fuzzerVertexes update verify and exercise the new behavior. No u…
Title check Passed The title clearly and concisely identifies the main change: adding the edgeToVertexes function.
Description check Passed The description directly explains the edgeToVertexes API, implementation, tests, and scope. It is relevant to the changeset.
Full details: Linked Issues check

Explanation

The PR implements the requested edgeToVertexes(H3Index edge, H3Index *v1, H3Index *v2) API for directed edges [#1071] [#421]. vertex.c validates the directed edge, obtains its origin and direction, selects the start vertex with vertexNumForDirection, selects the next vertex in CCW order, and converts both vertices with cellToVertex. This matches the requested right-hand ordering in [#1071]. The header declaration uses the edgeToVertexes API group. Tests cover a hexagon edge, pentagon edges, invalid inputs, and boundary endpoint ordering. The optional discussion of undirected-edge support in [#421] does not require implementation of undirected edges.

Full details: Out of Scope Changes check

Explanation

The reported changes remain connected to [#1071] and [#421]. The public declaration and changelog document the new API. The tests and fuzzerVertexes update verify and exercise the new behavior. No unrelated source or test behavior is identified in the supplied change summary or reviewed file evidence.

Full details: Docstring Coverage

Explanation

Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented Oct 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@maringantis
maringantis force-pushed the feat/h3-edge-to-vertexes branch from dc8b3dc to eb4309a Compare October 19, 2026 01:49
Add edgeToVertexes(H3Index edge, H3Index *v1, H3Index *v2), which returns
the two vertex H3Indexes at the ends of a directed edge. Previously,
getting an edge's vertexes required manually reconstructing them via
cellToVertexes/directedEdgeToBoundary.

The implementation mirrors the vertex-selection logic already used by
directedEdgeToBoundary: it validates the edge, finds the start vertex
number for the edge's direction via vertexNumForDirection, takes the next
vertex number (mod 5 or 6 for pentagons/hexagons) as the end vertex, and
converts both to H3 vertex indexes via the existing cellToVertex.

The function is declared in h3api.h.in with a @defgroup block following
the same convention as cellToVertex/cellToVertexes, so it is automatically
picked up by the generated `binding-functions` list used by language
bindings - no separate export list needed.

Adds unit tests in testVertex.c covering a valid hexagon edge (vertexes
valid, distinct, members of the origin cell, and matching the edge
boundary endpoints), a pentagon edge, and invalid inputs (H3_NULL, a cell
passed as an edge, an edge with an invalid direction, and a pentagon's
K-axis edge). Also wires the function into the existing vertex fuzzer.

Closes uber#1071. Also resolves uber#421, the older duplicate of the same request.

The API signature matches what nrabinowitz scoped in the issue thread,
described as "dead simple" to implement. A prior automated PR (uber#1086)
took a similar approach but was abandoned after a CI formatting nit; this
change was built and verified with clang-format-14 (matching CI) to avoid
the same issue.
@maringantis
maringantis force-pushed the feat/h3-edge-to-vertexes branch from eb4309a to 4b4996c Compare October 19, 2026 02:20
@maringantis

Copy link
Copy Markdown
Author

Re: CodeRabbit's docstring-coverage warning on this PR — checked it against the diff: edgeToVertexes itself already has a full doc comment in both vertex.c and h3api.h.in, matching cellToVertexes right above it. The remaining uncovered functions are the three new TEST() cases and the fuzzer wiring, and no existing test or fuzzer function in either file carries a docstring, so adding one there would be inconsistent with the file rather than following it. Leaving that warning as-is for that reason.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add edgeToVertexes function Implement edgeToVertexes

2 participants