garage44.eu/jeroen/cartopolis

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

.. /docs/notes/scenarios.md

raw


topic: scenarios triggers: [crates/scenario, lens_areas.rs, lens_areas.wesl, LensAreaMaterial, cartopolis_scenario, scenario.rs, official_areas.rs, xlsx.rs, ladder.rs, cbs-2024.toml, ses-2023.toml, pbl-2050.toml, wlo-2060.toml, night-wave.toml, ne-admin1-europe.bin, assets/scenarios, CARTO_SCENARIO, "atlas areas", "region state", "region_state", "areas/", "cbs-buurt-2024", SES-WOA, statusscores, "regionale prognose", WLO, COROP, "change_since", "field_at"] updated: 2026-11-26

Scenarios: generic layers on a ladder of places

Built 2026-10-31 from docs/mockups/scenarios/ (v1-engine, v4-whole, v5-areas). The person steering asked for generic layers from the solar system down to the wijk, with CBS figures as the example and no specific application yet; a drone exercise built first was taken out of the app and kept as a test. What the code does not say:

One engine, everything else is files

cartopolis_scenario knows primitives, boards, a ladder and a clock, never a subject. A scenario file (TOML) names its sources, its mode and its clock, and holds tracks and region-state layers. A layer's states are listed (a feed, a table: place, time, state), derived from tracks (soonest to enter an area), or read off a figure the areas carry, by bands (below = …). assets/scenarios/cbs-2024.toml is six such figure layers; the drone night is crates/scenario/testdata/night-wave.toml.

Rules the parser enforces, from the sheets: every scenario names its sources; a Live scenario may not derive states from a model; bands rise; a figure layer names a field every one of its area sets has.

The ladder: a layer stands on several rungs

ladder::Rung runs stars → solar system → world → continent → country → province → municipality → district (wijk) → neighbourhood (buurt) → street, each with the camera heights it is read at (Rung::altitudes; a place is then roughly 30–300 points across). A layer lists boards on several rungs.

Which board a layer reads follows the screen, not the camera's rung (Play::set_scale, since 2026-11-01): the finest board whose typical area (the median box width) is at least MIN_AREA_PX = 12 points wide, else the coarsest while it is 3 points or more. Reading by rung (Play::set_rung: nearest board, the coarser on a tie, nothing beyond two rungs) put a phone that sees the whole country on the country rung, and every figure lens became one flat patch the size of the Netherlands — reported from a phone the day the lenses landed. At 28 points that view showed the 12 provinces, at 14 it flipped between provinces and municipalities with the load order, at 12 it shows the 342 municipalities. The board shown is kept down to 0.8 of the threshold, so a zoom resting near it does not flicker. Area edges are a thin dark line (ink::AREA_EDGE), not the fill's own colour, or neighbours in one band merge into one patch. Cells (H3) and networks can be named as boards already; only official areas carry geometry, so the rungs above the country wait for those boards.

Figures roll up; a kept-back figure stays empty

An area set carries fields (Field: key, label, unit, how it rolls up) and a value per area, NaN where nothing is published. AreaSet::roll_up carries a child set into its parent by each child's parent code: counts are summed, shares and means weighted by another field (65+ by inhabitants, home value by homes, density by land area — which makes it total people over total land). A published parent figure is never overwritten. CBS's negative codes (−99997 "kept back", −99995 …) become NaN, and a NaN area is left uncoloured: v5's "small numbers hidden", never guessed.

The CBS sets, and where they live

atlas areas cbs-2024 --out <site>/areas (11 min on mac-2, 2026-10-31, almost all of it PDOK paging 1,000 features at a time):

setareasbytestolerance
cbs-buurt-202414,5742.9 MB0.0001°
cbs-wijk-20243,3930.9 MB0.0002°
cbs-gemeente-2024342195 KB0.0005°
cbs-provincie-20241217 KB0.001°
cbs-land-202415 KB0.002°

Buurt, wijk and gemeente come from CBS's wijkenbuurten WFS, land parts only (water = NEE), linked by CBS's own codes. CBS publishes no province or country here, so those polygons are the Kadaster's (bestuurlijkegebieden), a gemeente placed in a province by a point inside it (Area::inner_point: all 342 landed in one) and the figures rolled up.

The client fetches them from {CARTO_3DBAG_URL}/areas/<set>.bin when a layer opens and decodes them off the frame loop; nothing is embedded. Like every atlas dataset, deploying atlas does not write them: run atlas areas <set> --out /data/3dbag/site/areas for each of cbs-2024, ses-2023, pbl-2050 and wlo-2025 on the host once (atlas-run-on-the-host in memory has the identity it needs).

Figures over time: a series per year, played by the clock

Added 2026-11-01 for the planning offices' figures (the person asked for SCP and CPB as the next examples, "generic so the other uses fit later"). A figure over time is a series: one Field per year under one key, and AreaSet::field_at(key, year) gives the latest year at or before the one asked, else the earliest. The scenario's clock of years picks the year (Clock::year_at), so the same layer plays a forecast forward and a measured series back; between published years the last one holds — nothing is interpolated, which matters for the WLO's 2021/2040/2050/2060. roll_up carries a series year by year, each share weighted by its own year's weight.

Two layer options, both only on a figure layer: change_since = "2023" reads the figure as its change in % since that year (growth, not size), and range = [low, high] names the fields that bound it (a forecast's 67 % interval, a score's 95 %), shown as "likely … – …" under the value and never coloured. The clock's forecast = "2024" marks where measurement stops: the clock bar hatches from there and the key says "2050 forecast". Two futures are two figures on one clock (High and Low under one heading), so switching keeps the year.

lensset (atlas areas …)boardsyearstook (mac-2, 2026-11-01)
ses-2023ses-2023buurt → land2014–2023, measured14 min; buurt 4.7 MB, wijk 1.7 MB, gemeente 280 KB
pbl-2050pbl-2050gemeente → land2023–2050, forecast2.5 min; gemeente 300 KB
wlo-2060wlo-2025COROP → land2021, 2040, 2050, 20602 s, 43 KB + 6 KB

What each source is, and the traps:

The geometry is copied into each source's files (a ses-buurt-2024 holds the same outlines as cbs-buurt-2024): simple, and every board stays one file. It costs: ten years of four figures make the SES buurt file 4.7 MB against the Kerncijfers' 2.9 MB, all fetched when the lens opens. If a third source lands on the buurt rung, the next step is figure-only files joined to one geometry board by code.

A lens, not a layer

Opened from its own disc under Layers, not from the Layers panel (docs/mockups/lenses/, built 2026-11-01). Ticking a figure tile that closed the other was a radio dressed as a checkbox, and on a phone the panel covered the map you were choosing for. The lens is one surface (scenario::Sheet): a bottom sheet in portrait (figures, place, shelf), a column on the left otherwise. Its rect goes to place_pins::map_area as last frame's scenario::LensSlot, so pins under it do not eat its taps. Switching to another figure of the same file keeps the loaded areas (switch_figure); only another file fetches. A scenario file may give itself a question (the shelf's heading) and each region state a group (the figures' heading).

A lens that is on needs no surface at all (docs/mockups/lenses/v3, asked 2026-11-02: "why can't a lens be on and its dialog be clicked away? The lens icon can say whether one is on"). On and shown are two things: on is the coloured map, the mode's frame and the lit disc; the sheet (the open figure's key over the figures) is raised by the disc and put away by its ✕, the disc, a pick off the shelf or the figures, or a drag that starts on the bare map (UiInput::map_dragged, decided by where the press landed). "Lens off" turns it off. The same in the column. An earlier resting strip, then a one-row strip with the key behind a palette (v2), were dropped for it the same day: nothing has to rest over the map when the sheet is one tap away.

The lens answers back (asked 2026-11-01, "too static"): the area being read is outlined on the map — under the pointer on a desktop, with a card beside it, else under the crosshair; the scale's bands single theirs out (a tap; the library has no hover, so pointing no longer previews; CARTO_LENS_BAND=n for a capture) and a marker stands over the band here, as a tick does on each figure's small scale; and an area's colour eases to its state's (Open::colours), so a played year or a switched figure flows over and a finer board fades in. A finger has no hover: on a phone the crosshair is the pointer.

Drawn by the GPU, a texel an area

Until 2026-11-17 systems::scenario painted the areas as egui shapes: every frame, every area in a box round the camera projected vertex by vertex through place_pins::place_delta, its outline a second time, and all of it tessellated by egui on the main thread. The person steering reported the app slow with a lens on, and it was: measured on mac-1 (M5 Pro VM, dev profile, 1280×720, CARTO_SCENARIO=cbs-2024/share_65_plus, the session's scratch --perf manifest), Groningen from 12 km ran at 6.1 fps settled and 5.6 fps turning, and the whole country from 120 km at 9.4 fps.

systems::lens_areas meshes each board once per frame of reference on a worker — laid where place_delta puts a point, on the flat map's curve below the space tier and on the sphere above it, cut into about 6×6 chunks so the GPU culls — and draws it with LensAreaMaterial (shaders/lens_areas.wesl): every vertex names its area's texel, so a played year, a switched figure or a singled band rewrites one texel an area and nothing else moves. Edges are a line list on the same material, each border once, the ink one texel past the areas. Same runs after: 84.5 fps settled and 41 fps turning (that window still streaming tiles) at 12 km, 60 and 62 fps at 120 km. Meshing the buurt board took a worker 453 ms once.

The material draws with the depth test off, over the map as the overlay did, and drops in its shader what the camera cannot see past the horizon (the place_delta test, 200 m margin), so the far side of the globe does not show through. The board is laid on the Earth's curve, not on the relief. The pointer's area is found by casting the pointer onto the ground and asking the board (area_at), not by hit-testing triangles. The outline of the area being read, its card, the tracks and the mode's frame are the component library's (lib_scenario_map, 2026-11-26): scenario::place_scenario_map projects them to screen points and the library draws each line as a run of thin turned boxes, restyled every frame from one mount; an outline drops points under 2 px apart, so a country-scale ring costs a few hundred boxes, not thousands.

A rung is stored as a number

An area file stores its rung as its place in Rung. The zoom rail put eight rungs above the world on 2026-11-01, after the CBS files were written and before the others were deployed with it, so every lens file was read four rungs too coarse — a buurt as a "world region", and "This place" compared with no town or country, because no board stood on Municipality. Found 2026-11-17; every lens set was written again on the host that day (atlas areas … --out a staging directory, then moved in; areas.bak-20261117 holds the old ones). board::a_stored_rung_keeps_its_number pins the numbering now.

Tracks, against the drone sheet

The engine samples a track every 2 km to find its stays per area, so a state at any time is a lookup. Against v1-drones at 02:10 it names the same next three provinces as the sheet, 0/2/7 minutes out where the sheet says 2/6/9, because the sheet's gen.ts sampled every four minutes (tests::the_drone_exercise_at_0210_matches_the_sheet).

For a capture: CARTO_SCENARIO=cbs-2024/share_65_plus, and a CARTO_3DBAG_URL that serves areas/ (a loopback stand-in on the node works).