Defect (found while verifying #47's get_children_indices fix)
For aperture 7, encoding a cell ID to a Z7 index and decoding it back does not always recover the original cell ID.
Reproduction
g <- hex_grid(resolution = 4, aperture = 7)
cells <- lonlat_to_cell(c(0, 30, -60), c(10, 45, -30), g)
print(cells)
# [1] 17979 25142 46111
idx <- cell_to_index(cells, g)
print(idx)
# [1] "036566" "004545" "076106"
rt <- sapply(idx, function(s) {
r <- cpp_index_to_cell(s, 7, "z7")
cpp_quad_ij_to_cell(r$face, r$i, r$j, r$resolution, 7)
})
print(rt)
# 036566 004545 076106
# 17979 9316 46111
The first and third cells round-trip correctly; the second (25142) decodes to a different cell (9316) than it was encoded from.
Confirmed pre-existing
Verified via git stash that this reproduces identically at commit 59e3404 (before any of this audit session's fixes) -- not a regression from #31/#32/#35/#36/#37/#50 or the R-level fixes in ab2a811/d15edea.
Likely area
src/index_z7.cpp's encode()/decode() have nontrivial pentagon-adjacency rotation logic (adjacentBaseCellTable, rotateDigitVecCCW, the skipRotate/firstNonZero digit-rotation handling for pentagon gaps near cells 0-5/6-11) that likely has an edge case where the rotation applied during encode doesn't exactly invert during decode for certain base-cell/digit combinations. Given the complexity of this logic (ported/adapted pentagon-skip handling), this needs a dedicated investigation pass against known-good reference values (e.g. DGGRID or H3's own Z7-equivalent, if one exists) rather than a quick patch -- same caution as #50's investigation.
Defect (found while verifying #47's get_children_indices fix)
For aperture 7, encoding a cell ID to a Z7 index and decoding it back does not always recover the original cell ID.
Reproduction
The first and third cells round-trip correctly; the second (
25142) decodes to a different cell (9316) than it was encoded from.Confirmed pre-existing
Verified via
git stashthat this reproduces identically at commit 59e3404 (before any of this audit session's fixes) -- not a regression from #31/#32/#35/#36/#37/#50 or the R-level fixes in ab2a811/d15edea.Likely area
src/index_z7.cpp'sencode()/decode()have nontrivial pentagon-adjacency rotation logic (adjacentBaseCellTable,rotateDigitVecCCW, theskipRotate/firstNonZerodigit-rotation handling for pentagon gaps near cells 0-5/6-11) that likely has an edge case where the rotation applied during encode doesn't exactly invert during decode for certain base-cell/digit combinations. Given the complexity of this logic (ported/adapted pentagon-skip handling), this needs a dedicated investigation pass against known-good reference values (e.g. DGGRID or H3's own Z7-equivalent, if one exists) rather than a quick patch -- same caution as #50's investigation.