export const SCRUB_INTERVAL_MS = 150;
export const SCRUB_MAXIMUM_STEP = 512;
export function shouldDrawPreview(drawnFrame, target) {
return drawnFrame !== target;
}
export function randomAccessPointAtOrBefore(randomAccessPoints, index) {
let low = 0;
let high = randomAccessPoints.length;
while (low < high) {
const mid = Math.floor((low + high) / 2);
if (randomAccessPoints[mid] <= index) low = mid + 1;
else high = mid;
}
return low === 0 ? index : randomAccessPoints[low - 1];
}
export function scrubStrideFrames(msPerFrame) {
if (msPerFrame === null) return 1;
if (msPerFrame <= 0) return SCRUB_MAXIMUM_STEP;
const frames = Math.floor(SCRUB_INTERVAL_MS / msPerFrame);
return Math.min(Math.max(frames, 1), SCRUB_MAXIMUM_STEP);
}
export function scrubWalkStart(position, target, msPerFrame, randomAccessPoints) {
if (position === null) return randomAccessPointAtOrBefore(randomAccessPoints, target);
if (position < target) return Math.min(target, position + scrubStrideFrames(msPerFrame));
if (position === target) return target;
return randomAccessPointAtOrBefore(randomAccessPoints, target);
}