garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/021-region-tessellation-flat-clusters-quad-index.md

raw

ADR-021: Region Tessellation — Flat Metric Clusters with a Global Quad Index


Metadata:


Superseded direction. The fixed-region-grid + cluster + S2-index model below is being retired. The sim tier is moving to a capacity-bounded set of assets placed at any real-world position (a simulator caps how many assets it hosts, not where they sit) — no fixed 256 m squares, no cluster tessellation, no per-region (i,j) addressing. The floating-origin frame (ADR-019) and the map/content separation (ADR-020) still hold. Retained for history and for the addressing ideas a future spatial-index/discovery design may reuse. A forthcoming ADR specifies the new model.

Context

ADR-020 splits the world into a map tier (read-only globe) and a sim tier (discrete regions), and ADR-019 gives the precise global frame. One question was left open: how exactly are sim regions tessellated and addressed on the globe? Two candidates emerged:

The ambiguity created downstream fuzziness: do regions warp (to wrap the sphere) or stay exact squares (leaving gaps)? Do region IDs come from geometry or from an index? How do on-demand ("activate a region") and a global grid coexist?

A sphere is not flat-developable (Theorema Egregium): you cannot have flat + exact-square + globally-seamless at once. (A) keeps seamlessness by warping cells; (B) keeps flat exact squares and accepts that seams fall between clusters.

Decision

Adopt (B): sim regions are flat, fixed-size real-meter squares tiled inside locally-anchored clusters; a global quad index (S2-style) is used only for addressing, discovery, and neighbor lookup — never for geometry.

This cleanly separates two concerns that (A) conflated:

LayerJobProperty
Geometry / simulationwhere things are, physics, movementflat metric grid in a cluster's tangent plane
Addressing / indexstable IDs, "what's near here", neighborsglobal quad cells (S2-style)

Definitions

Resolutions to the open questions

  1. Warp vs gaps → neither, inside a cluster. Regions are exact squares and seamless within a cluster (shared metric grid). The unavoidable sphere seam lives between clusters — open water / unsimulated map — where a hairline discontinuity is irrelevant.
  2. IDs come from the index, not geometry. Region geometry is the flat grid; identity/addressing is the S2 cell. The two are linked (anchor → cell) but independent in purpose.
  3. On-demand activation. Quad cells are virtual indices until a region is activated ("convert a building" → instantiate the region). The global index gives every potential region a stable address without instantiating it, so sparse, on-demand activation and a global addressing grid coexist naturally.
  4. Cross-region movement. Within a cluster: pure flat translation between (i,j) frames. Between clusters: a small frame handoff (tilt ≤ ~0.0023°/region) via the S2 index — the same handoff path multiplayer AOI needs (ADR-010/012).

Worked example — positioning a sim and its neighbour

Anchor a Groningen cluster at the Grote Markt (53.2194°N, 6.5665°E):

A sim over part of Groningen = a block of regions, e.g. Sim A = (0,0)…(3,3).

Adjacent sim, same cluster (the common case). A neighbouring Sim B = (4,0)…(7,3) to the east is just the next block. Both sims share the cluster's one metric grid, so B's west edge (i=4) coincides with A's east edge to the millimetre — no transform, no rotation, no handoff; positioning is pure integer arithmetic:

adjacent(A, B)  ⇔  A.i_max + 1 == B.i_min   (and j-ranges overlap)
B region (4,j) origin = anchor + 4·256·East + j·256·North   ← continues A's grid exactly

Adjacent sim, different cluster (only past the sag bound ~7 km, or another town). Sim B gets its own anchor + ENU frame and its own S2 cluster cell (e.g. 47a1d4). A and B no longer share a plane, so they're related by a rigid transform T_AB derived from the two anchors (translation + a tilt of ≤ ~0.0023° per region of separation), discovered via S2 cell adjacency. Crossing the border is the AOI handoff (ADR-010/012): the avatar's local coords map A-frame → B-frame.

Rule of thumb: keep extending one cluster (trivial integer adjacency) until the sag budget forces a new one; place cluster borders on water/unsimulated terrain so the only non-flat seam is where nothing is simulated.

Rationale

  1. Keeps the sim flat and globe-agnostic. No geodesy or sphere math in cartopolis_simulator; it simulates flat squares in local meters, exactly as today (P-05).
  2. True squares preserve the SL/OpenSim model — fixed-size rectangular regions/parcels with consistent X/Y axes and north, which authoring and gameplay assume.
  3. Matches islands-of-simulation reality. Cartopolis visits cities with ocean between; global seamless tiling buys little, and (B) puts the only seams where nothing is simulated.
  4. Global index gives the benefits of (A) without its costs. Stable worldwide addressing, discovery, and neighbour queries — without warped cells or sphere math in the sim.

Alternatives Considered:

AlternativeProsConsRejected Because
(A) Global quad sphere as regionsGlobally seamless; intrinsic neighboursWarped/non-uniform cells; sphere math in sim; breaks square-parcel modelCost not justified for islands-of-sim
lat/lng grid as regionsSimple addressingCurvilinear → unequal, non-aligning squaresSeams everywhere (ADR-020 anti-pattern)
Flat clusters, no global indexSimplestNo stable worldwide IDs / discovery / cross-cluster neighboursNeeded for persistence & multiplayer

Consequences

Positive:

Negative:

Related