Repository navigation
h3: group the constants and derive the ones that repeat a value - #177
Merged
Merged
Conversation
Coverage Report for CI Build 39823171393Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - 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
force-pushed
the
refactor/constants
branch
from
October 22, 2026 17:29
b80e909 to
ceecd06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A tidy of
constants.gowith no value changes. The file was one flat block, with related declarations also scattered throughindex.go,hierarchy.goandfaceijk.go. It is now one block per concern:piDeg,twoPiDeg,halfPiDeg)faceNeighborsslot indicesindex.goinvalidFacefromfaceijk.goValues that restate another are derived from it, or collapsed into one name:
Directionenum, 0 through 7 in order, so they are aniotasequence ending innumDigits.invalidDigitwas the same 7 under another name (the C header definesNUM_DIGITS = INVALID_DIGIT), so there is now one name for the digit count and the unset value of a digit.numHexChildrenandnumPentChildrenwere also 7 and 6 under other names: one child per valid digit, less the pentagon's deleted K-axis child.fullChildCountinhierarchy.gowas their only user and its doc comment already states the two counts, so it returns them directly, as the C code does.dirIJ,dirKI,dirJKareiota + 1; slot 0 offaceNeighborsis the face itself.twoPiDegandhalfPiDegderive frompiDeg;DegsToRadsandRadsToDegsusepiDegtoo.digitMaskis1<<perDigitOffset - 1;h3Initis every digit set tonumDigits,1<<(MaxResolution*perDigitOffset) - 1.numCellEdgesisnumHexVerts, one edge per hexagon vertex.maxCellBoundaryVertsduplicated the exportedMaxCellBndryVertsand is removed; the doc comment moved to the exported one.polyfill.goset a parent's digit todigitMaskwhere it meant the unset digit. Same value, clearer intent.Test plan
h3Init,digitMask,numDigits, degree spans, directions,DegsToRads,RadsToDegs)go test ./...green, root and conformancegolangci-lint run ./...clean