diff options
| author | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
| commit | 3443c1c65e9f1753e1e656b35d08416c1fa298f2 (patch) | |
| tree | 4e43236f460145a4d75d1b4616dcb7aa6ef08f51 /tests/helpers.py | |
| download | worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.tar.gz worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.zip | |
worldmap-viewer: initial public history
Diffstat (limited to 'tests/helpers.py')
| -rw-r--r-- | tests/helpers.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 0000000..1bb865b --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,39 @@ +import copy +import functools +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + +BASE_CFG = { + "planet": {"radius_km": 12742.0, "gravity_g": 1.05, "day_hours": 31.149, "year_days": 216, + "tilt_deg": 20.0, "sea_level_pressure_bar": 1.0, "scale_height_km": 8.0, "o2_fraction": 0.21}, + "build": {"seed": 7, "res_dev": 2, "res_final": 2, "raster_width": 256, "preview_width": 128, + "land_fraction": 0.22}, +} + + +@functools.lru_cache(maxsize=4) +def small_grid(res: int = 2): + from mapgen.grid import build_grid + return build_grid(res, 12742.0) + + +def make_ctx(res=2, data=None, cfg=None, tect=None, root=None): + from mapgen.pipeline import Ctx + c = copy.deepcopy(BASE_CFG) + for sec, vals in (cfg or {}).items(): + c.setdefault(sec, {}).update(vals) + ctx = Ctx(root or ROOT, c, tect or {"plate": []}, res) + ctx.grid = small_grid(res) + ctx.data = dict(data or {}) + return ctx + + +def big_river(a) -> int: + """The cell of the biggest river that flows on over land (not into a lake at its own level, which cuts no + valley, nor off a coast, like a basin lake's spillway): the fixtures' river.""" + import numpy as np + river, lake = np.asarray(a["river"]).astype(bool), np.asarray(a["lake"]).astype(bool) + recv = np.asarray(a["recv"]) + wet = lake | np.asarray(a["ocean"]).astype(bool) + return int(np.argmax(np.asarray(a["discharge_km3_yr"]) * (river & ~wet & ~wet[recv]))) |
