The following static helpers return a cellset, the finite-collection companion type of cell. They operate on a static cell or on a cellset and are not lifted to tcell, the temporal lift being deferred pending a tset<T> primitive.
The QUADBIN cells a trajectory covers are the values of tquadbin over it, which are the join key a Raquet table is read by.
All cells within k grid steps of the origin
gridDisk(h3index,integer) → h3indexset gridDisk(quadbin,integer) → quadbinset gridDisk(h3indexset,integer) → h3indexset gridDisk(quadbinset,integer) → quadbinset s2EdgeNeighbors(s2cell) → s2cellset
The disk includes the origin, which is the whole of it at k = 0. Its shape follows the grid: on the QUADBIN square grid the disk at step k is the (2k+1)×(2k+1) block of cells centred on the origin, while on the H3 hexagonal grid it is the ring of hexagons at that many steps and everything inside it. S2 states the four cells sharing an edge with the origin and takes no step count, so it answers the disk at k = 1 less the origin itself. A cell set gives the union of the disks of its cells, which at k = 1 widens a cover by the ring of cells around it, and a disk of radius 1 widened by one step is the disk of radius 2 around the same origin.
SELECT gridDisk(h3index '871fa44a8ffffff', 1);
/* {"871fa44a8ffffff", "871fa44a9ffffff", "871fa44aaffffff", "871fa44abffffff",
"871fa44acffffff", "871fa44adffffff", "871fa44aeffffff"} */
SELECT gridDisk(quadbin '48a6227affffffff', 1);
/* {"48a6226dffffffff", "48a6226fffffffff", "48a62278ffffffff", "48a62279ffffffff",
"48a6227affffffff", "48a6227bffffffff", "48a622c5ffffffff", "48a622d0ffffffff",
"48a622d1ffffffff"} */
SELECT numValues(gridDisk(gridDisk(h3index '871fa44a8ffffff', 1), 1));
-- 19
SELECT numValues(gridDisk(gridDisk(quadbin '48a6227affffffff', 1), 1));
-- 25
SELECT s2EdgeNeighbors(s2cell '47c3c');
-- {"47c14", "47c24", "47c34", "47c44"}
All children of a cell at the given target resolution
cellToChildren(h3index,integer) → h3indexset cellToChildren(quadbin,integer) → quadbinset cellToChildren(s2cell,integer) → s2cellset
The number of children is the grid's branching factor: four for a QUADBIN or an S2 quadtree cell, seven for an H3 cell. The helper is static, children being a per-instant set whose temporal lift is deferred pending a tset<T> primitive.
SELECT cellToChildren(h3index '831c02fffffffff', 4);
/* {"841c021ffffffff", "841c023ffffffff", "841c025ffffffff", "841c027ffffffff",
"841c029ffffffff", "841c02bffffffff", "841c02dffffffff"} */
SELECT cellToChildren(quadbin '48a6227affffffff', 11);
-- {"48b6227a3fffffff", "48b6227a7fffffff", "48b6227abfffffff", "48b6227affffffff"}
SELECT cellToChildren(s2cell '47c3c', 8);
-- {"47c39", "47c3b", "47c3d", "47c3f"}
Compacted representation of a cell set, finer cells being merged into their parent whenever the parent's full set of children is present
compactCells(cellset) → cellset
A QUADBIN tile and an S2 cell are each exactly the union of their four children, so the cells of a QUADBIN or S2 set may be of any resolutions: a cell covered by a coarser cell of the set is dropped, and every four children of one parent are replaced by that parent, from the finest resolution up, as the S2 library normalizes a cell union. An H3 cell covers its seven children only approximately, so an H3 set is compacted as the H3 library compacts it, from cells of a single resolution, and cells of two resolutions raise an error. A compacted set mixes resolutions, while ?= compares cells, so a compacted cover is uncompacted to the resolution of a trajectory before the trajectory is read against it.
SELECT compactCells(cellToChildren(h3index '831c02fffffffff', 4));
-- {"831c02fffffffff"}
SELECT compactCells(cellToChildren(quadbin '48a6227affffffff', 12));
-- {"48a6227affffffff"}
SELECT compactCells(cellToChildren(s2cell '47c3c', 9));
-- {"47c3c"}
Uncompacted representation at the given resolution, the inverse of compactCells
uncompactCells(cellset,integer) → cellset
A cell coarser than the resolution is replaced by its descendants at the resolution. A cell finer than the resolution cannot be stated at it and raises an error, as does a QUADBIN or S2 result of more than 4194304 cells.
SELECT numValues(uncompactCells(compactCells(
cellToChildren(h3index '831c02fffffffff', 4)), 4));
-- 7
SELECT numValues(uncompactCells(quadbinset '{48a6227affffffff}', 12));
-- 16
SELECT numValues(uncompactCells(compactCells(cellToChildren(s2cell '47c3c', 8)), 9));
-- 16