3D engine that AI agents drive
measureLanding: throw a clear error when the body never reaches the floor (part of #696)
Nguyen Xuan An793ddcbc6b63
diff --git a/scripts/soft-body-film.mjs b/scripts/soft-body-film.mjsindex db814fcd..4e7b0446 100644--- a/scripts/soft-body-film.mjs+++ b/scripts/soft-body-film.mjs@@ -106,6 +106,9 @@ export function axisRange(vertices, axis) {export function measureLanding(frames, restHeight) {const lowest = frame => axisRange(frame, 1).low;const contact = frames.findIndex(frame => lowest(frame) <= FLOOR_THICKNESS + 1e-3);+ if (contact === -1) {+ throw new Error(`measureLanding: the body never reached the floor within ${frames.length} frames; pass a longer film or lower the drop.`);+ }let deepest = contact;let deepestHeight = Infinity;for (let frame = contact; frame < frames.length; frame++) {diff --git a/tests/soft-body-film.test.js b/tests/soft-body-film.test.jsindex 52b4fbcb..b65e33c2 100644--- a/tests/soft-body-film.test.js+++ b/tests/soft-body-film.test.js@@ -51,6 +51,11 @@ test('a jelly cube landing is byte-identical across two bakes and dents on contacontext.diagnostic(`jelly cube: bake ${milliseconds(bake)} ms for ${JELLY_FRAMES} steps (${milliseconds(bake / JELLY_FRAMES)} ms a step, ${FILM_FRAMES_PER_SECOND} steps a second)`);});+test('measureLanding names the problem when the body never reaches the floor', () => {+ const airborne = [new Float32Array([0, 5, 0, 1, 6, 1])];+ assert.throws(() => measureLanding(airborne, 1), /never reached the floor within 1 frames/);+});+test('a flag lowered into folds is byte-identical across two bakes and keeps its layers apart', context => {const first = recordFilm(foldingFlagRecipe(), 'flag', FLAG_FRAMES);const second = recordFilm(foldingFlagRecipe(), 'flag', FLAG_FRAMES);