Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(video): `beat` under `local_cycle.BEAT_STILL` reads as holding still with a `share` of 0.0 on every machine, and walk step tests reaching the binary carry a time limit and a pin of their calls.

Soohong Kimab9907f93abd
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 88637fd..7897846 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -1389,11 +1389,12 @@ own". Where `less_bands` is under the largest of `BOB_OWN` (0.3) times `beat`, t
less as much of the zoom as its band {a}% to {b}% of its height below its top reads, its top line's
rise and fall twice an interval is {x} rows of {beat} ({percent}), {ratio} of the {less_lowest} left
against the lowest row (at least 30%, {floor} rows and 0.6): the picture may zoom with the body, and the
-body's own is not told from it". Where `beat` is zero, as for a body whose top line holds still on the
+body's own is not told from it". Where `beat` is under `BEAT_STILL` (`1e-9` rows), as for a body whose top line holds still on the
screen while only its lowest row rises and falls (a body that does not rise and fall whose foot drawn
nearer is drawn lower each step), `{percent}` now reads "its top line holding still"
-(`local_cycle._share`). What the witness says is unchanged; before, `video-loop` stopped there on a
-division by zero.
+(`local_cycle._share`). The test is against `BEAT_STILL` rather than zero because a top line that does
+not rise and fall fits to round-off, which is 0 under one machine's numpy and a tiny nonzero value under
+another's. What the witness says is unchanged; before, `video-loop` stopped there on a division by zero.
Since every band's `less` is `less_lowest` times (1 - `reads`), this
hold catches every band seen that moves on the beat (its `reads` over 0.4): the body's own is witnessed
only where every band seen holds still on the beat and what is left is still at least 30% of `beat` and
@@ -1458,7 +1459,8 @@ written). Recorded in `cycle.step_count.cycles`:
(`half`, `quarter`, `edge` (frames whose lowest row is their last) and `body` are absent under the floors;
`body` is also absent where under 8 frames are left; `body` is `{beat, lowest, sole, less_lowest, less_bands,
still_bands, own, bands: {rows, width, zoom, beat, reads, less}, share, scale, least, scale_least,
-band_floor}`: `share` = `own` / `beat`, `scale` = `less_bands` / `less_lowest` (null where no band is seen),
+band_floor}`: `share` = `own` / `beat`, `scale` = `less_bands` / `less_lowest` (`share` and `scale` read 0.0
+where the value they are divided by is under `BEAT_STILL`, null where no band is seen),
`least` = `BOB_OWN`, `scale_least` = `BOB_SCALE`, `band_floor` = `BAND_FLOOR`; values rounded to 0.01; `why` absent
where it says `"cycles"`; `says` is `"cycles"` or null); `unwitnessed` true only where nothing witnessed; absent where not asked. `cue` and
`bob` are recorded only where the picture passes. The same reading is used for the search's cut
diff --git a/sprite_gen/video/local_cycle.py b/sprite_gen/video/local_cycle.py
index 4d362fa..dc7a5d8 100644
--- a/sprite_gen/video/local_cycle.py
+++ b/sprite_gen/video/local_cycle.py
@@ -92,6 +92,12 @@ BOB_OWN = 0.3
BOB_SCALE = 0.6
BAND_FLOOR = 1.0 # pixels of a band's mean width a zoom moves: under it the pixel grid moves the band as much
BEAT_FRAMES = 8 # a rise and fall twice an interval is fitted (`twice_an_interval`) to no fewer frames
+# A line that does not rise and fall fits to round-off, not to nothing: exactly 0 under one machine's numpy, about 1e-30
+# rows under another's, and two lines that move alike leave about 1e-14 rows of each other. A line read in whole rows
+# moves a row or not at all, and a row in one frame reads about 1e-5 rows up and down at the least, on a clip of a
+# thousand frames. Under BEAT_STILL rows there is no rise and fall to take a share of (`_share`, `bob_word` `share` and
+# `scale`). What the witness says does not read it: its floors are whole rows.
+BEAT_STILL = 1e-9
# The lines a walk's cut is read on (`cut_word`), and where each reads the body's top line: on the screen, and over its
# feet (`over_feet`). Each says its own word; the cut's is the first either says, in CUT_WORDS' order.
CUT_LINES = {'screen': 'on the screen', 'feet': 'over its feet'}
@@ -717,8 +723,8 @@ def over_feet(signals, interval):
def _share(rows, beat):
"""`rows` as a share of the top line's rise and fall twice an interval (`beat`, `own_beat`), for a why: or, where
- that is none, the top line holding still on the screen."""
- return f"{rows/beat:.0%}" if beat else "its top line holding still"
+ that is none (under BEAT_STILL), the top line holding still on the screen."""
+ return f"{rows/beat:.0%}" if beat >= BEAT_STILL else "its top line holding still"
def bob_word(signals, interval, *, feet=False):
"""Whether the body rises and falls twice an interval `interval` frames long (`read_cycles`), read off `signals`
@@ -764,9 +770,9 @@ def bob_word(signals, interval, *, feet=False):
word['body'] = {**{k: None if v is None else round(v, 2) for k, v in beat.items() if k != 'bands'},
'bands': {'rows': bands['rows'], **{k: [None if v is None else round(v, 2) for v in bands[k]]
for k in ('width', 'zoom', 'beat', 'reads', 'less')}},
- 'share': round(beat['own']/beat['beat'], 3) if beat['beat'] else 0.0,
+ 'share': round(beat['own']/beat['beat'], 3) if beat['beat'] >= BEAT_STILL else 0.0,
'scale': (None if beat['less_bands'] is None else
- round(beat['less_bands']/beat['less_lowest'], 3) if beat['less_lowest'] else 0.0),
+ round(beat['less_bands']/beat['less_lowest'], 3) if beat['less_lowest'] >= BEAT_STILL else 0.0),
'least': BOB_OWN, 'scale_least': BOB_SCALE, 'band_floor': BAND_FLOOR}
if half is None or quarter is None or half < BOB_TWICE or quarter > -BOB_TWICE:
return {**word, 'says': None, 'why': f"{what} less its flow does not rise and fall twice an interval "
diff --git a/tests/video/test_walk_steps.py b/tests/video/test_walk_steps.py
index 935a353..78e8e16 100644
--- a/tests/video/test_walk_steps.py
+++ b/tests/video/test_walk_steps.py
@@ -56,7 +56,7 @@ import numpy as np
import pytest
from PIL import Image, ImageDraw
-from conftest import feet_unseen
+from conftest import feet_unseen, rife_located
from sprite_gen.video import crossings, legs, local_cycle, loop
FRAMES = 73
@@ -491,16 +491,18 @@ def _unwitnessed(report: dict, interval: float) -> dict:
@pytest.mark.slow
[email protected]("walker, view, interval", [("behind", None, 17.5), ("behind", "back_diagonal", 17.5),
- ("outward", "front_diagonal", 16)])
[email protected](900) # up to 12 calls of the binary at 300 x 220 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver
[email protected]("walker, view, interval, runs", [("behind", None, 17.5, 12), ("behind", "back_diagonal", 17.5, 12),
+ ("outward", "front_diagonal", 16, 0)])
def test_a_walk_whose_feet_meet_once_a_cycle_but_whose_body_does_not_bob_is_cut_two_intervals_with_a_warning(tmp_path, walker, view,
- interval):
+ interval, runs, rife_runs):
"""The two walkers whose feet meet once a cycle, their body held still: its top line does not rise and fall, and
nothing else that reads no leg can tell a step on from a cycle on. The crossings stay on steps: two intervals, two
cycles, named in a warning — never one interval read as two steps on a word that cannot tell (the parent engine cut
one cycle on the picture where a pass hid, and on the foot cue's turn half an interval on from the view)."""
draw = (lambda k: _behind(k, cycle=interval, hold=1, bob=0)) if walker == "behind" else (lambda k: _outward(k, cycle=interval, bob=0))
report = _cut(tmp_path / "out", _keyed(tmp_path, draw), *(("--view", view) if view else ()))
+ assert rife_runs() == (runs if rife_located() else 0)
said = _unwitnessed(report, interval)
assert said["bob"]["swing"] < local_cycle.BOB_FLOOR and "does not rise and fall" in said["bob"]["why"]
@@ -526,8 +528,9 @@ def test_a_walk_whose_feet_meet_once_a_cycle_its_arms_swinging_past_its_sides_is
@pytest.mark.slow
[email protected]("cycle", [16, 18])
-def test_a_diagonal_walk_whose_near_foot_steps_out_is_cut_one_cycle_from_its_view(tmp_path, cycle):
[email protected](900) # up to 10 calls of the binary at 300 x 220 (the held fill's frames between, both cuts): seconds on a GPU, minutes on a CPU's Vulkan driver
[email protected]("cycle, runs", [(16, 0), (18, 10)])
+def test_a_diagonal_walk_whose_near_foot_steps_out_is_cut_one_cycle_from_its_view(tmp_path, cycle, runs, rife_runs):
"""On a front diagonal the near foot steps out toward the camera and passes the far one apart: the feet meet on the
screen once a cycle, and briefly — no pass hides. Given the view, the count asks the picture: the clip one interval
on is the same picture, the legs as they were, the view's foot cue does not turn over there, and the body rises and
@@ -550,11 +553,13 @@ def test_a_diagonal_walk_whose_near_foot_steps_out_is_cut_one_cycle_from_its_vie
assert "cycles" not in plain["cycle"]["step_count"] and abs(plain["cycle"]["length"] - 2 * cycle) <= 1
said = plain["cycle"]["cut_witness"]
assert said["says"] == "four steps" and local_cycle.four_steps(plain["cycle"]) and plain["cycle"]["steps"]["count"] == 2
+ assert rife_runs() == (runs if rife_located() else 0)
@pytest.mark.slow
[email protected]("cycle", [20, 24])
-def test_a_walk_whose_feet_stay_apart_and_meet_once_a_cycle_is_cut_one_cycle_on_the_order_its_feet_are_drawn_in(tmp_path, cycle):
[email protected](900) # up to 12 calls of the binary at 300 x 220 (the held fill's frames between, both cuts): seconds on a GPU, minutes on a CPU's Vulkan driver
[email protected]("cycle, runs", [(20, 10), (24, 12)])
+def test_a_walk_whose_feet_stay_apart_and_meet_once_a_cycle_is_cut_one_cycle_on_the_order_its_feet_are_drawn_in(tmp_path, cycle, runs, rife_runs):
"""Seen from the front, the feet apart, the foot stepping toward the camera drawn lower: the feet meet on the screen
once a cycle, and the body does not rise and fall. The clip shows its two sides of feet are its two legs — seen apart
most of the time, one drawn lower and then the other by 6 rows either way, no foot planted on the ground sliding
@@ -573,6 +578,7 @@ def test_a_walk_whose_feet_stay_apart_and_meet_once_a_cycle_is_cut_one_cycle_on_
side = _cut(tmp_path / "side", keyed, "--view", "side")
assert abs(side["cycle"]["length"] - 2 * cycle) <= 1.5 and local_cycle.unwitnessed(side["cycle"])
assert "order" not in (side["cycle"]["step_count"].get("cycles") or {}) and "order" not in side["cycle"]["cut_witness"]
+ assert rife_runs() == (runs if rife_located() else 0)
@pytest.mark.slow
@@ -723,8 +729,9 @@ def test_a_wide_walk_whose_far_leg_is_drawn_a_few_tones_off_is_cut_two_steps(tmp
@pytest.mark.slow
[email protected]("motion, bob, room", [("arc", 3, 0), ("arc", 0, 60), ("sway", 0, 60), ("ramp", 0, 60)])
-def test_a_walk_whose_crossings_are_its_steps_carried_up_and_down_is_cut_two_steps(tmp_path, motion, bob, room):
[email protected](900) # up to 22 calls of the binary at about 300 x 340 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver
[email protected]("motion, bob, room, runs", [("arc", 3, 0, 8), ("arc", 0, 60, 22), ("sway", 0, 60, 6), ("ramp", 0, 60, 16)])
+def test_a_walk_whose_crossings_are_its_steps_carried_up_and_down_is_cut_two_steps(tmp_path, motion, bob, room, runs, rife_runs):
"""The wide walker with its legs drawn alike, carried up and down the screen with the whole picture (`_carried`;
its legs, their steps and their crossings every 23 frames as they were): bobbing, along a smooth arc 24 px deep;
its body held still, along the same arc, a sway 12 px either way four intervals long, and a ramp 24 px down a row
@@ -735,6 +742,7 @@ def test_a_walk_whose_crossings_are_its_steps_carried_up_and_down_is_cut_two_ste
and falling twice an interval and cut each one step, counted two, and no warning said so)."""
walker = lambda k: _alike(k, cycle=46, phase=13, tone=4, lean=1, leg_tone=0, leg_half=10, bob=bob) # noqa: E731
report = _cut(tmp_path / "out", _keyed(tmp_path, _carried(walker, motion, room)))
+ assert rife_runs() == (runs if rife_located() else 0)
_two_steps(report, 46)
said = _unwitnessed(report, 23)
assert said["asked"].startswith("the feet together")
@@ -772,8 +780,9 @@ def test_a_walk_carried_up_and_down_whole_feet_and_all_is_cut_two_intervals_with
@pytest.mark.slow
[email protected]("bob", [0, 3])
-def test_a_walk_on_a_picture_shaken_twice_an_interval_is_cut_two_steps_with_a_warning(tmp_path, bob):
[email protected](900) # up to 8 calls of the binary at 300 x 340 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver
[email protected]("bob, runs", [(0, 8), (3, 4)])
+def test_a_walk_on_a_picture_shaken_twice_an_interval_is_cut_two_steps_with_a_warning(tmp_path, bob, runs, rife_runs):
"""The wide walker with its legs drawn alike, its crossings its steps every 23 frames, held still (or rising and
falling on its legs once a step), on a picture shaken 3 px up and down twice an interval — dy = round(3 sin(4 pi k /
23)), a camera's shake, not the walk. Its top line on the screen rises and falls twice an interval (the parent engine
@@ -782,6 +791,7 @@ def test_a_walk_on_a_picture_shaken_twice_an_interval_is_cut_two_steps_with_a_wa
warning."""
walker = lambda k: _alike(k, cycle=46, phase=13, tone=4, lean=1, leg_tone=0, leg_half=10, bob=bob) # noqa: E731
report = _cut(tmp_path / "out", _keyed(tmp_path, _carried(walker, lambda k: round(3 * math.sin(4 * math.pi * k / 23)))))
+ assert rife_runs() == (runs if rife_located() else 0)
said = _unwitnessed(report, 23)
assert said["asked"].startswith("the feet together")
if not bob:
@@ -1284,6 +1294,24 @@ def test_a_cut_of_a_body_whose_top_line_holds_still_says_why_whatever_its_length
assert still == [25, 26, 34, 35] and all(words[length]["says"] is None for length in still)
[email protected]("off", [0, 1e-13, -1e-11])
+def test_a_top_line_that_holds_still_reads_so_whatever_round_off_its_fit_leaves(off):
+ """The same walker on a cut of 25 frames. Its top line fits to round-off, not to nothing, and what round-off leaves
+ differs from machine to machine: exactly 0 under one numpy, a little over it under another. Laid over the line, as
+ much as round-off leaves or more, it reads as the line reads with none: holding still, with no share of a rise and
+ fall (the parent engine read it as the rise and fall and took a share of it, under a why and in the record alike,
+ where its fit did not come to exactly 0). A row in one frame is a rise and fall."""
+ frames = [_apart(k, cycle=30) for k in range(FRAMES)]
+ signals = {**legs.strike_signals(frames), **legs.body_signals(frames)}
+ top = np.asarray(signals["top"], dtype=float) + off * np.cos(4 * np.pi * np.arange(FRAMES) / 25)
+ word = local_cycle.bob_word({**signals, "top": top}, 25, feet=True)
+ assert word["says"] is None and "its top line holding still" in word["why"] and word["body"]["share"] == 0.0
+ top[36] += 1
+ word = local_cycle.bob_word({**signals, "top": top}, 25, feet=True)
+ assert word["says"] is None and "its top line holding still" not in word["why"]
+ assert word["body"]["beat"] > 0 and word["body"]["share"] > 0
+
+
# Walkers moved or zoomed with the whole picture, by their interval between crossings d: the side walker whose legs are
# drawn alike and wide, its crossings its steps (23 frames), and the walker seen from behind whose feet meet once a cycle
# (17.5); held still, carried up and down whole (feet and all, on the walk's beat), or rising and falling on its legs