refactor(rundown): simplify gap and overlap accumulation

The gap/overlap detection is already a merge-intervals sweep: `latestEvent`
is the running max end and `getTimeFrom` is `start - maxEnd`. Making that
explicit collapses the branching around it.

- getTimeFrom: the three branches all returned the same subtraction
- totalDuration: the gap === 0 / gap > 0 / gap < 0 cases are all
  Math.max(duration + gap, 0), since duration is never negative

Same behaviour, no signature changes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XSraCPafWbAg35gAFrtgH
This commit is contained in:
Claude
2026-07-31 05:10:29 +00:00
parent 5cf36f049a
commit 93170fbc69
3 changed files with 19 additions and 31 deletions
@@ -152,13 +152,10 @@ export function computeScopedRundown(
const timeFromPrevious: number = getTimeFrom(currentEntry, lastEntry);
if (timeFromPrevious === 0) {
totalDuration += currentEntry.duration;
} else if (timeFromPrevious > 0) {
totalDuration += timeFromPrevious + currentEntry.duration;
} else if (timeFromPrevious < 0) {
totalDuration += Math.max(currentEntry.duration + timeFromPrevious, 0);
}
// each event only contributes the time it pushes past the latest event so far
// NOTE: timeFromPrevious is negative on overlap, so adding it removes the overlapping part
totalDuration += Math.max(currentEntry.duration + timeFromPrevious, 0);
if (isNewLatest(currentEntry, lastEntry)) {
lastEntry = currentEntry;
}