@@ -17,6 +17,7 @@ import {
1717 buildLayoutSampleTimes ,
1818 buildTransitionSampleTimes ,
1919 collapseStaticLayoutIssues ,
20+ CONTENT_OVERLAP_HELD_ERROR_MS ,
2021 longestContiguousRunMs ,
2122 dedupeLayoutIssues ,
2223 limitLayoutIssues ,
@@ -489,19 +490,35 @@ async function collectGridSamples(
489490
490491// Dense grid catches mid-motion text collisions the sparse layout grid seeks past; text-only overlap collection is cheap enough to afford it.
491492const OVERLAP_SAMPLE_FPS = 8 ;
492- // Ceiling that bounds dense seeks; past ~75s the grid degrades below 8fps rather than growing the seek budget without limit.
493- const OVERLAP_MAX_SAMPLES = 600 ;
493+ // A fixed ceiling, so check's work does not grow with film length: clip windows first, then a uniform fill.
494+ const OVERLAP_MAX_SAMPLES = 240 ;
495+ // Part of it re-looks at an overlap half a second on where the grid is too sparse to show it held.
496+ const OVERLAP_HOLD_PROBES = 60 ;
497+
498+ function evenlyPicked ( times : number [ ] , count : number ) : number [ ] {
499+ if ( times . length <= count ) return times ;
500+ const last = Math . max ( 1 , count - 1 ) ;
501+ return Array . from (
502+ { length : count } ,
503+ ( _ , i ) => times [ Math . floor ( ( i * ( times . length - 1 ) ) / last ) ] ?? 0 ,
504+ ) ;
505+ }
494506
495- function buildOverlapSampleTimes ( duration : number ) : number [ ] {
507+ function buildOverlapSampleTimes ( duration : number , clipEdges : number [ ] ) : number [ ] {
496508 if ( ! Number . isFinite ( duration ) || duration <= 0 ) return [ ] ;
497509 const count = Math . min (
498- OVERLAP_MAX_SAMPLES ,
510+ OVERLAP_MAX_SAMPLES - OVERLAP_HOLD_PROBES ,
499511 Math . max ( 2 , Math . ceil ( duration * OVERLAP_SAMPLE_FPS ) + 1 ) ,
500512 ) ;
501- const step = duration / ( count - 1 ) ;
502- return mergeSampleTimes (
503- Array . from ( { length : count } , ( _ , index ) => Math . round ( index * step * 1000 ) / 1000 ) ,
504- ) ;
513+ const inner = clipEdges . filter ( ( t ) => t > 0 && t < duration ) ;
514+ const cuts = inner . length > 0 ? mergeSampleTimes ( [ 0 , duration ] , inner ) : [ ] ;
515+ // One sample inside every stretch where the visible clips stay the same, so a short overlap is never stepped over.
516+ const windows = cuts . slice ( 1 ) . map ( ( end , i ) => ( ( cuts [ i ] ?? 0 ) + end ) / 2 ) ;
517+ const picked = evenlyPicked ( windows , count ) ;
518+ const fill = count - picked . length ;
519+ const step = duration / Math . max ( 1 , fill - 1 ) ;
520+ const uniform = Array . from ( { length : fill } , ( _ , i ) => i * step ) ;
521+ return mergeSampleTimes ( [ ...picked , ...uniform ] . map ( ( t ) => Math . round ( t * 1000 ) / 1000 ) ) ;
505522}
506523
507524/** Reruns content_overlap on a fine grid, unconditionally rather than gated on fingerprint change, since an animation aliased to the sparse grid collides between identical-fingerprint samples. */
@@ -512,15 +529,28 @@ async function collectMotionOverlapSamples(
512529 range ?: [ number , number ] ,
513530) : Promise < void > {
514531 const baseTimes = new Set ( grid . layoutSamples ) ;
515- const overlapTimes = buildOverlapSampleTimes ( range ? range [ 1 ] - range [ 0 ] : grid . duration ) ;
532+ const offset = range ?. [ 0 ] ?? 0 ;
533+ const edges = ( await driver . getClipEdges ( ) ) . map ( ( time ) => time - offset ) ;
534+ const overlapTimes = buildOverlapSampleTimes ( range ? range [ 1 ] - range [ 0 ] : grid . duration , edges ) ;
516535 const shiftedTimes = range
517536 ? mergeSampleTimes ( overlapTimes . map ( ( time ) => time + range [ 0 ] ) )
518537 : overlapTimes ;
519- for ( const time of shiftedTimes ) {
538+ const holdS = CONTENT_OVERLAP_HELD_ERROR_MS / 1000 ;
539+ const end = range ? range [ 1 ] : grid . duration ;
540+ let probes = 0 ;
541+ for ( const [ index , time ] of shiftedTimes . entries ( ) ) {
520542 if ( baseTimes . has ( time ) ) continue ;
521543 // Settle-free seek: collectOverlap reads getBoundingClientRect geometry, valid synchronously after setTime, so the dense pass skips the per-seek paint settle.
522544 await driver . seekGeometry ( time ) ;
523- collected . layoutIssues . push ( ...( await driver . collectOverlap ( time ) ) ) ;
545+ const issues = await driver . collectOverlap ( time ) ;
546+ collected . layoutIssues . push ( ...issues ) ;
547+ const next = shiftedTimes [ index + 1 ] ?? Number . POSITIVE_INFINITY ;
548+ const probe = Math . round ( ( time + holdS ) * 1000 ) / 1000 ;
549+ if ( ! issues . length || next - time <= 2 * holdS || probe > end || probes >= OVERLAP_HOLD_PROBES )
550+ continue ;
551+ probes += 1 ;
552+ await driver . seekGeometry ( probe ) ;
553+ collected . layoutIssues . push ( ...( await driver . collectOverlap ( probe ) ) ) ;
524554 }
525555}
526556
0 commit comments