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-loop): the same picture overrules the step count only where the feet stand together through a pass

Soohong Kim319f898fd2a7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec48af6..d422e29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,8 +4,8 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
## Unreleased
-- **Fix: `video-loop --anchor motion-auto` keeps the pixel search's cut where the clip's crossings miss a pass, and where no cut of two steps closes in its place.** Seen from behind on a diagonal, the far foot passes hidden behind the near one, so the feet are seen apart once a cycle and together through the other step, its pass among them; in a clip on twos or threes a pass can also fall between two drawings. The count then sees one crossing a cycle, calls the clip's own cycle one step, and cut two cycles with `steps: 2` — which the set alignment read as settling its two-cycle screen, so the loop walked twice as fast as the rest of the set. A cut the count calls an odd number of steps has the legs swapped a cut on; where the clip a cut on is the same picture instead — frame by frame along the cut, its frame a cut on at most 1.0 of the cut's playback steps off (`local_cycle.same_picture`, `SAME_PICTURE_MAX`) — no legs were swapped, the count missed a crossing, and the search's cut stands, its count `uncertain` (`same-picture`, `step_count.search.same_picture`), no `steps` written. And a search's cut the count does not refute — a two out of phase, or uncertain — now gives way only to a two-step cut that passed the gates (in phase, its top calm, its wrap within the seam gate of its step, its seam under the flow limit) and whose seam the gate passes; where none does, the search's cut is kept (`step_count.declined`, a warning line), where before a cut whose seam the gate refuses replaced a loop it passed. A search's cut the count refutes — one step or three, each seen — still gives way to the two-step cut, closing or not. On the synthetic walkers the far foot hiding behind the near reads 0.03 to 0.48 playback steps a cut on, and the half step the count was made for 2.12; a clip the search finds no cycle in and whose crossings miss a pass a cycle is still cut two cycles long ([loop-repair](docs/loop-repair.md) section 3, "The step count").
-- **Tests** — `tests/video/test_walk_steps.py` (a walker seen from behind on a diagonal, on twos and on threes, whose far foot passes hidden: the clip's one cycle, not two, no `steps`; a walker on threes whose big tail closes on no cut of two steps: the search's cut, which passes, where the two-step cut failed the seam gate; the half-step walker reads over the same-picture bound; on `by_steps` itself, a search's cut two steps out of phase stands where every two-step cut's seam fails the gate and gives way where one passes, a cut refuted one step gives way to a two-step cut whose seam fails, and a one-step cut that is the same picture a cut on is kept).
+- **Fix: `video-loop --anchor motion-auto` keeps the pixel search's cut where the clip's crossings miss a pass, and where no cut of two steps closes in its place.** Seen from behind on a diagonal, the far foot passes hidden behind the near one, so the feet are seen apart once a cycle and together through the other step, its pass among them; in a clip on twos or threes a pass can also fall between two drawings. The count then sees one crossing a cycle, calls the clip's own cycle one step, and cut two cycles with `steps: 2` — which the set alignment read as settling its two-cycle screen, so the loop walked twice as fast as the rest of the set. A cut the count calls an odd number of steps has the legs swapped a cut on; where a pass can hide — the feet seen together at a pass over more than half a step, the median of the runs the clip shows whole (`crossings.Reading.overlap`, `HIDE_SHARE`) — and the clip a cut on is the same picture instead — frame by frame along the cut, its frame a cut on at most 1.0 of the cut's playback steps off (`local_cycle.same_picture`, `SAME_PICTURE_MAX`) — no legs were swapped, the count missed a crossing, and the search's cut stands, its count `uncertain` (`same-picture`, `step_count.search.same_picture`), no `steps` written. Both are asked: from the side, legs drawn alike, a step on can draw as near as the next frame, and there the feet pass briefly and the count stands. And a search's cut the count does not refute — a two out of phase, or uncertain — now gives way only to a two-step cut that passed the gates (in phase, its top calm, its wrap within the seam gate of its step, its seam under the flow limit) and whose seam the gate passes; where none does, the search's cut is kept (`step_count.declined`, a warning line), where before a cut whose seam the gate refuses replaced a loop it passed. A search's cut the count refutes — one step or three, each seen — still gives way to the two-step cut, closing or not. On the synthetic walkers the far foot hiding behind the near reads 0.03 to 0.48 playback steps a cut on, the feet together 0.6 of a step and more, and the half step drawn with a tail on its own beat 2.12; a side walker whose two steps are one silhouette, near and far a tone apart, reads 0.89 a step on — the picture alone kept its half step — and is cut two steps, its feet together briefly; a clip the search finds no cycle in and whose crossings miss a pass a cycle is still cut two cycles long ([loop-repair](docs/loop-repair.md) section 3, "The step count").
+- **Tests** — `tests/video/test_walk_steps.py` (a walker seen from behind on a diagonal, on twos and on threes, whose far foot passes hidden: the clip's one cycle, not two, no `steps`; a walker on threes whose big tail closes on no cut of two steps: the search's cut, which passes, where the two-step cut failed the seam gate; a side walker whose two steps are one silhouette, near and far a tone or four apart, cut one step by the search: two steps, its feet passing briefly, where asking the picture alone kept the half step; the half-step walker reads over the same-picture bound; on `by_steps` itself, a search's cut two steps out of phase stands where every two-step cut's seam fails the gate and gives way where one passes, a cut refuted one step gives way to a two-step cut whose seam fails, a one-step cut that is the same picture a cut on is kept where the feet stand together through a pass, and given up for two steps where they pass briefly).
- **New: `video-loop --anchor motion-auto` closes a two-step cut's wrap that a part on its own beat leaves open, with the clip's frames a cycle apart.** A walk cut two steps long by the clip's crossings closes for the legs; a tail swinging round on a beat of its own closes on no cut of two steps, so the seam gate refused every one — and the eased retime does not reach it, since the part turns back at the wrap, where its frames read off the flow against the way. The clip goes on past the cut, and its frame a cycle after one of the cut's shows the legs at the same point of the walk. Under `--repair auto` (and `on`), where such a cut's wrap reads over `--seam-max` on its frames as corrected (`loop.wrap_on_cells`), the frames beside the wrap are made again before the jump repair (`repair.overlap_wrap`): each by RIFE between its two frames of one time — the clip's frame a cycle apart, moved by the analysis translation between the two and corrected as the cut frame was (`loop.cycle_apart`), and the cut's own — so the wrap plays a step the clip filmed and the part goes over to the cut's way over those frames, each frame at its own time. The weights (`repair.overlap_weights`) are the ease in and out x²(3 − 2x), held off it only in the steps where the rest of the body or a body measure, read on the line between the two frames, would go past its bound; a weight of 0 or 1 shows a frame whole, with no call, and a frame at one weight is made once, whatever the run. Four frames, then six, eight, ten and twelve (`OVERLAP_WIDTHS`), on the side — after the wrap or before it — whose frames a cycle apart differ least, never past half the loop; a run is taken only where no made frame has an interpolation fault — a part torn among them, below — the gate passes it, the loop played round still covers two steps (`loop.ring_steps`), no body measure — the foot line, the torso, the ground — moves a pixel past the largest step of the stretch as the loop plays it (the eased retime's bound on the same torso, never the clip's frames a cycle apart: the part going over pulls the body's mass, which is reported, while a torso the clip's frame a cycle on shows elsewhere would slide) — the part steps no further than over the stretch, no new rush is read, no window of the rest of the body steps further than its own largest step over the stretch, and no frame is left further off the flow over its limit (`rejected_for`). The jump repair after it makes nothing from, beside or again over those frames (`jump_repair.overlapped`). A frame made between two frames a cycle apart bridges the part's whole move at once, and where the part swings over a smaller one — a tail across a hand — RIFE drags the small part apart with it, which on art painted without a line no other reading sees: each frame is also read with RIFE's sixteen single passes (`rife.Rife.read`: the binary's eight flips and transposes, both ways in time, run one at a time with no augmentation and turned back, `rife.passes`) and refused as `torn` where the forward passes' mean and the backward passes' mean put the colour and coverage more than 0.05 apart over more than 0.21 of a window a tenth of the body high (`rife.torn`, `interpolation_quality.TORN_WARN`); the frame delivered is still the binary's own. The frames are made the weight nearest a half first, and the first frame with a fault ends its run, the rest of it not made (`unmade`), so a clip whose part crosses another on every run is refused the overlapped wrap and kept as filmed for the gate to refuse. The report carries `wrap_overlap` (each try with the weights chosen, the frames made in play order and in the order made, and the run taken; the binary's calls), the summary names it, a warning line names the frame that ended each refused run, and without RIFE the wrap is cut as filmed with a warning line (`--repair on` refuses). Each frame made costs the binary 34 calls (its frame, and its sixteen passes in colour and coverage); at most forty frames, where every width is made whole and refused. On the test walker (front, 26 frames a cycle, the tail on a 41-frame beat) the cut 29/26 reads 6.23 at the gate as filmed and 3.17 after the jump repair alone; four frames after the wrap rush the tail and are refused, six are taken, and the loop passes at 1.04, two steps, in ten calls. On a second walker whose big tuft bobs on the loop and a cycle on is carried 8 px aside a frame, the walker in its place, four frames are taken at the ease (3.41 → 1.53 at the gate, four calls): the torso moves 0.05 px, the body's mass 3.95 px against the stretch's 0.71, reported; where the whole walker also stands 3 px aside a cycle on, its torso sliding, every run is held at 0.85 of the cut's own frame next to the wrap, the wrap stays open and the cut is kept as filmed for the gate to refuse. On a third walker, painted without a line and seen from behind, whose big tail swings from 48 to −8 degrees across its hand between two frames a cycle apart, the real RIFE's frames at weights 0.5 and 0.7 read torn 0.44 and 0.26 with no other fault; swung 10 degrees past no hand, its frames read 0.04 at most ([loop-repair](docs/loop-repair.md#the-overlapped-wrap--a-part-on-its-own-beat-that-no-cut-of-two-steps-closes)).
- **Tests** — `tests/video/test_loop_overlap.py` (a front walker whose tail swings round on its own beat, refused at the seam on every cut of two steps, is closed at the wrap: each frame beside it made between the clip's frame a cycle apart and the cut's own at its eased weight, once a frame and weight, four frames refused for a rush and six taken, two steps on the loop played round, the body within its drift, the rest of it no faster, every other frame the clip's own and nothing made by the jump repair; on a walker whose big tuft a cycle on is carried aside, every run's drift bound is the stretch's own as the loop plays it — the torso's, which stands still there, never the clip's frames a cycle apart — and the body's mass is reported beside it; with the tuft alone carried over the run is taken near the ease, the torso within its pixel while the mass moves 2 px and more past its own; with the whole walker also standing aside a cycle on, its torso sliding, no run moves it more than a pixel in a step on the frames shown, drawn again, the frame next to the wrap is held off the ease and the cut is kept as filmed; `--repair off` refused as before; without RIFE cut as filmed with a warning, and with `--repair on` refused asking for it; a made frame with a fault ends its run there — the frame nearest a half made first, the rest not made — every width refused and the cut kept as filmed; a stand-in whose passes disagree over a patch of the body ends every run at its first frame as torn, the warning naming it; the real RIFE (marked `real_rife`) drags the painted walker's hand apart between its frames a cycle apart and the frames are refused as torn, no other reading refusing them, while a swing past no hand reads nothing; a weighting search on lines drawn by hand: the ease where nothing binds, held off it in the one step a window of the rest of the body is bounded in, none where a body measure may not move); `tests/video/test_rife.py` (`Rife.read` makes the frame as every call does and then sixteen single passes with no augmentation, the pair flipped and transposed and run both ways in time: with a binary that hands back its first frame, turned back, they disagree by exactly how far the pair differs and only there; `rife.torn` reads a patch a window wide where the passes disagree and not lines a pixel or two wide, scattered pixels, a faint patch or a frame with no body).
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 796cc43..568e657 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -890,7 +890,7 @@ crossings, joined at the wrap where the walk itself goes on, is one cycle (`cros
| `unconfirmed` | frames no reading confirms: a run of feet together cut by the clip's first or last frame that its twin does not confirm, the frames before the first side is seen, a change the clip ends on |
| `step_range` | the clip's own step (the median between crossings) and the range a step must lie in, a factor of √2 either way |
| `readable`, `why`, `alternation` | whether the clip shows its steps: three crossings or more, and in sign mode a lean that turns over a step on (correlation one step on at most **−0.7**, `crossings.ALTERNATION_MAX`) |
-| `cut`, `search` | the cut taken and the pixel search's own cut (or why it found none), each with its `verdict`, `code`, `k` (steps covered), `phase` and `ring`; the search's cut counted an odd number of steps also with `same_picture` (the clip a cut on, in its playback steps) |
+| `cut`, `search` | the cut taken and the pixel search's own cut (or why it found none), each with its `verdict`, `code`, `k` (steps covered), `phase` and `ring`; the search's cut counted an odd number of steps where a pass can hide also with `same_picture` (the clip a cut on, in its playback steps, and `overlap`, the feet together at a pass over the step) |
| `chosen_by` | `search` (kept), `two steps` (chosen on the count), and the search again where the count refutes its cut (`searched_again`) |
| `declined` | the best two-step cut, where none closed and the search's cut stood: its `cut`, `phase`, whether it passed the gates (`gated`) and its `seam` |
@@ -914,17 +914,25 @@ far the wrap is from joining the same point of the walk, in frames, the worst ov
- The search's cut is a two within **1.5** frames of phase (`crossings.PHASE_TOLERANCE`): kept, every
image and frame as the search alone cuts it.
- The count says the search's cut is an odd number of steps — one or three, the legs swapped a cut on —
- but the clip a cut on is the same picture: frame by frame along the cut, its frame a cut on lies at most
- **1.0** of the cut's playback steps off (`local_cycle.same_picture`, `SAME_PICTURE_MAX`;
- `step_count.search.same_picture`). A step on, the legs are swapped, and a swap that draws nearer than
- the next frame is none: the count missed a crossing, and proves nothing. Seen from behind on a
- diagonal, the far foot passes hidden behind the near one, so the feet are seen apart once a cycle and
- together through the other step, its pass among them; in a clip on twos or threes a pass can fall
- between two drawings. The search's cut is kept, every image as the search alone cuts it, its count
- `uncertain` (`same-picture`), and no `steps` is written: the set alignment screens it as any loop. On
- the synthetic walkers of `tests/video/test_walk_steps.py` the frame a cut on lies 0.03 to 0.48
- playback steps off where the far foot hides (on twos and threes), and 2.12 on the half step the count
- was made for, legs drawn alike and a tail on its own beat.
+ where a pass can hide, and the clip a cut on is the same picture. A pass is brief; seen from behind on
+ a diagonal the far foot stands hidden behind the near one through part of the step, so the feet are
+ seen together for most of it, its pass among them, and apart once a cycle. Gap mode, the feet seen
+ together at a pass over more than **0.5** of a step (`crossings.Reading.overlap`, the median of the runs
+ the clip shows whole over the step; `crossings.HIDE_SHARE`), and frame by frame along the cut its frame
+ a cut on at most **1.0** of the cut's playback steps off (`local_cycle.same_picture`,
+ `SAME_PICTURE_MAX`; both in `step_count.search.same_picture`): a step on, the legs are swapped, and a
+ swap that draws nearer than the next frame is none — the count missed a crossing, and proves nothing.
+ The search's cut is kept, every image as the search alone cuts it, its count `uncertain`
+ (`same-picture`), and no `steps` is written: the set alignment screens it as any loop. Both are asked
+ because neither tells alone: from the side, with the legs drawn alike, a step on can draw as near as
+ the next frame — the very half step the count was made for — but there the feet pass briefly and the
+ count stands; where the feet stand together through a step, a lookalike step a cut on still draws
+ further off than a frame. On the synthetic walkers of `tests/video/test_walk_steps.py` the frame a cut
+ on lies 0.03 to 0.48 playback steps off where the far foot hides (on twos and threes, the feet
+ together 0.6 of a step and more), and 2.12 on the half step drawn with a tail on its own beat. The side
+ walker whose two steps are one silhouette, near and far a tone apart, reads 0.89 a step on — under the
+ bound, so the picture alone kept its half step — and 1.04 at two tones; its feet pass briefly, and it is
+ cut two steps.
- Otherwise the cut is among the cuts that cover two steps — any start, any length the count allows,
inside an explicit `--min-len`/`--max-len` but not the state's window, half the clip or the gait
fallback's ceiling (a walk slower than the window is cut two steps long). Those in phase, if any, are
@@ -971,10 +979,12 @@ crossings are not asked.
**What crossings cannot see**: a hold the step range absorbs (a 13-frame step held to 17), a still run of
the feet together inside the clip as long as a pass, and a wobble that reaches the reading's sides at a
step's beat read as steps; a narrow step that opens the feet only just past the reading's threshold
-reads at that threshold. A pass hidden behind the other foot, or between two drawings, leaves one
-crossing a cycle, and the count reads a cycle as one step: the clip's own repeat overrules it where the
-pixel search found it (the same picture a cut on, above); where the search found no cycle, the cut is two
-cycles long and says `steps: 2`. Four-legged gaits are read as one foot band (`legs.strike_signals`), as before.
+reads at that threshold. A pass hidden behind the other foot leaves one crossing a cycle, and the count
+reads a cycle as one step: the clip's own repeat overrules it where the pixel search found it and the feet
+stand together through most of a step (the same picture a cut on, above); where the search found no cycle,
+the cut is two cycles long and says `steps: 2`. A pass that falls between two drawings with the feet seen
+together only briefly is not overruled: from there the same picture a cut on is what a side walk with its
+legs drawn alike does. Four-legged gaits are read as one foot band (`legs.strike_signals`), as before.
### The step screen — a slow walk cut one step long
diff --git a/docs/loop-review.md b/docs/loop-review.md
index 3a3f455..bb12cdb 100644
--- a/docs/loop-review.md
+++ b/docs/loop-review.md
@@ -119,8 +119,9 @@ one step long (or, past a tail on its own beat, three), and the search has nothi
the step repeats. Where the clip shows its feet pass, the cut is counted on those crossings and is
two steps long — any length the count allows, past the window for a slow walk — joined at the walk's
own point (`cycle.step_count`; [loop repair](loop-repair.md) section 3, "The step count"). The search's
-cut stands where the clip a cut on is the same picture though the count says one step (a pass hidden
-behind the other foot or between drawings), and where no cut of two steps closes in its place. Where it
+cut stands where the clip a cut on is the same picture though the count says one step and the feet stand
+together through most of a step (a pass hidden behind the other foot), and where no cut of two steps closes in
+its place. Where it
does not, the cut is screened the other way, over the whole clip (`cycle.step_screen`): where twice it
repeats better than it, the report names it a suspect and nothing else changes. Look at the loop and
count its steps (how often each foot lands); `video-loop --steps 1` cuts it again two of its lengths
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index dcb77d3..7701e16 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -764,7 +764,8 @@ was 17). `video-loop` therefore:
side"). Where the clip shows its steps, the cut is two of them — read off the crossings of the
feet, joined at the walk's own point, the smoothest seam first — and the search's cut is kept
where it already is that, where the clip a cut on is the same picture though the count says one
- step (a pass it did not see), and where no cut of two steps closes in its place
+ step and the feet stand together through most of a step (a pass it did not see), and where no cut
+ of two steps closes in its place
(`cycle.step_count`, "The step count"). Where it does not, the cut taken
is screened for one step of a cycle twice as long, over the whole clip (`cycle.step_screen`, "The
step screen"); nothing is cut on it, and `--steps` is the count that cuts again.
diff --git a/sprite_gen/video/crossings.py b/sprite_gen/video/crossings.py
index dd86745..db91c09 100644
--- a/sprite_gen/video/crossings.py
+++ b/sprite_gen/video/crossings.py
@@ -63,6 +63,9 @@ SEAM_BAND = (1 / ROOT2 - 1, ROOT2 - 1) # the wrap's delta: its step within the
OPEN_SAMPLES = 9 # values an open step's unseen end is tried at, across its bound
PARTIAL_SAMPLES = 3 # values a partial crossing's middle is tried at, across its bound
PHASE_TOLERANCE = 1.5 # frames: crossings are read to half a frame, a cut's length to one
+# gap mode: the feet seen together at a pass, the median whole run over the step, past which a pass can hide among
+# them — the far foot standing behind the near one through part of the step (`Reading.overlap`)
+HIDE_SHARE = 0.5
EPS = 1e-9
@@ -210,6 +213,16 @@ class Reading:
def readable(self) -> bool:
return self.why is None
+ @property
+ def overlap(self) -> float | None:
+ """Gap mode: how long the feet are seen together at a pass, over the step — the median of the runs the clip
+ shows whole. A pass is brief; past HIDE_SHARE the far foot stands behind the near one through part of the
+ step, and a pass can hide in the run. None in sign mode, or without a step or a whole run."""
+ whole = [b - a + 1 for a, b in self.runs if a > 0 and b < self.n - 1]
+ if self.mode != "gap" or self.step is None or not whole:
+ return None
+ return float(np.median(whole)) / self.step
+
def record(self) -> dict[str, Any]:
"""The reading as the report keeps it."""
out: dict[str, Any] = {"method": "observed-crossings-v1", "mode": self.mode, "readable": self.readable,
diff --git a/sprite_gen/video/local_cycle.py b/sprite_gen/video/local_cycle.py
index 9f35d62..31359ca 100644
--- a/sprite_gen/video/local_cycle.py
+++ b/sprite_gen/video/local_cycle.py
@@ -18,6 +18,7 @@ from __future__ import annotations
import math
from sprite_gen._deps import np
from sprite_gen.video import period as period_mod
+from sprite_gen.video.crossings import HIDE_SHARE
REFUSED_SHOWN = 12 # refused windows a failed search reports, as many as a found cycle's candidates
# A two-step cut's seam is as smooth as the smoothest in-phase one's within this much more flow off (`_rank`): about
@@ -27,7 +28,8 @@ REPEAT_OVER_STEP_MAX = 2 # `detect` refuses a repeat further off than two playb
SEAM_TRIES = 4 # two-step cuts, best first, whose seam is read as the seam gate reads it before one is taken (`by_steps`)
# The clip a cut on, frame by frame along the cut, at most this many of the cut's playback steps off: the same picture
# again (`same_picture`). An odd count of steps swaps the legs a cut on, and a step drawn nearer than the next frame
-# is no swap: the count missed a crossing.
+# is no swap: the count missed a crossing — asked only where a pass can hide (crossings.HIDE_SHARE), since from the
+# side a step on can draw as near as that, its legs alike.
SAME_PICTURE_MAX = 1.0
@@ -468,10 +470,12 @@ def by_steps(distances, trajectory, reading, *, found, refused, min_len, max_len
under two steps): the search's cut, as it chose it.
- The search's cut covers two steps (`two`) and its wrap joins the walk at its own point (`reading.in_phase`):
that cut, as it chose it.
- - The crossings count the search's cut an odd number of steps — the legs swapped a cut on — but the clip a cut
- on is the same picture (`same_picture`, at most SAME_PICTURE_MAX playback steps along the cut): no swap, so the
- count missed a crossing (a foot passing hidden behind the other) and proves nothing. The search's cut, as it
- chose it, its count `uncertain` (`same-picture`).
+ - The crossings count the search's cut an odd number of steps — the legs swapped a cut on — but the feet are seen
+ together over more than HIDE_SHARE of a step at a pass (`reading.overlap`: the far foot behind the near one, a
+ pass can hide there) and the clip a cut on is the same picture (`same_picture`, at most SAME_PICTURE_MAX
+ playback steps along the cut): no swap, so the count missed a crossing and proves nothing. The search's cut, as
+ it chose it, its count `uncertain` (`same-picture`). Where passes are brief — from the side, where a step on
+ draws as near as the next frame with the legs alike — the count stands.
- Else the cuts [min_len, max_len] frames long that cover two steps, any start, however long — the window that
binds the search binds no count; none, and the search's word stands. Those in phase, if any, else all, are
read at the wrap (`seam_flow(start, length)`: the flow off of the cut's last and first frames; `wrap_pop`, the
@@ -501,14 +505,17 @@ def by_steps(distances, trajectory, reading, *, found, refused, min_len, max_len
if reading.in_phase(searched):
record.update(chosen_by='search', cut=searched)
return _two_steps(found, record), record
- if searched['verdict'] == 'refuted' and searched['k'][0] % 2:
+ overlap = reading.overlap
+ if searched['verdict'] == 'refuted' and searched['k'][0] % 2 and overlap is not None and overlap > HIDE_SHARE:
near = same_picture(distances, found['start'], found['length'])
- record['search']['same_picture'] = {'over_step': None if near is None else round(near, 3), 'max': SAME_PICTURE_MAX}
+ record['search']['same_picture'] = {'over_step': None if near is None else round(near, 3), 'max': SAME_PICTURE_MAX,
+ 'overlap': round(overlap, 3), 'hides': HIDE_SHARE}
if near is not None and near <= SAME_PICTURE_MAX:
record.update(chosen_by='search', cut={
**searched, 'verdict': 'uncertain', 'code': 'same-picture',
- 'why': f"the crossings count {searched['why']}, but the clip a cut on is the same picture ({near:.2f} playback "
- f"steps along the cut, at most {SAME_PICTURE_MAX:g}): no legs swapped, a crossing unseen"})
+ 'why': f"the crossings count {searched['why']}, but the feet are seen together {overlap:.2f} of a step at a "
+ f"pass (over {HIDE_SHARE:g}: a pass can hide there) and the clip a cut on is the same picture ({near:.2f} "
+ f"playback steps along the cut, at most {SAME_PICTURE_MAX:g}): no legs swapped, a crossing unseen"})
return found, record
twos = reading.twos(min_len, max_len)
record['two_cuts'] = len(twos)
diff --git a/tests/video/test_walk_steps.py b/tests/video/test_walk_steps.py
index 3e9ac6f..7b2fcf4 100644
--- a/tests/video/test_walk_steps.py
+++ b/tests/video/test_walk_steps.py
@@ -104,6 +104,24 @@ def _behind(k: int, *, cycle: int, hold: int) -> Image.Image:
return im
+def _alike(k: float, *, cycle: float, phase: float = 0, tone: int = 1, lean: float = 0) -> Image.Image:
+ """A side walker whose two steps are the same silhouette: the far leg and arm `tone` tones lighter than the near
+ ones, the arms swinging `lean` px further back than forward — nothing else tells a step from the next."""
+ ph = 2 * math.pi * (k + phase) / cycle
+ im = Image.new("RGBA", (300, 220))
+ d = ImageDraw.Draw(im)
+ x, y = 90, 40 + round(3 * math.cos(2 * ph))
+ for sign, t in ((1, 0), (-1, tone)):
+ sw = sign * (16 * math.sin(ph) + lean)
+ d.rectangle((x + 14 - sw - 4, y + 34, x + 14 - sw + 4, y + 72), fill=(190 + t, 190 + t, 190 + t, 255))
+ for sign, t in ((1, 0), (-1, tone)):
+ lx = x + 14 + 14 * sign * math.sin(ph)
+ d.rectangle((lx - 5, y + 80, lx + 5, y + 126), fill=(60 + t, 60 + t, 70 + t, 255))
+ d.rectangle((x, y + 30, x + 28, y + 84), fill=(200, 80, 80, 255))
+ d.rectangle((x + 2, y, x + 26, y + 28), fill=(230, 200, 170, 255))
+ return im
+
+
def _tailed(k: int) -> Image.Image:
"""A side walker on threes, 30 frames a cycle, its legs hurrying through each pass and slowing apart, with a big
tail swinging on a beat of its own (34 frames); each repeat of a drawing redrawn a few tones."""
@@ -173,8 +191,8 @@ def test_a_half_step_diagonal_walk_is_cut_two_steps(tmp_path):
counted = _two_steps(report, 29)
assert counted["mode"] == "gap" and counted["step_range"][1] == 14.5
assert counted["search"]["verdict"] == "refuted" and counted["search"]["k"] == [1] and counted["search"]["cut"][1] in (14, 15)
- # The step a cut on is no repeat of the picture: the tail has moved on.
- assert counted["search"]["same_picture"]["over_step"] > local_cycle.SAME_PICTURE_MAX
+ # Its feet pass briefly: no pass can hide, and the count is not asked whether the clip a cut on is the same picture.
+ assert "same_picture" not in counted["search"]
strip = json.loads((tmp_path / "out" / "loop.strip.json").read_text())
assert strip["steps"] == 2 and strip["cycle_frames"] == report["cycle"]["length"]
# The step screen's pixel suspicion of a cycle twice as long is settled by the count.
@@ -244,6 +262,19 @@ def test_a_held_walk_whose_far_foot_hides_is_cut_one_cycle(tmp_path, cycle, hold
assert c["method"] == "local-repeat-drift-v1"
[email protected]("tone, lean", [(1, 0), (4, 1)])
+def test_a_side_walk_whose_two_steps_look_alike_is_cut_two_steps_however_near_a_step_on(tmp_path, tone, lean):
+ """The case the count was made for, guarded: from the side the two steps are one silhouette, the near leg and arm
+ a tone or a few apart from the far ones. The walk is slower than the window, so the search cuts one step, and at
+ one tone the clip a step on draws nearer than the next frame (0.89 playback steps). Its feet pass briefly — no pass
+ can hide — so the count stands: two steps, a cycle long (as the parent engine cut it; asking the picture alone kept
+ the half step)."""
+ report = _cut(tmp_path / "out", _keyed(tmp_path, lambda k: _alike(k, cycle=46, phase=13, tone=tone, lean=lean)))
+ counted = _two_steps(report, 46)
+ assert counted["search"]["verdict"] == "refuted" and counted["search"]["k"] == [1]
+ assert "same_picture" not in counted["search"]
+
+
def test_a_cut_of_two_steps_that_does_not_close_leaves_the_searchs_cut(tmp_path):
"""On threes, a big tail on its own beat: the search's cut is one the count does not refute (it plays feet held
together past a pass: uncertain), and every cut of two steps leaves the tail open at the wrap, out of phase, its
@@ -345,12 +376,15 @@ def test_the_search_refuses_what_the_crossings_refute_and_names_their_count(unce
assert "refute after the rest" in refused.value.diagnostics["order"]
-def _choose(found: dict, *, period: int, seam: float) -> tuple[dict, dict]:
+def _choose(found: dict, *, period: int, seam: float, run: int = 9) -> tuple[dict, dict]:
"""`by_steps` on a clip whose picture goes round every `period` frames, its feet passing every 15 (crossings at 8,
- 23 … 68), with the search's cut `found`: every two-step cut's seam reads `seam` at the gate, its top calm and its
- flow off 1.0 either side."""
+ 23 … 68), seen together `run` frames at each pass (9: over half a step, a pass can hide there; 3: brief), with the
+ search's cut `found`: every two-step cut's seam reads `seam` at the gate, its top calm and its flow off 1.0 either
+ side."""
D = _distances(period=period, frames=FRAMES)
- reading = crossings.Reading(FRAMES, "gap", [(c, c) for c in (8.0, 23.0, 38.0, 53.0, 68.0)])
+ middles = (8, 23, 38, 53, 68)
+ reading = crossings.Reading(FRAMES, "gap", [(float(c), float(c)) for c in middles],
+ runs=[(c - run // 2, c + run // 2) for c in middles])
return local_cycle.by_steps(
D, np.zeros(FRAMES), reading, found=dict(found), refused=None, min_len=12, max_len=FRAMES,
seam_flow=lambda s, L: {"off": [1.0, 1.0], "turn": [0.0, 0.0], "window": [[0, 0, 1, 1], [0, 0, 1, 1]]},
@@ -391,3 +425,12 @@ def test_a_one_step_cut_that_is_the_same_picture_a_cut_on_is_the_searchs_cycle()
assert (picked["start"], picked["length"]) == (10, 15) and "steps" not in picked
assert record["chosen_by"] == "search" and record["cut"]["code"] == "same-picture" and record["cut"]["verdict"] == "uncertain"
assert record["search"]["same_picture"]["over_step"] <= local_cycle.SAME_PICTURE_MAX
+ assert record["search"]["same_picture"]["overlap"] > crossings.HIDE_SHARE
+
+
+def test_where_the_feet_pass_briefly_the_count_stands_however_alike_a_step_on():
+ """The same clip, its feet seen together only at the moment they pass: no pass can hide, and a step on drawing as
+ near as the next frame is what legs drawn alike do from the side. The count stands: two steps."""
+ picked, record = _choose({"start": 10, "length": 15}, period=15, seam=1.0, run=3)
+ assert record["search"]["verdict"] == "refuted" and "same_picture" not in record["search"]
+ assert record["chosen_by"] == "two steps" and picked["steps"] == {"count": 2, "by": "crossings"}