tests/live/reference_fit.py: a mirrored free cage fitted through fit_shell by its vertex chains, rebuilt by brokkr_kitbash.shell and read against Blender's build

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-03 05:24:51 +01:00
commit 54781f45da
2 changed files with 96 additions and 15 deletions

View file

@ -12,6 +12,9 @@ Blender's own projection draws them on the shell as designed. Then:
crease_run the fitted shell at one level: the rim run and the crease stand where core.crease_run says
refusals a trace doubled back over itself, an unknown camera, a scaled shell and a mesh that is no shell,
each a failed receipt naming its cause, the shell unchanged
free cage a mirrored free cage with one hard crease, blocked off its design and traced on both halves: fit_shell
takes the run as {verts}, brokkr_kitbash.shell rebuilds it, and Blender builds the crease on both
halves where core.crease_run says
The Jacobian by differences (mutant F6: core.lm on the same residual) costs time only: the mirrored column of
tests/test_reference.py, views one at a time, medians of 3 interleaved runs on Starfire, read
@ -107,6 +110,15 @@ def blocking(sheet):
return out
def free_cage(points=6):
"""A mirrored free cage three columns wide (x 0 on the mirror plane, 0.5, 1) whose middle column is a hard crease,
and that column's vertices in order."""
verts = [[x, -1 + 2 * i / (points - 1), 0.5 - x * x + 0.1 * math.sin(3 * i / (points - 1)) * (c == 1)] for c, x in enumerate((0.0, 0.5, 1.0)) for i in range(points)]
faces = [[c * points + i, c * points + i + 1, c * points + i + 1 + points, c * points + i + points] for c in range(2) for i in range(points - 1)]
chain = list(range(points, 2 * points))
return {"verts": verts, "faces": faces, "creases": [[a, b, 1.0] for a, b in zip(chain, chain[1:])], "mirror": True, "rim": 1.0}, chain
def run_of(sheet, column, side):
"""A column's built run in the shell's frame, as core.crease_run builds it twice over."""
return core.crease_run(core.crease_run(np.array(sheet["rings"])[:, column] * [side, 1, 1]))
@ -161,8 +173,8 @@ try:
traces = [{"camera": "View", "run": {"column": column, "from": 0, "to": RINGS - 1}, "side": side, "line": lines[tag]} for tag, (column, side) in runs.items()]
receipt, fit = send("brokkr_reference.fit_shell", object_name="Plate", traces=json.dumps(traces, separators=(",", ":")))
ok = receipt["status"] == "accepted" and fit is not None
check("fit_shell returns a sheet with every trace explained within 3 px, and a row for each of the 12 moved points",
ok and max(row["unexplained_px"] for row in fit["traces"]) <= 3.0 and len(fit["points"]) == 2 * RINGS and len(receipt["hostResult"]) < 16000,
check(f"fit_shell returns a sheet with every trace explained within {core.TOL:g} px, and a row for each of the 12 moved points",
ok and max(row["unexplained_px"] for row in fit["traces"]) <= core.TOL and len(fit["points"]) == 2 * RINGS and len(receipt["hostResult"]) < 16000,
fit and {"traces": fit["traces"], "seconds": fit["seconds"], "chars": len(receipt["hostResult"])})
check("fit_shell wrote nothing: the shell's request and its cage are as they were", state(shell) == before)
if ok:
@ -209,6 +221,47 @@ try:
bpy.context.view_layer.update()
check("a scaled shell is refused", receipt["status"] == "failed" and "is scaled" in receipt["message"], receipt["message"])
check("no refusal changed the shell", state(shell) == before)
# --- a free cage, by its vertex chains ---------------------------------------------------------------------------------
design, chain = free_cage()
def crease(sheet, side, levels=core.LEVELS):
run = np.array(sheet["verts"])[chain] * [side, 1, 1]
for _ in range(levels):
run = core.crease_run(run)
return run
send("brokkr_kitbash.shell", object_name="Free", sheet=json.dumps(design), thickness=0.03, levels=2)
free = bpy.data.objects["Free"]
free.matrix_world = shell.matrix_world.copy()
bpy.context.view_layer.update()
free_lines = {side: pixels(camera, free, core.resampled(crease(design, side), 120)) for side in (1, -1)}
rough, bump = json.loads(json.dumps(design)), np.random.default_rng(1).normal(0, 0.06, (len(chain), 3))
for v, d in zip(chain, bump):
rough["verts"][v] = [round(float(x + y), 6) for x, y in zip(design["verts"][v], d)]
send("brokkr_kitbash.shell", object_name="Free", sheet=json.dumps(rough), thickness=0.03, levels=2)
bpy.context.view_layer.update()
before = state(free)
receipt, fit = send("brokkr_reference.fit_shell", object_name="Free",
traces=json.dumps([{"camera": "View", "run": {"verts": chain}, "side": side, "line": free_lines[side]} for side in (1, -1)], separators=(",", ":")))
ok = receipt["status"] == "accepted" and fit is not None
if ok:
gap, off = (float(core._off(core.resampled(crease(sheet, 1), 200), crease(design, 1)).max()) for sheet in (fit["sheet"], rough))
check("a mirrored free cage's crease, traced on both halves and named {verts}, is fitted within 1 mm of the designed run from a blocking over 0.05 m off: "
"a row for each of its six vertices and no other, every trace explained, nothing written",
gap < 0.001 and off > 0.05 and [row["vertex"] for row in fit["points"]] == chain and max(row["unexplained_px"] for row in fit["traces"]) <= core.TOL
and all(0 <= u <= WIDTH and 0 <= v <= HEIGHT for line in free_lines.values() for u, v in line) and state(free) == before,
{"gap": gap, "off": off, "traces": fit["traces"], "prior_share": max(row["prior_share"] for row in fit["points"]), "seconds": fit["seconds"]})
applied, _ = send("brokkr_kitbash.shell", object_name="Free", sheet=json.dumps(fit["sheet"]), thickness=0.03, levels=1)
wall = free.modifiers["Kit Solidify"]
wall.show_viewport = False
built = np.array([v.co for v in free.evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh().vertices])
wall.show_viewport = True
worst = {side: max(float(np.linalg.norm(built - p, axis=1).min()) for p in crease(fit["sheet"], side, 1)) for side in (1, -1)}
check("brokkr_kitbash.shell takes the fitted free cage, and at one level Blender builds its crease on both halves where core.crease_run says, within 1e-4 m",
applied["status"] == "accepted" and max(worst.values()) < 1e-4, worst)
else:
check("fit_shell fits a mirrored free cage by its vertex chains", False, receipt["message"])
except Exception: # noqa: BLE001 whatever it was, it is a failed check with a name, printed and written, not a missing result file
check(f"no uncaught error after: {R['checks'][-1]['name'] if R['checks'] else 'the start'}", False, traceback.format_exc().splitlines()[-6:])

View file

@ -49,29 +49,29 @@
}
},
{
"name": "fit_shell returns a sheet with every trace explained within 3 px, and a row for each of the 12 moved points",
"name": "fit_shell returns a sheet with every trace explained within 5 px, and a row for each of the 12 moved points",
"ok": true,
"detail": {
"traces": [
{
"miss_px": 0.004,
"unexplained_px": 0.021
"unexplained_px": 0.01,
"worst_px": 0.021
},
{
"miss_px": 0.008,
"unexplained_px": 0.082
"unexplained_px": 0.058,
"worst_px": 0.082
},
{
"miss_px": 0.005,
"unexplained_px": 0.071
"unexplained_px": 0.053,
"worst_px": 0.071
},
{
"miss_px": 0.003,
"unexplained_px": 0.055
"unexplained_px": 0.037,
"worst_px": 0.055
}
],
"seconds": 0.12,
"chars": 2059
"seconds": 0.138,
"chars": 2066
}
},
{
@ -90,7 +90,7 @@
{
"name": "every moved point reports metres per pixel and a prior share from 0 to 1",
"ok": true,
"detail": 0.617
"detail": 0.069
},
{
"name": "applied with brokkr_kitbash.shell, flow_score reads the four traced lines on a built edge over 0.747 in the mean: the geometric mean of the fitted build's reading (0.991) and the blocked build's (0.563), separation 1.33 each side; no fitted line reads under 0.9",
@ -123,7 +123,7 @@
{
"name": "a trace doubled back over itself is refused, naming the trace and the span no built run draws",
"ok": true,
"detail": "Error: traces[1] is not explained: 281 px of the trace, between 110 and 466 px along it, lie more than 3 px from the run as built, up to 15.7 px. Nothing is returned as a fit. The trace draws something this run does not build (an overdrawn or doubled stroke, another edge, a bend the cage has too few points for): redraw it, or give the run more points. Nothing changed."
"detail": "Error: traces[1] is not explained: 239 px of the trace, between 124 and 461 px along it, lie more than 5 px from the run as built (12.1 px at the 90th of a hundred, 5% of the trace left out at each end; up to 15.7 px). Nothing is returned as a fit. The trace draws something this run does not build (an overdrawn or doubled stroke, another edge, a bend the cage has too few points for): redraw it, or give the run more points. A very unsteady hand reads the same as a slight overdraw: if the trace is one clean stroke, ask again with tol over this reading. Nothing changed."
},
{
"name": "an unknown camera is refused naming the trace",
@ -144,6 +144,34 @@
"name": "no refusal changed the shell",
"ok": true,
"detail": null
},
{
"name": "a mirrored free cage's crease, traced on both halves and named {verts}, is fitted within 1 mm of the designed run from a blocking over 0.05 m off: a row for each of its six vertices and no other, every trace explained, nothing written",
"ok": true,
"detail": {
"gap": 0.00042547668113367745,
"off": 0.055743395392436126,
"traces": [
{
"unexplained_px": 0.013,
"worst_px": 0.022
},
{
"unexplained_px": 0.02,
"worst_px": 0.032
}
],
"prior_share": 0.06,
"seconds": 0.022
}
},
{
"name": "brokkr_kitbash.shell takes the fitted free cage, and at one level Blender builds its crease on both halves where core.crease_run says, within 1e-4 m",
"ok": true,
"detail": {
"1": 1.305964704160048e-07,
"-1": 1.305964704160048e-07
}
}
],
"hostErrors": [],