Skip to content

H3: Implement CellToParent and CellToChildren #22

Description

@lukaskabrt

Summary

Implement the hierarchical operations CellToParent and CellToChildren which navigate up and down the H3 cell hierarchy by resolution.

Background

Part of #21 – Basic H3 Cell-Mode Support in SpatialLite.

H3 encodes hierarchy directly in the index bit structure:

  • CellToParent: replace child digit bits below the target resolution with the padding value (7)
  • CellToChildren: enumerate all valid digit combinations for the added resolution levels

Each regular hexagon has exactly 7 children per resolution step. Pentagon cells have 5 children per step due to a missing digit direction in their structure.

Tasks

  • Implement CellToParent(H3Cell cell, int parentResolution) → H3Cell
    • Validate that parentResolution is coarser (lower number) than the cell's current resolution
  • Implement CellToChildren(H3Cell cell, int childResolution) → IEnumerable<H3Cell>
    • Validate that childResolution is finer (higher number) than the cell's current resolution
    • Enumerate all valid digit combinations, skipping digit 1 for pentagon cells

Acceptance Criteria

  • CellToParent returns the correct parent for all resolution combinations
  • CellToChildren returns exactly 7 children for hexagons and 5 for pentagons per resolution step
  • Total child count for multi-step traversal: 7^(childRes − cellRes) for hexagons
  • ArgumentOutOfRangeException thrown for invalid resolution arguments
  • Behavior verified against upstream H3 test vectors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions