No description
  • Python 99.7%
  • Shell 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
surdeus 623f74f2b3 feat: plate sizes are a step, and a rank law cannot make one
Requested after D-44 matched the largest plate and left the top eight at 56%
against Earth's 95.5%.

Why one law cannot do it: a rank power law target_k ~ k^-spread has one shape.
Matching the Pacific needs spread 0.95, which leaves the top eight at 56%;
raising it to 1.5 lifts the top eight to 75% but overshoots the largest to 32%.
Earth's curve is not a power law - seven majors covering 92.4% with only 2.4:1
between them, a 2.8x cliff to the ninth, then a microplate tail.

The law is two tiers: 7 majors sharing 92% flatly (MAJOR_SPREAD 0.40), the rest
through a steeper tail (MINOR_SPREAD 1.40, which is SIZE_SPREAD). Fitted to
Earth at 52 plates it reproduces all five numbers: top1 20.7% (E 20.3), top7
92.0% (E 92.4), top8 95.1% (E 95.5), 8th/9th 2.6x (E 2.8), 1st/8th 6.6% (E 6.6).
Spread 0 still means equal areas, on a separate single-tier branch.

Writing the law was the easy half. Growth had to become two-phase: growing all
regions at once gives each equal room because _spread_seeds places seeds evenly,
so competition capped each near 1/count and the top eight read 80% with the
cliff flat at 1.0x. Now the majors grow first and stop at their share, then the
tail is seeded in what is left. Three defects surfaced on the way, each pinned:

- regions never stopped: fill_rest handed the majors every leftover cell after
  the heap had correctly stopped them - 99.6% of the world;
- labels collided: both phases numbered from 0, so the total read 157%;
- the phase-two result was assigned rather than merged, leaving 6 plates of 64.

The tail needs a finer mesh: it gets 8% of the world and a minor plate still
needs a cell, so DEFAULT_GROWTH goes 8 -> 14, driven by minimum_growth(). It is
clamped before the mesh is sized - clamping at the merge step cannot add cells
that were never generated - and mondo:plates reports the raise.

Targets are now grown in true surface area. An equatorial cell covers 1.57x the
surface of a polar one of the same projected size, so a share enforced in
projected area makes an equatorial plate too big: measured, the largest reached
27.3% of the true surface against a 20.7% target.

Measured, six seeds: largest plate 20.8% (E 20.3), top eight 92.8% (E 95.5),
dry land 27.2% (E 29.2), continents 5.8, largest continent 20.4% (E 16.5). The
headline is the step: 56% -> 92.8%.

Still off, and recorded: the top-24 ratio is 146:1 against 258:1, so the mid-tier
is fatter than Earth's even though the top eight match; and the largest continent
is 20.4% because crust is a per-plate type, where Earth carries continental crust
across six major plates while only 40% of the surface is continental crust - that
needs provinces, which is D-26's open question.

Four test measurements changed, each for a reason: convexity is now area-weighted
(a microplate is convex by construction, so the median read 1.000); the spectrum
check compares top-eight share (largest:smallest saturates at one mesh cell); D-37
asserts continental area rather than median plate rank; and the Earth-defaults
top-8 band was a record of the gap, so it now asserts 85-99%.

Suite 16/16, 1,976 assertions; plugin builds as 0.34.0.
2026-11-23 04:39:06 +05:00
docs feat: plate sizes are a step, and a rank law cannot make one 2026-11-23 04:39:06 +05:00
qgis_mondo feat: plate sizes are a step, and a rank law cannot make one 2026-11-23 04:39:06 +05:00
tests feat: plate sizes are a step, and a rank law cannot make one 2026-11-23 04:39:06 +05:00
tools feat: basic gates and metrics. 2026-11-21 17:40:46 +05:00
.gitignore feat: started implementing tectonic plates generation, standardized schema of fields. 2026-11-21 18:08:53 +05:00
build.sh feat: crust bodies as objects carried by plates 2026-11-21 23:36:02 +05:00
README.md feat: plate sizes are a step, and a rank law cannot make one 2026-11-23 04:39:06 +05:00

qgis-mondo

A staged, editable pipeline for building a fictional world's terrain inside QGIS. Every stage stops at a real layer you can open, inspect, hand-edit, and re-run from.

Status: six stages built, plus a draft tool. The measurement layer exists and its acceptance bands are validated against ten real mountain regions (docs/metrics.md). Seven QGIS Processing algorithms work and build into a loadable plugin:

  • mondo:draft — plates and the crust on them in one run, for flicking through worlds until one is worth editing. Not a stage: it owns no data, and both layers are written by the stages below with their own recipes and seeds. Both seeds default to 0, which draws a new one each run; pin the shape seed and leave the crust seed at 0 to keep the plates and reroll the crust (D-32)
  • mondo:world — a latitude/longitude window and the planet; the projected extent is derived through the CRS, so it is right in any projection
  • mondo:plates — a Voronoi tessellation that wraps at the longitude seam, so every shared edge is a real boundary and stage 2 has something to find. Ships a velocity arrow at each centroid, turned by the layer's own move_dir_deg. Boundary detail is a parameter: DETAIL segments per tessellation edge and ROUGHNESS for organic displacement, reduced to the largest value the geometry can take and reported when that happens (D-21). Continental crust rides the large plates (D-37): the draw that decides which plates are continental is weighted by plate area, so continents belong to the plate map instead of being sprinkled across it
  • mondo:tensions — one feature per plate boundary, with obliquity, a compression-positive stress in −100..+100, and closing speed. Ships a blue→white→red gradient so extension and compression are visible at a glance
  • mondo:crust — crust as objects: discrete pieces of material, each carried by exactly one plate, with an origin read off the boundary regime it belongs to and an age inherited from the ridge that made it. This is what makes islands possible — under the old model land was a plate property, so the smallest land body was the smallest plate (D-26). Outlines are contour-drawn from a thickness field and the field is discarded; what survives is the objects. Plates shape the margins (D-30): a distance-and-regime field gives a passive margin a shelf, an Andean one its coast on the boundary, a collision land across the suture, and a rift a sea — so a coastline is no longer a noise isopleth that happens to be near a plate. Islands have mechanisms (D-31): island arcs sit on the overriding plate at the arc-trench gap, and hotspot chains trail along each plate's own move_dir_deg at its own move_rate_mm_yr, so a chain's direction and length are the plate's motion. SHARPNESS controls how ragged the coast is: it is the amplitude the small octaves carry, and it is what decides between a smooth arc and bays and headlands (D-33). SUPERSAMPLE draws the outline on a lattice finer than the field, which is what stops a long coast being drawn as a staircase of lattice chords; it is anti-aliasing and cannot add texture, which RESOLUTION does (D-40). The shelf edge follows the margin; the shore does not (D-38): the interior relief now carries its full amplitude at the coast instead of 38% of it, so a coastline is decided by the thickness field rather than by its distance from the plate boundary
  • mondo:landmass — crust bodies dissolved into continents, islands, shelves, inland seas and ocean basins. Grouping is topological over shared edges, and a continent may now span plates — Africa is one continent on the Nubian and Somalian plates, which is only expressible because crust is its own layer. A continent includes its shelf and keeps its seas: an enclosed sea is a hole in the continent and a sea feature of its own, so it is never averaged away and filled in (D-29). Elevation comes with the grouping: Airy isostasy from area-weighted crustal thickness, Parsons–Sclater age–depth for the ocean, so a spreading ridge is shallow and old ocean is deep. This is the level everything downstream erodes from (D-20)
  • mondo:mountains — signed thrust direction and per-side decay, refusing the symmetric case that produces bubbles

Every layer is validated against a declared schema (qgis_mondo/schema.py) and the schema is stored with the data. Two further properties follow from that, and are the reason it exists: a layer generated without the reference map is now possible, and several generators can write the same schema with different content — stage 2 cannot tell a careful tectonic model from a crude random one (D-15).

Two gates survived validation. Three of the five originally proposed were demoted: they failed legitimate terrain, or proved too unstable to gate on. docs/decisions.md D-13 records the rules that follow.

Both gates are specified in physical units — a 1–16 km variogram span, a 25 km walk from a summit — so they apply at any resolution the window can support, not only at the 1 km the reference map happens to use.

Known gap, partly closed. The bubble defect described in docs/mountains.md §1 — the project's central failure mode — has no terrain gate: five statistics were tried and none works at tile scale, because radial symmetry is only identifiable relative to the size of the feature that should have been a range. The resolution is structural rather than statistical, and is built: qgis_mondo/mountains.py uplifts from signed distance with a per-side decay, and direction_response tests whether an implementation reads its own front_dip_deg — 0.45 for a correct one, exactly 0.000 for a distance-field defect, at every bearing and immune to noise. See D-14.

python3 tests/run_all.py               # every suite, one verdict (16 suites)

python3 -m qgis_mondo --dem dem.tif --window 10040,5740,960,1160 --check
python3 tests/test_metrics.py          #  88/88   (pure core, no QGIS)
python3 tests/test_schema.py           # 148/148  (pure core, no QGIS)
python3 tests/test_seeds.py            # 221/221  (pure core, no QGIS)
python3 tests/test_plates.py           # 595/595  (pure core, no QGIS)
python3 tests/test_tensions.py         # 109/109  (pure core, no QGIS)
python3 tests/test_crust.py            # 140/140  (pure core, no QGIS)
python3 tests/test_landmass.py         # 107/107  (pure core, no QGIS)
python3 tests/test_mountains.py        #  34/34   (pure core, no QGIS)
python3 tests/test_earth_defaults.py   #  28/28   (pure core, no QGIS)
python3 tests/test_origin_independence.py  # 15/15 (pure core, no QGIS)
python3 tests/test_stage_draft.py      #  35/35   (headless QGIS)
python3 tests/test_stage_plates.py     # 126/126  (headless QGIS)
python3 tests/test_stage_tensions.py   #  39/39   (headless QGIS)
python3 tests/test_stage_landmass.py   # 310/310  (headless QGIS)
python3 tests/test_stage_mountains.py  #  42/42   (headless QGIS)
python3 tests/test_styles.py           #  57/57   (headless QGIS)
python3 tools/validate_gates.py        # re-derive the bands from real terrain
./build.sh                             # -> dist/qgis_mondo-0.34.0.zip

The name

Mondo is Italian for "world". It is also the honest scope: this builds a world, not a single DEM.

Naming is not cosmetic here. The QGIS Processing provider id becomes the namespace for every algorithm, and therefore for every saved model:

mondo:plates         mondo:tensions     mondo:landmass
mondo:mountains      mondo:dem          mondo:temperature
mondo:precipitation  mondo:hydrology    mondo:erosion
mondo:biomes

A saved .model3 refers to algorithms by that id. Rename the provider later and every saved pipeline breaks silently, because the model points at an id that no longer exists. The name is permanent API.

Conventions, matching qgis-smoothie:

directory   qgis-mondo
package     qgis_mondo
metadata    name=qgis-mondo
provider    mondo      (display: Mondo)

What it is

A pipeline of nine stages, each a QGIS Processing algorithm, wired together by the Graphical Modeler. The defining rule:

Every stage's output is a layer, not an intermediate in memory.

That single rule is what separates this from the generators that already exist. terrain-generator, PlaTec, and WorldEngine all go to raster immediately and keep everything in memory. Mondo keeps vector layers at the stage boundaries — plates are polygons, landmass is polygons, mountains are polygons with attributes — and only converts to raster where raster is genuinely needed.

Consequences, in order of importance:

  1. You can edit any stage. Drag a polygon vertex at stage 3 and stages 4–8 re-derive from it. Two plates share their boundary vertex for vertex, so the drag moves both: the stages that write a partition turn on QGIS's topological editing themselves and say so, and mondo:tensions warns by name and coordinate if an edit ever leaves a vertex mid-edge instead (D-39).
  2. You can stop anywhere. Every intermediate is a layer in the map, not a step you must remember.
  3. Parameters live on the features. A mountain's peak height is a column value, not a slider position in a config dict. You tune the world by editing a table row.
  4. The result is ordinary GIS data. map.gpkg opens in anything. The map is the artifact, not the program that made it.

What it is not

Not a generator that produces a finished world from a seed.

The distinguishing claim is the opposite: Mondo produces a draft you art-direct. Generation runs until the output is good enough to edit, then you edit, then the rest of the chain re-derives from your edit.

This matters because realism and interestingness are close to orthogonal. A physically faithful generator samples mostly ocean and mostly featureless plain, because that is what planets are. The features worth having in a fictional world — a rift valley through a temperate rainforest at a river confluence — are intent, and no model has access to intent. So the design optimises for the moment after generation, when a human decides.

A corollary, and the reason for the "derived vs pinned" distinction that appears throughout docs/architecture.md: without it, the first hand-edit either gets overwritten by the next rebuild or silently contradicts it.

The pipeline

Order is a DAG, not a line. Climate depends only on plates and the DEM; rivers depend on climate; biomes depend on both.

  plates ──→ tensions
     │           │
     └───────────┴──→ landmass ──→ dem ──→ erosion
                                    │
                    ┌───────────────┼───────────────┐
                    ↓               ↓               ↓
              temperature      precipitation    ─ (plate + DEM)
                    └───────────────┼───────────────┘
                                    ↓
                                 rivers
                                    ↓
                                 biomes
# stage in out geometry
1 plates planet parameters plates polygon
2 tensions plates boundaries + stress line
3 landmass plates, tensions continents, crust polygon
4 mountains landmass, tensions ranges + wedge params polygon
5 dem stages 1–4 elevation raster raster
6 climate dem, planet params temperature, precipitation raster
7 hydrology dem, climate rivers, lakes, flow line, raster
8 erosion dem, hydrology shaped terrain raster
9 biomes climate, hydrology biomes polygon

The common ordering mistake, and the reason the table is explicit: rivers need precipitation, so climate must precede hydrology. A chain that puts rivers before climate produces rivers that thread evenly through deserts, which is the single most recognisable way a generated world looks generated.

Why vector stages matter

This is the part that is actually unoccupied. See docs/prior-art.md for what exists and what it does.

The generators that exist skip vector intermediates because raster is easier: one array, one loop, one PNG out. That choice is what makes them non-editable — there is no stage you can reach into.

Keeping polygons at the boundaries buys three things raster cannot:

  • Editability. A coastline is a vertex you can drag.
  • Attributes. A mountain carries its own peak height, base level, and erosion constants.
  • Locality. Work happens per feature, not per grid. Measured on the reference map: the 18 mountain polygons cover 0.0188% of the 337.9 M-cell grid, and their bounding boxes 0.0294% — 3,407× less work per pass. Timed, all 18 boxes through 20 erosion iterations takes 0.33 s, against a scaled whole-grid figure of 1,127 s.

The locality point is not a micro-optimisation. Mountain realism wants iteration to steady state, not a fixed 20 passes, and iteration is only affordable when the domain is per-feature. See docs/mountains.md.

Design principles

  • The map is the artifact. Generated worlds are defined by seed + parameters + algorithm version + RNG order — an identity that is a hash and dies with the toolchain. Layers survive.
  • Guarantees belong in mechanism. Determinism, staleness, and parameter storage are enforced by the pipeline, not by a note asking you to remember. This is the same principle as the map repo's pre-commit gate.
  • Stable keys, never fid. GeoPackage fids are INTEGER PRIMARY KEY AUTOINCREMENT and are consumed on regeneration, never reused. Downstream stages join on a propagated uid.
  • Derived vs pinned. Every layer is one or the other, and the rebuild respects it. This is what makes "generate, edit, continue" safe.
  • A random seed is not an unknown seed. Every seed parameter accepts 0, meaning choose one for me; the drawn value is written into the layer and the recipe, and the run says which one it used. A layer never records 0, because a world whose seed is unknown can never be rebuilt (D-22).
  • Validate before generating. A consistency checker over the chain is worth more than another generator, and is cheaper. See docs/decisions.md D-9.

Adding a stage

The invariants below are enforced by tests, not by memory. python3 tests/run_all.py must pass before a change lands.

  1. Declare the schema first in qgis_mondo/schema.py. Every field needs a meaning; bearings declare a domain, not a convention.
  2. Put the maths in a pure core that imports no QGIS or GDAL, so it can be tested on a machine with neither (metrics, plates, tensions, landmass, mountains are the models).
  3. Register it in tests/run_all.py — an unregistered suite does not run, and a suite that does not run is a document with extra steps.
  4. If it consumes coordinates, add it to tests/test_origin_independence.py. A stage must not care where the map sits (D-17). This is the defect that put half a world's boundaries in the wrong place, and every existing test passed at the time.
  5. Validate against the schema, not by hand. A stage that checks fields itself will drift from the ones that call schema.validate_feature.
  6. Write the recipe in postProcessAlgorithm, never in processAlgorithm: while the output sink is open GDAL holds a transaction and the write fails silently (D-14).
  7. Style the loaded layer, not only the file. The output layer exists before postProcessAlgorithm runs, so a style written to layer_styles does not reach the layer already on the canvas. Install a QgsProcessingLayerPostProcessorInterface on the output instead (D-18).
  8. If it groups or dissolves features, derive the uid from the inputs. A random uuid makes every rebuild look like a new feature, and anything pinned downstream detaches (D-20). The uid must change when the membership changes, and only then.

Three classes of bug have appeared more than once here, and each has a test now. Fixtures at a special value test that value rather than the code — the flat-fraction band excluded plains from its population, the asymmetry statistic used one peak-spacing, and the coordinate tests sat at origin zero. If a new fixture picks a convenient value, ask what the code does at an inconvenient one.

Repository layout

README.md              this file
qgis_mondo/metrics.py  terrain metrics (pure NumPy, no QGIS)
qgis_mondo/mountains.py  signed-distance uplift + the direction test
qgis_mondo/schema.py   layer contracts: fields, units, domains, validation
qgis_mondo/plates.py   stage 1 core: periodic Voronoi tessellation
qgis_mondo/tensions.py stage 2 core: boundary chaining + classification
qgis_mondo/stage_tensions.py  stage 2: boundaries from the plate layer
qgis_mondo/stage_world.py   stage 0: extent + planet as a layer
qgis_mondo/stage_plates.py  stage 1: plates from the world layer
qgis_mondo/gates.py    acceptance thresholds, verdicts, exit codes
qgis_mondo/dem.py      GDAL window reader (the adapter boundary)
qgis_mondo/provider.py Processing provider: the "mondo" namespace
qgis_mondo/stage_mountains.py  stage 4: thrust direction and per-side decay
qgis_mondo/gpkgmeta.py stage parameters written into the GeoPackage
qgis_mondo/metadata.txt plugin metadata (QGIS requires it in the module)
qgis_mondo/__main__.py CLI: report, --check, --compare
tests/test_metrics.py  88 assertions, analytic fixtures + reference map
tests/test_mountains.py  34 assertions, directional uplift
tests/run_all.py         runs every suite; nonzero exit on any failure
tests/test_schema.py     91 assertions, the layer contract
tests/test_origin_independence.py  the map's position must not change output
tests/test_styles.py     the default styles, rendered and measured
tests/test_plates.py     49 assertions, tessellation + wrapping
tests/test_tensions.py  105 assertions, classification + chaining
tests/test_stage_mountains.py  42 assertions, headless QGIS adapter
build.sh              package the plugin archive QGIS can install
tools/validate_gates.py      re-derives every gate band from real SRTM terrain
docs/architecture.md   the pipeline, the layer contract, staleness
docs/mountains.md      the hard problem, with measurements
docs/metrics.md        the measurement layer, calibration, and 3 findings
docs/prior-art.md      what already exists, and what is left
docs/decisions.md      decisions and the reasoning behind each

Reference world

All measurements in docs/ come from the Vir map (/home/surdeus/dev/monada-vir-map), which is the reference case:

  • dem.tif — 24,002 × 14,078, Int16, 1 km cells, no declared nodata; sea is -1. CRS ESRI:54001 World Plate Carrée.
  • 337.9 M cells. One float32 raster over it is 1.35 GB.
  • Extent reads as latitude −63.7°..+62.8°, longitude −107.7°..+107.9° — a region on a globe, not a full planetary surface. No poles.
  • Two continents under active work; the rest are flat zero-height drafts. Measured: 0.7% of cells are land with any elevation (84.2% sea, 15.1% flat zero). It is a draft, not a finished world.

Numbers quoted from it are measured unless marked otherwise. Where a figure is recalled rather than verified, it says so.

Its four distinct roles, and which of them hold, are set out in docs/metrics.md §4.5. Short version: it is a sound calibration target and a sound ground truth for plates and tensions (11,822 hand-drawn vertices), but it is a negative control only per window — its two terrain defects are complementary, not co-located — and it is not a reference for terrain quality, because almost none of it has been built.