Skip to content

Fix frame order - #2

Open
bbcuffer wants to merge 5 commits into
LibbyRogersBBC:mainfrom
bbcuffer:fix_frame_order
Open

Fix frame order#2
bbcuffer wants to merge 5 commits into
LibbyRogersBBC:mainfrom
bbcuffer:fix_frame_order

Conversation

@bbcuffer

Copy link
Copy Markdown

Fixes two issues on gganimate and enables simplification of bbanim code.

Combo of PRs

thomasp85#525

thomasp85#524

fixing issues

thomasp85#499

thomasp85#498

bbcuffer and others added 5 commits June 22, 2026 10:35
Modulo arithmetic moved the final frame
from last to first.

.frame was frame-number %% number-of-frames
(which is zero for the final frame - ie first
when sorted on .frame)
fix is to use
(frame-number - 1) %% number-of-frames

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two issues caused frames to be distributed unequally across pauses and
transitions, making wrap=FALSE animations zoom back and wrap=TRUE
animations spend more time pausing than transitioning.

Issue 1 — setup_params: an unnecessary phase for pause_first=FALSE
The phase vectors were built by prepending a zero-pause slot and
appending a zero-step slot, then conditionally zeroing elements:

  pause_length <- c(0, pause_length)      # e.g. c(0, 1, 1)
  step_length  <- c(step_length, 0)       # e.g. c(1, 1, 0)
  if (!wrap) pause_length[last] <- 0      # e.g. c(0, 1, 0) for wrap=FALSE

For wrap=FALSE this made no difference.
It left a dead (0, 0) trailing phase; for wrap=TRUE it
left a live (1, 0) trailing phase that allocated frames to a w1 pause
that should not exist (the gif loop provides that continuity).

Fix: drop the append entirely and trim the last pause in one step:
  pause_length <- c(0, pause_length[-length(pause_length)])

The behaviour becomes:
  wrap=FALSE: pause=c(0,1) step=c(1,0)  — transition then freeze
  wrap=TRUE:  pause=c(0,1) step=c(1,1)  — transition, pause, return

Bug 2 — train: nframes inflated by 1 for wrap=TRUE
  if (params$wrap) nframes <- nframes + 1

This made distribute_frames divide one extra frame across all phases,
which in practice biased allocation toward pauses. Wrap is already
handled by padding params$windows with the first window row; the
inflated nframes was not needed and is removed.

Adds tests for all four wrap/pause_first combinations covering both
the phase structure produced by setup_params and the resulting frame
allocation from distribute_frames.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removes redundant nesting of if statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant