# How this explainer was made: working notes

Running log of every step, so the explainer page, the book and the paper can be checked, rebuilt and trusted. Newest steps at the bottom.

## 0. The request (29 Nov 2026, 00:13)

Fabio: "Make this a page to explain it to the whole world, fill it with actual renderings and graphical explanations, for web, print and an academic paper in LaTeX (low priority, but super high precision, accuracy and authority). I also want a book, print-friendly versions."

Deliverables:
- `how/index.html`: web explainer, with a print stylesheet.
- `how/print-the-world-book.pdf`: typeset book (LaTeX), plus its sources.
- `how/print-the-world-paper.pdf`: academic paper (LaTeX), plus its sources.
- This file.

Rule I set myself: **every figure comes from the site's real code on real data**, not a re-implementation, and every number in the text is traced to a run recorded here.

## 1. Getting real elevation data out

Problem: my workspace (Anthropic cloud) cannot reach `tiles.mapterhorn.com`; network allowlist. The shell on Fabio's Mac (device_bash) has no network either. Only the browser pane on Fabio's Mac can fetch tiles.

Steps:
1. Added one line to `app.js` (v31): `window.isole.pipeline = { loadTiles, pickZoom, makeSampler, buildGrid, boundsAt, snap }`. No behaviour change; it only exposes functions already there.
2. In the browser pane at `localhost:8000`, for each site: `boundsAt(lat, lng, groundMetres)` → `pickZoom(b, 256)` → `loadTiles` → `buildGrid(b, makeSampler(tiles), 256)`. That's exactly what the site does on "Make the model", at Draft detail (n = 256).
3. Encoded heights as uint16 `(h + 100) × 10` (0.1 m steps), gzipped with `CompressionStream`, base64. Returned as a large tool result, which the harness saves to a file; decoded in the workspace with numpy.
4. Round-trip checked: min and max after decoding equal the browser's to 0.1 m.

Sites (frame centre, frame width on the ground, tile zoom used):

| site | lat, lng | frame | zoom | height range |
|---|---|---|---|---|
| Elba | 42.770, 10.270 | 42 km | z9 | 0 to 949 m |
| La Maddalena | 41.235, 9.430 | 16 km | z10 | −0.1 to 191 m |
| Etna | 37.751, 14.995 | 30 km | z10 | 60 to 3,301 m |
| Stromboli | 38.794, 15.211 | 6 km | z12 | 0 to 918 m |
| Matterhorn | 45.976, 7.659 | 11 km | z11 | 1,725 to 4,459 m |

Files: `data/<site>.npy` (256 × 256 float32, metres), `data/meta.json`.

Caveat for the text: at 256 points the Matterhorn grid peaks at 4,459 m, not the surveyed 4,478 m. Sampling at 43 m spacing smooths the very tip.

## 2. Running the site's real pipeline in Node

`harness/pipeline.js` is built by **cutting the source text out of `app.js`** (from `const buildStl` to the end of `buildSea`, lines 618–1200 of app.js v31) plus its constants (`EARTH`, `ISLAND_CUT_M = 1`, `GAP_MM = 0.11`, `MARGIN_MM`, `VEXAG_STEPS`). Nothing re-typed.

`harness/pipeline_tapped.js` is the same, with four read-only taps inside `squaresAbove` that copy the land mask after each stage: `raw` (four-corner rule), `filled` (lakes filled), `kept` (crumbs dropped), `final` (pinches fixed). The taps only copy; they change nothing.

`harness/run.js` runs the same decision as `make()` in app.js:
- an island if some but not all squares are land;
- otherwise `mountainSquares`;
- otherwise a square tile.

Settings: 150 mm wide, relief auto, base 3 mm.

Results:

| site | shape | relief | top (mm) | triangles | notes |
|---|---|---|---|---|---|
| Elba | island + sea | 3× | 13.2 | 41,140 + 2,360 | 3 land pieces, frame edge cuts land |
| La Maddalena | island + sea | 3× | 8.4 | 78,644 + 5,232 | 7 pieces |
| Stromboli | island + sea | 1× | 25.9 | 93,300 + 2,200 | whole island inside frame |
| Etna | mountain | 1.2× | 27.3 | 115,952 | cut at 233 m, slope 0.25, first try |
| Matterhorn | mountain | 1.2× | 33.1 | 43,488 | cut at 2,929 m, slope 0.25, 18th try |

Stage counts, from the taps:
- **Lakes filled:** 6 squares at La Maddalena; none elsewhere.
- **Crumbs dropped:** 311 squares in 8 crumbs at La Maddalena (threshold 110 squares = 2% of the largest piece, 5,482); 13 squares at Elba.
- **Pinches fixed:** 0 on all five sites at n = 256. The figure for that step is a schematic, and the text says so.

Every STL is watertight (trimesh `is_watertight`).

## 3. Verifications done so far

- **Smoothing:** a numpy copy of `smoothed()` (separable 5-tap kernel [0.054, 0.244, 0.403, 0.244, 0.054], edge clamped) reproduces the site's `raw` mask exactly on Elba, La Maddalena and Stromboli (0 squares differ). So the figures of softened heights show exactly what the site computes.
- **Gap:** sliced both Elba STLs at z = 1.5 mm with trimesh and shapely. Minimum distance island→sea 0.220 mm, median 0.220 mm, overlap 0. The 0.22 mm in the text is measured, not just declared.
- **Matterhorn cut:** the formula reproduces the site's cut: lowest = 2nd percentile of softened heights = 2,011.0 m; highest = summit 4,403.8 − max(40, 12% of (summit − lowest)) = 4,116.6 m; try t = 17 of 40 gives 2,011.0 + (4,116.6 − 2,011.0) × 17/39 = 2,928.9 m. That equals the site's `ref`.
- **Auto relief:** the step rule puts all five sites on the steps the code chose:
  - Elba: steepness 0.023 → 3×
  - La Maddalena: 0.012 → 3×
  - Stromboli: 0.190 → 1×
  - Etna: 0.135 → 1.2×
  - Matterhorn: 0.167 → 1.2×

## 4. Figures

- **3D renders:** `render/render.html` (three.js 0.170, STLLoader, orthographic camera, hemisphere plus directional light), shot by `render/shoot.py` with headless Chromium (SwiftShader WebGL). The renders show the real STLs.
- **2D figures:** `figs.py` (palette and helpers) and `make_figs.py`, with matplotlib, Instrument Sans and Serif. Output as PNG (220 dpi), PDF and SVG.

| figure | shows | data |
|---|---|---|
| fig-grid | frame, then 256 × 256 points | Elba grid |
| fig-smooth | 5 × 5 weights; raw vs softened land, 11 vs 5 pieces in the same crop | La Maddalena |
| fig-corners | real softened heights, four-corner rule (asserted against the site's mask) | La Maddalena |
| fig-lakes | 6 enclosed water squares filled | La Maddalena taps |
| fig-crumbs | 7 kept, 8 dropped, threshold 110 | La Maddalena taps |
| fig-pinch | diagonal pinch | schematic |
| fig-mountain | 18 tried outlines, chosen one; west–east profile with cut levels | Matterhorn taps |
| fig-section | true-scale section of the Elba model | Elba |
| fig-gap | side view at the coast, to scale, 0.59 mm squares | constants from code, measured gap |
| fig-relief | auto relief steps with the five sites | facts-relief.json |

Renders: r-elba, r-elba-exploded, r-stromboli, r-maddalena, r-etna, r-matterhorn.

Honest findings to report, not hide: the Matterhorn mountain comes out as a thin, deep strip, because valleys drain to the frame edge at every level below about 2,900 m, so the outline only closes high up. That's a real limitation of the rule.

## 5. Research: sources the text relies on

**Copernicus DEM (GLO-30)**
- A Digital Surface Model (includes buildings, vegetation), 30 m.
- From TanDEM-X acquisitions 2011–2015. Vertical datum EGM2008 (EPSG:3855).
- Spec: absolute vertical accuracy < 4 m (90% linear error); absolute horizontal < 6 m (CE90).
- Edited: water bodies flattened, shorelines edited.
- Required notice: "produced using Copernicus WorldDEM-30 © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved."
- Sources: Copernicus DEM Product Handbook v5.0 (2022); Copernicus Data Space collection page; Leister-Taylor 2015 ESA slides (accuracy figures).

**Mapterhorn** (Oliver Wipfli; NLnet-funded; github.com/mapterhorn/mapterhorn, pipelines/README.md, read from a git clone on 29 Nov 2026):
- **Projection and tiles:** everything is reprojected to Web Mercator, in 512 px tiles, Terrarium encoding, WebP.
- **Merging:** source groups are ordered by local maxzoom (higher = finer = more important), then lexicographically. The best source is used; its no-data pixels are painted from the second best, then the third, and so on. A Gaussian blur is applied along the seams between sources.
- **Overviews:** lower zooms are made by 2×2 averaging.
- **Bundles:** planet.pmtiles holds z0–12; 6-x-y bundles hold z13+.
- **Vertical rounding:** 1 m at z ≤ 11, 0.5 m at z12, 0.25 m at z13, …, 1/256 m at z19. The README notes the minimum representable slope is the same at every zoom, about atan(1/38.2) ≈ 1.5°.

**Consequence for this project:** the figure grids (z9–z12) carry heights rounded to 1 m (0.5 m at z12). The 1 m coastline threshold therefore sits at the first quantisation step above 0. Worth stating in the paper.

**Terrarium:** elevation = R·256 + G + B/256 − 32768 (Mapzen/Tilezen documentation; joerd).

**Sources under each frame**, read from the site's own panel (Mapterhorn coverage plus attribution.json):

| site | sources |
|---|---|
| Elba | TINITALY 1.1 10 m (INGV, CC BY 4.0); Copernicus GLO-30 |
| La Maddalena | Regione Autonoma della Sardegna DTM/DSM 1 m (2013 flight, CC BY 4.0); TINITALY; GLO-30 |
| Etna, Stromboli | Regione Siciliana MDT 2 m (ATA 2012–2013 flight, CC BY 4.0); TINITALY; GLO-30 |
| Matterhorn | swissALTI3D 0.5 m (swisstopo, OGD); Regione Autonoma Valle d'Aosta DTM 2 m (CC BY 4.0); TINITALY; GLO-30 |

**Datasets:**
- **TINITALY:** Tarquini et al. 2023, doi:10.13127/tinitaly/1.1; Tarquini et al. 2007, Annals of Geophysics 50, 407–425, doi:10.4401/ag-4424. A DTM (bare ground).
- **swissALTI3D:** swisstopo product info. Accuracy ±0.3–0.5 m 1σ below 2,000 m; ±1–3 m 1σ above 2,000 m.

**Prior work:**
- **TouchTerrain:** Hasiuk, Harding, Renner, Winer 2017, Computers & Geosciences 109, 25–31, doi:10.1016/j.cageo.2017.07.005. Harding, Hasiuk, Wood 2021, ISPRS IJGI 10(3):108, doi:10.3390/ijgi10030108; more than 20,000 models downloaded July 2019 to January 2021.
- **Prominence:** Kirmse & de Ferranti 2017, Progress in Physical Geography 41:788–802, doi:10.1177/0309133317738163.
- **Connected components:** Rosenfeld & Pfaltz 1966, J. ACM 13(4):471–494, doi:10.1145/321356.321357. Rosenfeld 1970, "Connectivity in digital pictures", J. ACM 17(1):146–160.
- **Earcut:** mapbox/earcut, modified ear slicing with z-order hashing; Eberly, "Triangulation by Ear Clipping".
- **Fit clearance:** university fab-lab guidance of 0.15–0.2 mm (UAL CCI wiki); Grgić et al. 2023, Processes 11:2810.
- **Relief cartography:** Imhof 1965/2007, Cartographic Relief Presentation; vertical exaggeration = vertical scale ÷ horizontal scale.

## 6. Code facts checked for the text (app.js v31)

- **Grid:** n × n points, uniform in Web Mercator over a square frame. The ground width uses cos(latitude at the frame centre). Heights are sampled bilinearly from the decoded tile pixels.
- **Tile zoom:** z = ceil(log2(n / (span × 512))), capped at the source maxzoom, lowered until there are ≤ 64 tiles. Above z12, a missing tile falls back to its parent.
- **Smoothing:** a separable 5-tap kernel [0.054, 0.244, 0.403, 0.244, 0.054]. This is a sampled Gaussian with σ = 1 sample, normalised over ±2 samples; edges are clamped. Used only to decide the outline.
- **Land:** a square is land iff all 4 corner points of the smoothed grid are above the level. For islands the level is 1 m; for mountains it's level(i, j).
- **Connectivity:** connected-component labelling by stack flood fill with 4-connectivity, for both land and water.
- **Lakes:** water components not touching the frame border become land.
- **Crumbs:**
  - Islands keep components of at least max(24, 2% of the largest).
  - Mountains keep only the component containing the summit square, or the largest if the summit is not land.
- **Pinches:** a 2 × 2 block with land on one diagonal only loses one square (sq[d] or sq[c]). Repeated up to 12 passes.
- **Mountain level(i, j)** = cut + max(0, r·cell − flat)·slope, where r is the distance in squares from the frame centre and flat = 0.55 × (n·cell/2).
  - Slopes tried in order: 0.25, 0.5, 0.9, 1.5.
  - Cuts tried: 40 steps from lowest (2nd percentile) to highest (summit − max(40 m, 12% of the range)).
  - Accept the first outline that doesn't touch the edge, has at least max(30, 200·m²/399²) squares, and at most 80% of the squares.
  - The summit is the highest smoothed point within 8% of n of the centre.
- **Solid:**
  - cell (mm) = width / span, where span = m for islands (the whole frame) and the outline's bounding-box span for mountains.
  - z = base + max(0, h − ref) × (cell / groundCell) × vexag. ref = 0 for islands; ref = the cut for mountains.
  - Top: 2 triangles per kept square, vertices at the grid points. Bottom: flat at z = 0, 2 triangles per square. Walls: 2 triangles per boundary edge.
- **Auto relief:** steepness = max(h − ref) over the bounding box ÷ (bounding-box span × groundCell). Steps: ≥ 0.18 → 1; ≥ 0.12 → 1.2; ≥ 0.07 → 1.5; ≥ 0.04 → 2; ≥ 0.025 → 2.5; otherwise 3.
- **Gap:**
  - Island boundary vertices move by the sum of the inward unit normals of their boundary edges × 0.11 mm, so a straight wall moves 0.11 mm and a corner moves (0.11, 0.11).
  - Sea outline corners move 0.11 mm along both adjacent edge normals, away from the land, except along the frame edge. Collinear points are merged.
  - Sea polygon triangulated with earcut, slivers flipped. Corners get a 2e-5 mm deterministic jitter to avoid exact degeneracies.
- **Digital topology note:** using 4-connectivity for both land and water is the case Rosenfeld showed to be paradoxical; land and water can each "cross" at a diagonal. The pinch fix removes exactly those diagonal contacts, so the final land set is unambiguous.

## 7. The web page (`how/index.html`, `how/how.css`)

- One editorial column (40rem text, 60rem figures), site palette, Instrument Serif and Instrument Sans. Ten numbered steps, each with real figures; tables for sources and results; references.
- Print stylesheet: A4, each step on a new page, URLs printed after the references.
- Images:
  - 3D renders: WebP plus PNG fallback, 2,000 px wide.
  - Figures: WebP at 220 dpi.
- After Fabio said the images might be too light, I re-rendered at 2× with stronger directional light, ACES tone mapping and deeper peach and indigo, and deepened the land and sea colours in the 2D figures.
- Claims fixed before publishing:
  - The corner example named the wrong square.
  - "Pinches appear at finer detail" was unverified, so I removed it.
  - Added the half-metre rounding at z12.
- Linked from the site's top bar ("How it works").
- Share card: `how/img/og-how.png`.

## 8. The book (`how/print-the-world-book.pdf`, source in `how/src/book`)

- XeLaTeX, memoir, 170 × 240 mm, 36 pages; chapters open on right-hand pages.
- Fonts: Instrument Serif, plus static Regular and SemiBold instances cut from the Instrument Sans variable font with fontTools (XeTeX can't select named instances).
- Figures: white-background print variants (`PRINT=1 python3 make_figs.py`) and 3D renders flattened on white.
- Factual fixes found while proofreading:
  - Terrarium precision is 1/256 m ≈ 4 mm, not "a fraction of a millimetre".
  - Elba at true scale on a 150 mm model rises 949 × 150/42,000 ≈ 3.4 mm, not 4 mm.
  - The 1 m threshold is presented as why it works, not as the designer's documented intent.

## 9. The paper (`how/print-the-world-paper.pdf`, source in `how/src/paper`)

- pdfLaTeX, article class built up into a journal-style preprint after Fabio asked for "typeset like a proper academic paper":
  - layout: two columns, Times (mathptmx);
  - front matter: full-width title block with affiliation, an Article-info box with keywords and data, abstract between rules;
  - running head "F. Venni / … · Preprint, November 2026";
  - numbered bold sections, italic subsections, run-in paragraph heads;
  - "Fig." captions, wide figures and tables across both columns, numbered references.
- No journal class (elsarticle, IEEEtran, acmart) is installed and CTAN is unreachable from the workspace, so the look is built from standard packages. No journal name is claimed.
- Content:
  - formal definitions taken from the code (Sections 3.1–3.8);
  - results table;
  - limitations: quantisation, DSM/DTM, projection, sampling, ranges, printing;
  - reproducibility section.
  - Authorship: Fabio Venni, with an acknowledgement of AI assistance.
- The one-column draft is kept as `src/paper/paper-onecol.tex`.

## 10. Authorship (00:40)

At Fabio's request, everything is credited as "Claude Opus 5.5, prompted by Fabio Venni":
- paper: title block with affiliations (a: Anthropic, b: Antanix), running head, and an authorship statement in the acknowledgements;
- book: title page and colophon;
- web page: byline under the lead.

## 11. Final checks (29 Nov, ~00:45)

- **Browser pane on Fabio's Mac, localhost:8000:**
  - Main site shows "How it works" in the top bar.
  - These all return 200: /how/, both PDFs, NOTES.md, og-how.png.
- **Explainer at 375 px:** no horizontal overflow. Tables scroll sideways inside their box; captions are pinned so they wrap.
- **Print stylesheet,** rendered to PDF with headless Chromium and the real fonts: 17 A4 pages, one step per page, figures not split, URLs printed after the references.
- **Paper:** pdfLaTeX, 7 pages, 0 overfull boxes, 0 undefined references.
- **Book:** XeLaTeX, 36 pages, fonts embedded.

**Not checked:**
- a real phone or iPad;
- Safari and Firefox;
- an actual printer for book or page;
- an independent expert review of the paper.

Nothing is deployed: Fabio runs `mondo`.

## 12. Paper in LaTeX's own typeface (29 Nov, 15:20)

At Fabio's request ("should look more like it came out of LaTeX"):
- Body: Times (mathptmx) and Helvetica replaced by Latin Modern (`lmodern`), the default Computer Modern look.
- Paper figures re-rendered with LM Roman 10 labels and Computer Modern maths (`PRINT=1 LATEXFONT=1 python3 make_figs.py` → `figs-paper/`).
- `\raggedbottom`, so columns aren't stretched with gaps between paragraphs.
- Running head shortened so it no longer collides with "Preprint".
- 7 pages, 0 overfull boxes, 0 undefined references.

## 13. Move to printtheworld.antanix.net (30 Nov)

- All hard-coded https://antanix.net/mondo-751f19/ addresses changed to https://printtheworld.antanix.net/:
  - share-card URLs on the site and on the explainer;
  - the paper's reproducibility section;
  - the book's last chapter.
- `printtheworld-setup.sh` (run by Fabio on his Mac):
  - adds a `ptw` alias and repoints `mondo`, both deploying `$SITES/print-the-world` to the subdomain; the server path pattern is copied from the `pietre` alias;
  - copies the server folder there;
  - leaves a 301 redirect in the old folder, so shared links keep working; browsers keep the #model part of the link across the redirect.
