itacart.topology.get_neighbor

itacart.topology.get_neighbor(index, direction)[source]

Single adjacent cell in a given direction.

Directions are true compass points in every quadrant: "N" is cardinal north and "E" is cardinal east whether the cell sits east or west of the prime meridian, north or south of the equator. The cardinal four share an edge with the origin; the diagonal four share only a vertex.

Inside, the lattice counts columns away from the meridian and rows away from the equator, which is what lets one piece of arithmetic serve four quadrants. _lattice_direction() is the seam.

Reciprocity is not promised. This is a directional selector, not an involution. Where a row’s last column shifts between rows, the step back from the answer can land one column off the origin. Enumerated over the four border families – meridian, last column, equator and polar row, every cell of each, in four quadrants – 6,338 such pairs out of 102,090. Every one of them was classified, and every one is the same case: the answer genuinely touches its origin, and the origin is genuinely among the answer’s neighbours. None is a step that missed, and none is the tie-break of cell_to_edges() choosing differently. What varies is the length of the row.

Geometric adjacency is symmetric – are_neighbor_cells() answers the same from either side – and that is the invariant to compose on.

The diagonals are lattice steps. "NE" moves one column and one row, which is geographically north-east everywhere except at the last column of a row, where the shear can carry the answer the other way in longitude: 4,382 of 25,572 diagonal pairs in that family, and none at all in the other three. The cardinal four are true compass points everywhere, with zero exceptions in 102,090 enumerated pairs.

Derivation is lexical: the direction’s displacement is added to the XXXX/YYYY pair and nothing else is consulted. Existence is a separate question, delegated to itacart.boundary.is_valid_cell(), and when the lexical target does not exist the step is handed to deflect().

Parameters:
  • index (str) – Compositional index string.

  • direction (Literal['N', 'S', 'E', 'W', 'NE', 'NW', 'SE', 'SW']) – One of the eight lattice directions.

Return type:

str | None | list[str | None]

Returns:

The neighbour index, or None where no cell exists on that side, for a single cell; or a positionally aligned list.

Raises:
  • ValueError – If direction is not one of the eight. An invalid member of a closed vocabulary is a caller mistake, not a statement about a cell, and the package refuses that class with the built-in exception everywhere it occurs: containment, coverage, edge_model, zone, direction and metric. The package’s own hierarchy is reserved for what is wrong with an index or with the domain.

  • ResolutionError – If the cell is not at resolution 1. Descent through the refinement alphabets is not yet implemented here.

  • DomainError – If the cell sits in the geometric exception set, where the step is real but no lexical rule names it. See deflect().

  • NonExistentCellError – If any cell of the index names no cell. The predicate is the arbiter and the contract ends there: a spelling it denies is refused rather than answered for the cell it would otherwise fold onto.