Add helper method to find absorbing frames
tswast opened this issue · comments
A dead-end frame is one where there is no next frame in the clip and there are no transitions from that frame.
It is undefined what to do when reaching a dead-end-frame. Does the animation get stuck? Does it disappear?
Per https://en.wikipedia.org/wiki/Absorbing_Markov_chain such a state is called an "absorbing state". Let's use the same term when talking about frames: it's an absorbing frame not a dead-end.
The following SQL query appears to find all desired frames:
-- Select the final frame in each clip.
-- See max-value-in-group: https://stackoverflow.com/a/7745635/101923
SELECT f1.clip_id, f1.clip_order
FROM frame AS f1
LEFT OUTER JOIN frame AS f2
ON f1.clip_id = f2.clip_id
AND f1.clip_order < f2.clip_order
-- Join with transitions to find frames with no transitions out.
LEFT OUTER JOIN transition
ON f1.clip_id = transition.source_clip_id
AND f1.clip_order = transition.source_clip_order
AND (
f1.clip_id != transition.target_clip_id
OR f1.clip_order != transition.target_clip_order
)
WHERE f2.clip_order IS NULL -- No next frame.
AND transition.source_clip_order IS NULL; -- No transitions out.