Skip to content

Vectorized precision in gh_encode + doc/build cleanups - #47

Merged
MichaelChirico merged 4 commits into
masterfrom
chore/qol-improvements
Jun 9, 2026
Merged

MichaelChirico merged 4 commits into
masterfrom
chore/qol-improvements

Conversation

@dshkol

@dshkol dshkol commented May 31, 2026

Copy link
Copy Markdown
Collaborator

QOL improvements (independent of the gh_covering performance work in #44).

gh_encode() accepts a vector of precisions

gh_encode() previously errored on any precision of length > 1 ("precision is fixed on input (for now)"). It now accepts either:

  • a single precision (applied to all coordinates, as before), or
  • a precision vector the same length as the coordinates, giving a per-coordinate zoom level.
gh_encode(c(2.345, 0), c(6.789, 0), precision = c(4L, 8L))
#> [1] "s0kv"     "s0000000"

Backward compatible — length-1 precision behaves exactly as before. The C encoder sizes its working buffer to the largest requested precision and reads each coordinate's precision inside the main loop. New tests verify the vector path equals element-wise scalar calls, prefix behaviour, NA/Inf handling, per-element truncation warnings, and the length/validity error paths.

Doc & build cleanups

  • Doc fix: ?gh_encode claimed a maximum precision of 28; the actual cap is 25 (GH_MAX_PRECISION). Corrected.
  • Build: added .claude to .Rbuildignore to silence the R CMD check "hidden files and directories" NOTE.

Notes

  • The package's man/*.Rd are hand-maintained (not roxygen-generated), so RoxygenNote: 7.2.3 in DESCRIPTION is vestigial — bumping it would falsely imply roxygen manages the docs. Left as-is; flagging in case you'd prefer to remove the field.

🤖 Generated with Claude Code

- gh_encode() now accepts a per-coordinate precision vector (length 1 or
  length(coords)), encoding different points at different zoom levels in one
  call. Length-1 precision still applies to all coordinates as before, so the
  change is backward compatible. The C encoder sizes its buffer to the largest
  requested precision and reads each coordinate's precision in the main loop.
- Fix gh_encode docs: maximum precision is 25 (GH_MAX_PRECISION), not 28.
- Add .claude to .Rbuildignore to silence the R CMD check hidden-files NOTE.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread man/gh_encode.Rd
}
\details{
\code{precision} is limited to at most 28. This level of precision encodes locations on the globe at a nanometer scale and is already more than enough for basically all applications.
\code{precision} is limited to at most 25. This level of precision encodes locations on the globe at a nanometer scale and is already more than enough for basically all applications.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 😬

Comment thread src/encode.c Outdated
Comment thread src/encode.c Outdated
Comment thread src/encode.c Outdated
// size the working buffer to the largest requested precision
int kmax = 0;
for (int j=0; j<nk; j++) if (kp[j] > kmax) kmax = kp[j];
char gh_elt[kmax+1];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/encode.c Outdated
Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
Comment thread tests/testthat/test-encode.R Outdated
Comment thread tests/testthat/test-encode.R Outdated
Comment thread NEWS.md Outdated
Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
@MichaelChirico
MichaelChirico merged commit d88bb61 into master Jun 9, 2026
@MichaelChirico
MichaelChirico deleted the chore/qol-improvements branch June 9, 2026 23:57
@MichaelChirico

Copy link
Copy Markdown
Owner

Thanks!

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