Skip to content

h3: group the constants and derive the ones that repeat a value - #177

Merged
justinhwang merged 1 commit into
masterfrom
refactor/constants
Oct 22, 2026
Merged

justinhwang merged 1 commit into
masterfrom
refactor/constants

Conversation

@justinhwang

@justinhwang justinhwang commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A tidy of constants.go with no value changes. The file was one flat block, with related declarations also scattered through index.go, hierarchy.go and faceijk.go. It is now one block per concern:

  • exported limits and conversions
  • degree spans (piDeg, twoPiDeg, halfPiDeg)
  • the C library's mathematical constants, with the previously undocumented ones commented
  • cell geometry counts
  • index digits
  • faceNeighbors slot indices
  • the index bit layout, now including the offsets and masks that lived in index.go
  • table sentinels, now including invalidFace from faceijk.go

Values that restate another are derived from it, or collapsed into one name:

  • The digits are the C Direction enum, 0 through 7 in order, so they are an iota sequence ending in numDigits. invalidDigit was the same 7 under another name (the C header defines NUM_DIGITS = INVALID_DIGIT), so there is now one name for the digit count and the unset value of a digit.
  • numHexChildren and numPentChildren were also 7 and 6 under other names: one child per valid digit, less the pentagon's deleted K-axis child. fullChildCount in hierarchy.go was their only user and its doc comment already states the two counts, so it returns them directly, as the C code does.
  • dirIJ, dirKI, dirJK are iota + 1; slot 0 of faceNeighbors is the face itself.
  • twoPiDeg and halfPiDeg derive from piDeg; DegsToRads and RadsToDegs use piDeg too.
  • digitMask is 1<<perDigitOffset - 1; h3Init is every digit set to numDigits, 1<<(MaxResolution*perDigitOffset) - 1.
  • numCellEdges is numHexVerts, one edge per hexagon vertex.
  • maxCellBoundaryVerts duplicated the exported MaxCellBndryVerts and is removed; the doc comment moved to the exported one.
  • polyfill.go set a parent's digit to digitMask where it meant the unset digit. Same value, clearer intent.

Test plan

  • Every derived constant checked equal to its former literal (h3Init, digitMask, numDigits, degree spans, directions, DegsToRads, RadsToDegs)
  • go test ./... green, root and conformance
  • golangci-lint run ./... clean

@coveralls

coveralls commented Oct 22, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 39823171393

Coverage remained the same at 100.0%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 31 of 31 lines across 10 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3669
Covered Lines: 3669
Line Coverage: 100.0%
Coverage Strength: 5169754.83 hits per line

💛 - Coveralls

constants.go was one flat block with a few related declarations scattered
through index.go, hierarchy.go and faceijk.go. It is now one block per
concern: exported limits, degree spans, the C library's mathematical
constants, cell geometry counts, index digits, faceNeighbors slots, the
index bit layout and the table sentinels.

Values that restate another are derived from it. The digits are the C
Direction enum, 0 through 7 in order, so they are an iota sequence ending
in numDigits, the one name for 7 as both the digit count and the unset
value of a digit; invalidDigit was the same constant under another name.
dirIJ, dirKI and dirJK are iota + 1, slot 0 of faceNeighbors being the
face itself. twoPiDeg and halfPiDeg come from piDeg, digitMask from
perDigitOffset, h3Init is every digit set to numDigits, and numCellEdges
is one edge per hexagon vertex. maxCellBoundaryVerts duplicated the
exported MaxCellBndryVerts and is gone. numHexChildren and
numPentChildren were also 7 and 6 under other names, one child per valid
digit less the pentagon's deleted one; fullChildCount states them
directly, as its doc comment already did. polyfill set a parent's digit
to digitMask where it meant the unset digit. No value changed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@justinhwang
justinhwang merged commit b02e85d into master Oct 22, 2026
15 checks passed
@justinhwang
justinhwang deleted the refactor/constants branch October 22, 2026 17:44
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.

2 participants