diff --git a/tools/e2e/41-physics.mjs b/tools/e2e/41-physics.mjs index b9ec7253..6330342f 100644 --- a/tools/e2e/41-physics.mjs +++ b/tools/e2e/41-physics.mjs @@ -182,20 +182,15 @@ export async function physics(t) { samples.length > 100 && samples[0].crate < REST - 50 && last.every((y) => Math.abs(y - REST) < 1), JSON.stringify({ frames: samples.length, first: samples[0], last: last.slice(-3), rest: REST }), ); - // The heights the ball climbs back to: the highest point between two landings. + // The heights the ball climbs back to: every turn from rising to falling after the first landing. + // Turning points, not a threshold at the ground: the ball lands at ~9 px per frame, and whether a + // drawn frame comes within a pixel of the landing depends on where it falls between two steps. const peaks = []; - let landings = 0; - let down = false; - let top = Infinity; - for (const { ball } of samples) { - if (ball > REST - 1) { - if (!down && landings++ > 0 && Number.isFinite(top)) peaks.push(REST - top); - down = true; - top = Infinity; - } else { - down = false; - if (landings > 0) top = Math.min(top, ball); - } + let landed = false; + for (let i = 1; i < samples.length - 1; i++) { + const [before, y, after] = [samples[i - 1].ball, samples[i].ball, samples[i + 1].ball]; + if (y >= before && y > after) landed = true; + else if (landed && y <= before && y < after && REST - y > 2) peaks.push(REST - y); } const drop = REST - Y; check(