From 7bf01fb54f6048b186fed562f7fc76afa29b0ce9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 25 Nov 2026 03:10:04 +0100 Subject: [PATCH] ridge-bake: near-only card-0 tiles bind r_max at the clip they are slid at; mutate.py runs the unmutated copy first and kills only on an AssertionError Co-Authored-By: Claude Sonnet 5.5 --- docs/gamecult/ridge-backdrop-target.md | 2 +- scripts/ridge-bake/README.md | 2 +- scripts/ridge-bake/export.py | 8 ++--- scripts/ridge-bake/ridge-bake.schema.json | 2 +- scripts/ridge-bake/tests/mutate.py | 37 ++++++++++++++++------- scripts/ridge-bake/tests/test_ridge.py | 18 ++++++----- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/docs/gamecult/ridge-backdrop-target.md b/docs/gamecult/ridge-backdrop-target.md index 5b78b32b..83e6b1ad 100644 --- a/docs/gamecult/ridge-backdrop-target.md +++ b/docs/gamecult/ridge-backdrop-target.md @@ -7,7 +7,7 @@ The live noise ridge is nearly invisible on a phone (about 1.35:1 against the da ## Ends - One owner per decision: the baker owns ridge geometry and shading; the runtime owns only the ring's residency, the camera's pose against its heading, blending and compositing. No ridge geometry is computed in the browser. -- The ground under the authored 500 m near clip is the place's own DEM from 1 m, drawn by card 0 inside the silhouette of the terrain at the clip and riding card 0's slide; everything that bounds the view reads terrain at or beyond the clip: `r_max` is where the linear slide holds for the nearest solid terrain each card draws in each tile (a tile of near ground only binds nothing), and every bake keeps 150 rows under the horizon so the plane reaches the bottom of every viewport. +- The ground under the authored 500 m near clip is the place's own DEM from 1 m, drawn by card 0 inside the silhouette of the terrain at the clip and riding card 0's slide; everything that bounds the view reads terrain at or beyond the clip: `r_max` is where the linear slide holds for the nearest solid terrain each card draws in each tile (a tile of near ground only binds at the clip, 500 m, where it is slid), and every bake keeps 150 rows under the horizon so the plane reaches the bottom of every viewport. - Nothing from the scene paints above app content: the scene is one stacking context at the back of the app, and nothing it creates has its own z-index or lives outside it. - Phone cost is bounded: no per-frame script for the ridge, decoded size and fetched size gated in CI. - The ring is the bake and the heading is unbounded: the whole 360 degrees ships as azimuth tiles, the client holds only the arc it is about to need and fetches more as the view turns, and nothing caps the heading: it is unwrapped within a stretch of motion and `ridge/heading.ts` `normalize` brings it into [0, 360) before each one, so no angle or pixel position grows with uptime, while `ridge/ring.ts` is the one place that reasons about the wrap at 0 / 360. diff --git a/scripts/ridge-bake/README.md b/scripts/ridge-bake/README.md index 20681620..83ecac2c 100644 --- a/scripts/ridge-bake/README.md +++ b/scripts/ridge-bake/README.md @@ -35,7 +35,7 @@ Files are `Copernicus_DSM_COG_10_dd_00_ddd_00_DEM.tif`; the list below 4. **Seams.** `coverage` counts the visible rows of the opaque view per log-distance bin and column. `seams` finds one seam per authored split per column by dynamic programming (seam carving, forward energy): it sits in a gap between depths, moving it costs 2 per bin plus the visible rows it sweeps (so it never hops across a ridge between two columns and splits it side by side), a seam inside visible terrain is cheap to cross-fade, the authored depth only breaks ties. Seam k stays 0.4 nat beyond seam k-1. The DP runs over the ring three times side by side and keeps the middle lap, so a seam is continuous across the wrap (column 6399 to 0) and a tile boundary is only a crop. 5. **Cards.** `cards` runs per tile, on that tile's columns and the matching normals (it is column-independent: a tile is a crop of per-column results, so no seam appears at a tile boundary). It makes card i from the first visible hit at or beyond seam i-1 (layered depth: a farther card keeps the terrain a nearer ridge hides), alpha 1 minus a smoothstep over seam i in log-distance (the cross-fade), crest rows with fractional coverage, distance and normal interpolated between samples by angle, albedo from a small height and slope material, cropped to the rows where alpha is not zero. The rows of card i > 0 below the angle of its first sample (hit and first sample of the card) are its **wall**: the extruded face of the ridge the card starts at, which keeps that sample's distance, wears the ground material at its height with the face up, and is flagged `wall`. Card 0 also draws the **near march** (ruling `ridge-near-ground-outline`): the place's own DEM from `NEAR_START_M` = 1 m to the near clip `NEAR_CLIP_M` = 500 m (`near_march`: float64 bilinear samples every max(1 m, 0.02 d) up to 10 m, about 170 per column, low-passed with the place's own `prefilter_m`), joined to the far march by `join_near` on the whole ring before the tile cut, its angles capped per column at the angle of the clip sample so the near ground draws inside the silhouette of the terrain at the clip (a near hill above that edge is cut along it). Its rows are ordinary terrain with their own normal and the albedo of their own height and n_up, flagged `near` in memory; `cards` refuses a march that starts at the clip. The runtime reads them as ground at the clip distance (they decode at `log_d_min`) and lights them like any card pixel. The alpha-over composite of the cards equals the opaque view; `check_cover` refuses a tile that differs by more than 0.02. 6. **Tiles.** The ring is absolute compass, column 0 = north, column c at azimuth (c + 0.5) / 6400 x 360; `places.json`'s `az_deg` / `look_at` is only the rest azimuth (`view.look_az_deg`). Tile t owns columns [200 t, 200 t + 200) (11.25 degrees) and its files hold [200 t - 2, 200 t + 202): two columns of real neighbour data each side (the client's ink pass and lighting read one texel each way; the client crops it), taken periodically by `ridge.ring_cols`. Per card and tile the file is cropped to the rows where that tile's 8-bit alpha is not zero (`top`, `h`); a card that holds nothing in a tile is `null` there (the client interpolates its distance from the neighbours); a card with no solid pixel in any tile is refused. -7. **Distance and the offset range.** The bake holds no camera (ruling `ridge-camera-full-ring`). `pack` gives each card tile `distance_m` = exp(median ln d) over the tile's solid pixels that are neither wall nor near ground (its interior 200 columns); the client derives each card's slide from that and the viewer's offset r and heading. `camera.r_max_m` is the largest |r| (never above half the nearest terrain's distance) at which, for every tile, card and phi (24 steps of the camera's angle on the circle against its heading; the offset-only rotation mode moves phi round the whole circle), the least-squares line `a + s beta` fitted to the exact view angle `atan2(R sin beta - r sin phi, R cos beta - r cos phi)` over the widest viewport (`HFOV_MAX_DEG` = 72 / 1.1) errs by at most `FIT_PX_MAX` = 24 card px (the continuous error: the line by quadrature over the viewport, the worst error looked for on 513 points, so a handful of samples cannot undercount it); the distance d is that of the NEAREST solid (alpha >= 0.5, neither wall nor near ground) pixel the card draws in the tile's interior columns, which is where the slide errs most (the line is fitted for the tile's `distance_m`, the median, but the bound is held for the nearest terrain: a tile whose terrain spans 600 to 2000 m is bound at 600 m); a tile whose card 0 draws only near ground (under the clip) has no such pixel and binds nothing; and the resident gate (below) must hold at r_max_m too. `camera.r_max_forward_m` is the same search at phi = 0 alone (same `FIT_PX_MAX`, the same half-distance cap, the same resident gate): the camera pushed forward along its heading, which is where the offset stays when the view direction turns with it (the modes 'still' and 'both'), so it is at least `r_max_m`; the client takes `r_max_m` for the offset-only mode and for a backward offset, `r_max_forward_m` for a forward one in the other modes (`view.ts` `offsetRange`). `FIT_PX_MAX` is provisional, tuned by eye (ruling `ridge-offset-range-fit`). A bake whose `r_max_m` is below `R_MAX_FLOOR_M` = 25 m is refused, naming the card and tile. `distance_m` and the nearest-terrain table exclude the near ground (a tile with nothing outside it gets `distance_m` = 500 m), so card 0's distances are never nearer than the near clip (`write_bake` refuses one that is), and `r_max_m` and `r_max_forward_m` hold for the nearest solid terrain each card draws in each tile, at or beyond 500 m, near-only tiles excluded: the ground nearer than that rides card 0's slide and is not measured. +7. **Distance and the offset range.** The bake holds no camera (ruling `ridge-camera-full-ring`). `pack` gives each card tile `distance_m` = exp(median ln d) over the tile's solid pixels that are neither wall nor near ground (its interior 200 columns); the client derives each card's slide from that and the viewer's offset r and heading. `camera.r_max_m` is the largest |r| (never above half the nearest terrain's distance) at which, for every tile, card and phi (24 steps of the camera's angle on the circle against its heading; the offset-only rotation mode moves phi round the whole circle), the least-squares line `a + s beta` fitted to the exact view angle `atan2(R sin beta - r sin phi, R cos beta - r cos phi)` over the widest viewport (`HFOV_MAX_DEG` = 72 / 1.1) errs by at most `FIT_PX_MAX` = 24 card px (the continuous error: the line by quadrature over the viewport, the worst error looked for on 513 points, so a handful of samples cannot undercount it); the distance d is that of the NEAREST solid (alpha >= 0.5, neither wall nor near ground) pixel the card draws in the tile's interior columns, which is where the slide errs most (the line is fitted for the tile's `distance_m`, the median, but the bound is held for the nearest terrain: a tile whose terrain spans 600 to 2000 m is bound at 600 m); a tile whose card 0 draws only near ground (under the clip) has no such pixel, but it is slid at its `distance_m` (the clip, 500 m), so it binds at 500 m; and the resident gate (below) must hold at r_max_m too. `camera.r_max_forward_m` is the same search at phi = 0 alone (same `FIT_PX_MAX`, the same half-distance cap, the same resident gate): the camera pushed forward along its heading, which is where the offset stays when the view direction turns with it (the modes 'still' and 'both'), so it is at least `r_max_m`; the client takes `r_max_m` for the offset-only mode and for a backward offset, `r_max_forward_m` for a forward one in the other modes (`view.ts` `offsetRange`). `FIT_PX_MAX` is provisional, tuned by eye (ruling `ridge-offset-range-fit`). A bake whose `r_max_m` is below `R_MAX_FLOOR_M` = 25 m is refused, naming the card and tile. `distance_m` and the nearest-terrain table exclude the near ground (a tile with nothing outside it gets `distance_m` = 500 m), so card 0's distances are never nearer than the near clip (`write_bake` refuses one that is), and `r_max_m` and `r_max_forward_m` hold for the nearest solid terrain each card draws in each tile, at or beyond 500 m, a near-only tile counts at 500 m: the ground nearer than that rides card 0's slide and is not measured beyond that. 8. **Normals.** `normals` takes the along-ray slope and the across-ray slope at equal distance (neighbouring columns, same sample), both times the vertical exaggeration. Files per card `i` and tile `t`: `card--t-colour.webp` (lossy RGB albedo, lossless straight alpha) and `card--t-geometry.webp` (lossless: R, G = (n + 1) / 2 for the normal's along and across components, B = log-distance normalised between `encoding.log_d_min` and `log_d_max`; wall pixels write R = G = 255, a code outside the unit disc that no real normal reaches), each 204 columns wide. The manifest lists the cards nearest first (`near_m`, `far_m`: the median seam depths over the ring) and `tiles[t][i]` = `{ top, h, distance_m, colour, geometry }` or `null`; the runtime paints the cards last to first. The `bake_id` is the sha256 of the files, tile-major, then card, colour then geometry. diff --git a/scripts/ridge-bake/export.py b/scripts/ridge-bake/export.py index e9e32946..b8362216 100644 --- a/scripts/ridge-bake/export.py +++ b/scripts/ridge-bake/export.py @@ -51,7 +51,7 @@ SCHEMA = {'$schema': 'https://json-schema.org/draft/2020-12/schema', 'title': 'r view=_obj(look_az_deg=_num, ring_w={'const': RING_W}, tile_w={'const': TILE_W}, tiles={'const': TILES}, apron={'const': APRON}, plane_h=_int, px_per_deg_h=_num, px_per_deg_v=_num, exaggeration=_num, horizon_row=_num, sky_row=_num, near_row=_num), curvature=_obj(r_earth_m=_num, k_ref=_num), encoding=_obj(log_d_min=_num, log_d_max=_num, normal={'const': 'rt8'}), - camera=dict(_obj(r_max_m=_num, r_max_forward_m=_num), description="r_max_m (every camera angle on its circle) and r_max_forward_m (the camera on its heading) are the offsets up to which the linear slide holds (the fit error at most FIT_PX_MAX card px) for the NEAREST solid terrain (at or beyond the near clip, ridge.NEAR_CLIP_M, 500 m) that each card draws in each tile, not for the tile's median distance_m; a tile whose card 0 draws only near ground (under the clip) has no such terrain and binds nothing. The ground under the clip is drawn by card 0 from the near march and is not measured, so they are no measure of it."), + camera=dict(_obj(r_max_m=_num, r_max_forward_m=_num), description="r_max_m (every camera angle on its circle) and r_max_forward_m (the camera on its heading) are the offsets up to which the linear slide holds (the fit error at most FIT_PX_MAX card px) for the NEAREST solid terrain (at or beyond the near clip, ridge.NEAR_CLIP_M, 500 m) that each card draws in each tile, not for the tile's median distance_m; a tile whose card 0 draws only near ground (under the clip) is slid at the clip distance (its distance_m) and binds at 500 m. The ground under the clip is drawn by card 0 from the near march and is otherwise not measured."), cards={'type': 'array', 'minItems': 1, 'maxItems': MAX_CARDS, 'items': _obj(near_m=_numnull, far_m=_numnull), 'description': "nearest first; the runtime paints the list last to first. near_m and far_m are the median seam depths over the ring, null at the ends."}, tiles={'type': 'array', 'minItems': TILES, 'maxItems': TILES, 'items': {'type': 'array', 'minItems': 1, 'maxItems': MAX_CARDS, 'items': _objnull(top=_int, h=_int, distance_m=_num, colour=_file, geometry=_file)}, @@ -251,8 +251,8 @@ def bake_place(pid): return dict(place=place, view=view, meta=meta, v=v, **ring) def pack(bake): - """The tiles of a bake as bytes plus their manifest facts. Per card tile: distance_m = exp(median ln d) over the solid (alpha >= 0.5) pixels that are neither wall nor near ground (under the clip) of the interior TILE_W columns (a tile with none falls back to its non-wall, then any, lit pixels, near ground never; a tile with nothing outside the near ground gets ridge.NEAR_CLIP_M: the near ground binds nothing and is not measured); - a card with no rows in a tile is null there. Per card: the median seam depths over the ring. camera.r_max_m: solve_r_max over the NEAREST solid non-wall pixel of each card tile (not its median distance_m; a tile whose card 0 draws only near ground, under the clip, has none and binds nothing) and every camera angle on its circle (the offset-only rotation mode), camera.r_max_forward_m: the same at phi = 0 alone (the modes where the offset turns with the view). Refuses a card empty in every tile (naming the splits) and a card with + """The tiles of a bake as bytes plus their manifest facts. Per card tile: distance_m = exp(median ln d) over the solid (alpha >= 0.5) pixels that are neither wall nor near ground (under the clip) of the interior TILE_W columns (a tile with none falls back to its non-wall, then any, lit pixels, near ground never; a tile with nothing outside the near ground gets ridge.NEAR_CLIP_M: the near ground itself is not measured, but such a tile is slid at that distance and binds r_max there); + a card with no rows in a tile is null there. Per card: the median seam depths over the ring. camera.r_max_m: solve_r_max over the NEAREST solid non-wall pixel of each card tile (not its median distance_m; a tile whose card 0 draws only near ground, under the clip, is slid at the clip distance and binds there) and every camera angle on its circle (the offset-only rotation mode), camera.r_max_forward_m: the same at phi = 0 alone (the modes where the offset turns with the view). Refuses a card empty in every tile (naming the splits) and a card with no solid terrain apart from its wall in any tile. Returns dict(cards, tiles, camera, report) (report is printed, not written).""" import ridge sm = bake['seams']; sp = bake['splits_km']; k = len(sp) + 1; ppd = bake['view']['px_per_deg_h']; inner = slice(APRON, APRON + TILE_W); enc = bake['meta']['encoding'] @@ -265,7 +265,7 @@ def pack(bake): if c['alpha'].shape[0] == 0: row.append(None); drow.append(None); nrow.append(None); continue al, wl, ld, nr = c['alpha'][:, inner], c['wall'][:, inner], c['logd'][:, inner], c['near'][:, inner]; solid = (al >= 0.5) & ~wl & ~nr; any_solid[i] |= bool(solid.any()) pool = next(((m, l) for m, l in ((solid, ld), ((al > 0) & ~wl & ~nr, ld), ((al > 0) & ~nr, ld), ((c['alpha'] > 0) & ~c['near'], c['logd'])) if m.any()), None) - dm = float(np.exp(np.median(pool[1][pool[0]]))) if pool else ridge.NEAR_CLIP_M; nrow.append(float(np.exp(ld[solid].min())) if solid.any() else None) # the nearest solid terrain the card draws in this tile: None where it draws only near ground, which binds nothing + dm = float(np.exp(np.median(pool[1][pool[0]]))) if pool else ridge.NEAR_CLIP_M; nrow.append(float(np.exp(ld[solid].min())) if solid.any() else (ridge.NEAR_CLIP_M if pool is None else None)) # the nearest solid terrain the card draws in this tile; a tile with nothing but near ground is slid at the clip (its distance_m), so it binds there; None where it draws only wall or faint pixels row.append(dict(top=c['top'], colour=encode_colour(c['albedo'], c['alpha']), geometry=encode_geometry(c['n_r'], c['n_t'], c['logd'], enc, c['wall']), distance_m=dm)); drow.append(dm); brow.append(c['alpha'].shape[0]) tiles.append(row); dist.append(drow); near.append(nrow); bands.append(brow) for i in range(k): diff --git a/scripts/ridge-bake/ridge-bake.schema.json b/scripts/ridge-bake/ridge-bake.schema.json index 62a4d3ea..3f7f9b41 100644 --- a/scripts/ridge-bake/ridge-bake.schema.json +++ b/scripts/ridge-bake/ridge-bake.schema.json @@ -173,7 +173,7 @@ "type": "number" } }, - "description": "r_max_m (every camera angle on its circle) and r_max_forward_m (the camera on its heading) are the offsets up to which the linear slide holds (the fit error at most FIT_PX_MAX card px) for the NEAREST solid terrain (at or beyond the near clip, ridge.NEAR_CLIP_M, 500 m) that each card draws in each tile, not for the tile's median distance_m; a tile whose card 0 draws only near ground (under the clip) has no such terrain and binds nothing. The ground under the clip is drawn by card 0 from the near march and is not measured, so they are no measure of it." + "description": "r_max_m (every camera angle on its circle) and r_max_forward_m (the camera on its heading) are the offsets up to which the linear slide holds (the fit error at most FIT_PX_MAX card px) for the NEAREST solid terrain (at or beyond the near clip, ridge.NEAR_CLIP_M, 500 m) that each card draws in each tile, not for the tile's median distance_m; a tile whose card 0 draws only near ground (under the clip) is slid at the clip distance (its distance_m) and binds at 500 m. The ground under the clip is drawn by card 0 from the near march and is otherwise not measured." }, "cards": { "type": "array", diff --git a/scripts/ridge-bake/tests/mutate.py b/scripts/ridge-bake/tests/mutate.py index f92e3e9c..b706e23a 100644 --- a/scripts/ridge-bake/tests/mutate.py +++ b/scripts/ridge-bake/tests/mutate.py @@ -1,5 +1,5 @@ """Mutation check: re-introduce a cause into a COPY of the baker, run the fixtures against it, and require that at least one fails. - venv/bin/python tests/mutate.py [word ...] (prints one line per mutant whose name holds every word; exit 1 if a mutant survives or only crashes the run)""" + venv/bin/python tests/mutate.py [word ...] (runs the unmutated copy first and exits 2 if a fixture fails; prints one line per mutant whose name holds every word; exit 1 if a mutant survives or only crashes the run: a kill is an AssertionError in a fixture)""" import os, shutil, subprocess, sys, tempfile HERE = os.path.dirname(os.path.abspath(__file__)); SRC = os.path.join(HERE, '..') MUTANTS = { # name -> (text in ridge.py or export.py, replacement) @@ -41,7 +41,7 @@ MUTANTS = { # name -> (text in ridge.py or export.py, replacement) 'pack: the apron fallback pool reads near pixels': ("((c['alpha'] > 0) & ~c['near'], c['logd'])", "(c['alpha'] > 0, c['logd'])"), 'pack: a tile with nothing outside the near ground is not at the clip': ("if pool else ridge.NEAR_CLIP_M", "if pool else 0.0"), 'r_max: the tile median binds, not the nearest terrain': ("r_max = solve_r_max(near, bands, ppd); r_fwd = solve_r_max(near, bands, ppd, phis=1)", "r_max = solve_r_max(dist, bands, ppd); r_fwd = solve_r_max(dist, bands, ppd, phis=1)"), - 'r_max: a tile of near ground only binds at its distance': ("if solid.any() else None)", "if solid.any() else dm)"), + 'r_max: a tile of near ground only binds nothing': ("(ridge.NEAR_CLIP_M if pool is None else None))", "None)"), 'r_max: the nearest pixel is the farthest solid one': ("nrow.append(float(np.exp(ld[solid].min()))", "nrow.append(float(np.exp(ld[solid].max()))"), 'near clip: the writer compares the float32 distance strictly': ("if rmin < ridge.NEAR_CLIP_M * (1 - 1e-5): raise", "if rmin < ridge.NEAR_CLIP_M: raise"), 'near clip: the march starts nearer than the clip': ("d = [NEAR_CLIP_M]", "d = [100.0]"), @@ -90,18 +90,33 @@ MUTANTS = { # name -> (text in ridge.py or export.py, replacement) 'mosaic cache key ignores the tile list': ("sorted(tiles_for(p)), 3600", "3600"), } EQUIVALENT = {'fit: the error is looked for between four points': "the worst error of the best line is at the viewport's two ends for every distance and offset the bound is searched over (checked against a 20001-sample brute force in test_fit_px_is_the_continuous_error); the grid only guards a shape where it is not"} # mutant name -> one line on why it is behaviourally equivalent (reported, not run) +def execute(edit): + """Run the fixtures on a COPY of the baker, with edit = (text, replacement) applied or None for the unmutated copy: (returncode or None if the text is gone, [(fixture, exception class)] of every FAIL line, last stderr line).""" + d = tempfile.mkdtemp(); shutil.copytree(SRC, os.path.join(d, 'src'), ignore=shutil.ignore_patterns('tests', '__pycache__')) + try: + if edit: + a, b = edit; p = next((q for q in (os.path.join(d, 'src', f) for f in ('ridge.py', 'export.py')) if a in open(q).read()), None) + if p is None: return None, [], 'the mutant text is in neither ridge.py nor export.py' + s = open(p).read(); open(p, 'w').write(s.replace(a, b)) + r = subprocess.run([sys.executable, os.path.join(HERE, 'test_ridge.py')], env=dict(os.environ, RIDGE_SRC=os.path.join(d, 'src')), capture_output=True, text=True) + finally: shutil.rmtree(d) + fails = [(l.split('|')[0][4:].strip(), (l.split('|', 1)[1].strip().split('(')[0] if '|' in l else '?')) for l in r.stdout.splitlines() if l.startswith('FAIL')] + return r.returncode, fails, (r.stderr.strip().splitlines() or ['no output'])[-1][:200] def run(item): - name, (a, b) = item; d = tempfile.mkdtemp(); shutil.copytree(SRC, os.path.join(d, 'src'), ignore=shutil.ignore_patterns('tests', '__pycache__')); p = next((q for q in (os.path.join(d, 'src', f) for f in ('ridge.py', 'export.py')) if a in open(q).read()), None) - if p is None: shutil.rmtree(d); line = 'CRASHED ' + name + ' -> the mutant text is in neither ridge.py nor export.py'; print(line, file=sys.stderr, flush=True); return line, True - s = open(p).read() - open(p, 'w').write(s.replace(a, b)) - r = subprocess.run([sys.executable, os.path.join(HERE, 'test_ridge.py')], env=dict(os.environ, RIDGE_SRC=os.path.join(d, 'src')), capture_output=True, text=True); shutil.rmtree(d) - fails = [l.split('|')[0].strip() for l in r.stdout.splitlines() if l.startswith('FAIL')] - killed = bool(r.returncode and fails) # a kill is a NAMED fixture failure: a run that crashes without one (unset RIDGE_TILES / RIDGE_WORK, a syntax error in the mutant) proves nothing - line = ('KILLED ' if killed else 'CRASHED ' if r.returncode else 'SURVIVED ') + name + ' -> ' + (', '.join(fails) or (r.stderr.strip().splitlines() or ['no fixture failed'])[-1][:200]); print(line, file=sys.stderr, flush=True) # progress: a killed run keeps what finished - return line, not killed + """KILLED: at least one fixture failed on an ASSERTION (AssertionError). CRASHED: the run failed but no fixture failed an assertion (every FAIL is another exception, NameError and the like, or none printed, or the mutant text is gone), which proves nothing and fails the run. SURVIVED: every fixture passed.""" + name, (a, b) = item; rc, fails, err = execute((a, b)); asserts = [n for n, c in fails if c == 'AssertionError'] + state = 'CRASHED ' if rc is None or (rc and not asserts) else 'KILLED ' if rc else 'SURVIVED ' + why = ', '.join(f'{n}[{c}]' for n, c in fails) if fails else err + line = state + name + ' -> ' + why; print(line, file=sys.stderr, flush=True) # progress: a killed run keeps what finished + return line, state != 'KILLED ' +def baseline(): + """The unmutated copy must pass every fixture before any mutant means anything: a broken environment would kill them all.""" + rc, fails, err = execute(None) + if rc or fails: print('BASELINE FAILED: the unmutated baker does not pass its fixtures: ' + (', '.join(f'{n}[{c}]' for n, c in fails) or err), file=sys.stderr, flush=True); sys.exit(2) + print('BASELINE ok: the unmutated copy passes every fixture', file=sys.stderr, flush=True) if __name__ == '__main__': from concurrent.futures import ThreadPoolExecutor + baseline() with ThreadPoolExecutor(int(os.environ.get('MUTATE_JOBS', '6'))) as ex: res = list(ex.map(run, [(n, v) for n, v in MUTANTS.items() if n not in EQUIVALENT and all(w in n for w in sys.argv[1:])])) for line, _ in res: print(line, flush=True) for n, why in EQUIVALENT.items(): print('EQUIVALENT ' + n + ' -> ' + why) diff --git a/scripts/ridge-bake/tests/test_ridge.py b/scripts/ridge-bake/tests/test_ridge.py index c926b135..003b3796 100644 --- a/scripts/ridge-bake/tests/test_ridge.py +++ b/scripts/ridge-bake/tests/test_ridge.py @@ -517,9 +517,9 @@ def test_the_sheet_lights_a_wall_with_the_face_up(): def _nearest_solid(c): """The nearest solid (alpha >= 0.5) pixel that is neither wall nor near ground of a card tile's interior columns, metres; None where there is none (computed here from the arrays, not by pack).""" ld, al, wl, nr = (c[k][:, 2:-2] for k in ('logd', 'alpha', 'wall', 'near')); m = (al >= 0.5) & ~wl & ~nr; return float(np.exp(np.float64(ld[m].min()))) if m.any() else None -def test_r_max_holds_for_the_nearest_terrain_of_every_tile_and_near_only_tiles_do_not_bind(): +def test_r_max_holds_for_the_nearest_terrain_of_every_tile_and_near_only_tiles_bind_at_the_clip(): """The offset range is where the linear map holds for the NEAREST solid terrain each card draws in each tile (ruling ridge-offset-range-fit), not its median: a tile whose card 0 spans 600 to 2000 m has its median near 1200 m, and at the r_max the median would give the 600 m pixels err past FIT_PX_MAX. - So the fit at every tile's nearest solid pixel is within the bound at r_max_m (over the circle) and at r_max_forward_m (phi 0), and the bound is reached: a little more offset breaks it at the binding tile. A tile whose card 0 draws only near ground (under the clip) has no terrain and binds nothing.""" + So the fit at every tile's nearest solid pixel is within the bound at r_max_m (over the circle) and at r_max_forward_m (phi 0), and the bound is reached: a little more offset breaks it at the binding tile. A tile whose card 0 draws only near ground (under the clip) is slid at the clip distance (its distance_m) and binds there.""" b = _toy(); cs = [[dict(c) for c in tile] for tile in b['cards']]; c = dict(cs[7][0]); n = c['alpha'].shape[1] ld = np.log(np.linspace(600.0, 2000.0, n))[None, :].repeat(c['alpha'].shape[0], 0).astype(np.float32); cs[7][0] = dict(c, logd=ld) bad = dict(cs[5][0]); cs[5][0] = dict(bad, near=np.ones_like(bad['near']), logd=np.full_like(bad['logd'], math.log(300.0))) # tile 5: card 0 is all near ground @@ -527,14 +527,13 @@ def test_r_max_holds_for_the_nearest_terrain_of_every_tile_and_near_only_tiles_d for t, tile in enumerate(cs): for i, card in enumerate(tile): d = _nearest_solid(card) - if d is None: assert (t, i) == (5, 0), ('a tile has no solid terrain but was not made all near ground', t, i); continue + if d is None: assert (t, i) == (5, 0), ('a tile has no solid terrain but was not made all near ground', t, i); d = ridge.NEAR_CLIP_M seen += 1; assert export.fit_px(d, r, ppd) <= export.FIT_PX_MAX + 1e-6 and export.fit_px(d, rf, ppd, 1) <= export.FIT_PX_MAX + 1e-6, ('the nearest terrain of a tile is outside the fit bound', t, i, d, r, rf) worst, worst_f = max(worst, export.fit_px(d, r + 0.5, ppd)), max(worst_f, export.fit_px(d, rf + 0.5, ppd, 1)) - assert seen == 32 * 3 - 1 and worst > export.FIT_PX_MAX and worst_f > export.FIT_PX_MAX, ('the range stops short of the bound of the nearest terrain', worst, worst_f) + assert seen == 32 * 3 and worst > export.FIT_PX_MAX and worst_f > export.FIT_PX_MAX, ('the range stops short of the bound of the nearest terrain', worst, worst_f) assert abs(pk['tiles'][7][0]['distance_m'] - float(np.exp(np.median(np.log(np.linspace(600.0, 2000.0, n)))))) < 1.0, 'the manifest distance is still the median' assert r < export.solve_r_max([[1200.0 if (t, i) == (7, 0) else None for i in range(3)] for t in range(32)], [[100] * 3 for _ in range(32)], ppd) - 5, 'the range is the median model' near_free = export.pack(_toy()); assert pk['camera']['r_max_m'] < near_free['camera']['r_max_m'], 'the 600 m pixels do not bind' - only = export.pack(dict(b, cards=[[dict(cs[t][i]) if (t, i) != (7, 0) else dict(b['cards'][7][0]) for i in range(3)] for t in range(32)])); assert only['camera'] == near_free['camera'], ('a near-only tile binds r_max', only['camera'], near_free['camera']) def test_the_near_clip_compare_does_not_depend_on_float32_rounding(): """A card 0 exactly at the near clip is accepted whatever the clip's value: exp of a float32 ln 700 is 699.99994, which a strict compare against a 700 m clip refuses; one 1.5 per mille under the clip is still refused.""" saved = ridge.NEAR_CLIP_M; d = tempfile.mkdtemp() @@ -604,14 +603,17 @@ def test_near_ground_has_the_material_and_relief_of_its_own_heights(): got[blk[x]] = c['albedo'][sel, x].mean(0) assert np.abs(got[0] - got[1]).max() > 0.05 and np.abs(got[1] - got[2]).max() > 0.05 and np.abs(got[0] - got[2]).max() > 0.05, ('the blocks do not differ where the ground does', got) def test_near_pixels_are_not_measured(): - """pack of a bake with near rows (card 0, one tile: its lower third is near ground at 150 m) equals in every distance_m and in the camera pack of the same bake with those pixels cut out; a tile whose card 0 is near only gets distance_m == NEAR_CLIP_M and binds nothing, and write_bake accepts it.""" - b = _toy(dists=(520.0, 15000.0, 50000.0)); base = export.pack(b); cs = [[dict(c) for c in tile] for tile in b['cards']]; c = cs[3][0]; n = c['alpha'].shape[0]; near = np.zeros_like(c['near']); near[n * 2 // 3:] = True + """pack of a bake with near rows (card 0, one tile: its lower third is near ground at 150 m) equals in every distance_m and in the camera pack of the same bake with those pixels cut out; a tile whose card 0 is near only gets distance_m == NEAR_CLIP_M and BINDS r_max at that distance (it is slid at 500 m) even where every other tile stands 3000 m away, and write_bake accepts it.""" + b = _toy(); base = export.pack(b); cs = [[dict(c) for c in tile] for tile in b['cards']]; c = cs[3][0]; n = c['alpha'].shape[0]; near = np.zeros_like(c['near']); near[n * 2 // 3:] = True cs[3][0] = dict(c, near=near, logd=np.where(near, math.log(150.0), c['logd']).astype(np.float32)); a = export.pack(dict(b, cards=cs)) cs[3][0] = dict(c, alpha=np.where(near, 0.0, c['alpha']).astype(np.float32)); cut = export.pack(dict(b, cards=cs)); dists = lambda pk: [[e and e['distance_m'] for e in row] for row in pk['tiles']] assert dists(a) == dists(cut) == dists(base) and a['camera'] == cut['camera'] == base['camera'], ('near pixels were measured', a['camera'], cut['camera']) cs[3][0] = c; only = dict(cs[9][0]); cs[9][0] = dict(only, near=np.ones_like(only['near']), logd=np.full_like(only['logd'], math.log(300.0))); ob = dict(b, cards=cs); pk = export.pack(ob); d = tempfile.mkdtemp() try: - assert pk['tiles'][9][0]['distance_m'] == ridge.NEAR_CLIP_M and pk['camera'] == base['camera'] and pk['tiles'][8][0]['distance_m'] == base['tiles'][8][0]['distance_m'], ('a near-only tile', pk['tiles'][9][0]['distance_m'], pk['camera']) + assert pk['tiles'][9][0]['distance_m'] == ridge.NEAR_CLIP_M and pk['tiles'][8][0]['distance_m'] == base['tiles'][8][0]['distance_m'], ('a near-only tile', pk['tiles'][9][0]['distance_m']) + r, rf = pk['camera']['r_max_m'], pk['camera']['r_max_forward_m']; ppd = ridge.HPX_DEG; assert r < base['camera']['r_max_m'] - 5 and rf < base['camera']['r_max_forward_m'] - 5, ('a near-only tile does not bind', pk['camera'], base['camera']) + assert export.fit_px(ridge.NEAR_CLIP_M, r, ppd) <= export.FIT_PX_MAX + 1e-6 and export.fit_px(ridge.NEAR_CLIP_M, rf, ppd, 1) <= export.FIT_PX_MAX + 1e-6 and export.fit_px(ridge.NEAR_CLIP_M, r + 0.5, ppd) > export.FIT_PX_MAX, ('the near-only tile is not bound at the clip distance it is slid at', r, rf) + cs[9][0] = dict(only, logd=np.full_like(only['logd'], math.log(ridge.NEAR_CLIP_M))); assert export.pack(dict(b, cards=cs))['camera'] == pk['camera'], 'a near-only tile does not bind exactly like terrain at the clip' assert _write(d + '/ok', ob, pk).exists(), 'a bake with a near-only tile was refused' finally: shutil.rmtree(d) def test_cards_refuses_a_march_without_the_near_ground():