long-screen 0.1.1

Long Screen as a Rust library and command line: a screen recording in, one big screenshot out
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
//! Cheap Rust-side unit tests for the parts of the region-construction port that don't need Wasm (see
//! tests/unit/parity/regions.test.ts for the real, Wasm-backed oracle comparison).

use super::bands::strongest_cut;
use super::cells::{group_and_label, DisjointSet};
use super::crops::native_edge;
use super::*;

#[test]
fn disjoint_set_unions_by_size_and_compresses_paths() {
    let mut ds = DisjointSet::new(5);
    ds.join(0, 1);
    ds.join(1, 2);
    ds.join(3, 4);
    assert_eq!(ds.find(0), ds.find(2));
    assert_ne!(ds.find(0), ds.find(3));
    ds.join(2, 3);
    assert_eq!(ds.find(0), ds.find(4));
}

#[test]
fn strongest_cut_picks_first_maximum_above_threshold() {
    // 8 bins; informativeFrames = 10; bin 3 clears 12% (>1.2) and is the unique max.
    let g = [0.0, 0.0, 0.5, 1.3, 1.3, 0.0, 0.0, 0.0];
    // Ties keep the FIRST index (strict `>` in the scan), so two equal maxima both at 1.3 resolve to index 3.
    assert_eq!(strongest_cut(&g, 10.0), 3);
    // Below the 4-frame floor, no cut is ever accepted.
    assert_eq!(strongest_cut(&g, 3.0), 0);
}

#[test]
fn group_and_label_keeps_map_insertion_order_and_grows_groups_during_the_fill_scan() {
    // 6 cells, 2 columns: a 4-cell union (0,1,2,3) and two singletons (4,5) below the `minimum` floor
    // (max(3, floor(6*.025)) = 3), so 4 and 5 must be assigned to the nearest large group by Manhattan
    // distance, and (per the TS) that assignment can feed later distance comparisons within the same scan.
    let cols = 2;
    let n = 6;
    let mut ds = DisjointSet::new(n);
    ds.join(0, 1);
    ds.join(1, 2);
    ds.join(2, 3);
    let (large, labels) = group_and_label(&mut ds, n as i64, cols);
    assert_eq!(
        large.len(),
        1,
        "cells 4 and 5 fall below the minimum and must fold into the sole large group"
    );
    assert_eq!(labels, [0, 0, 0, 0, 0, 0]);
    assert_eq!(large[0].len(), 6);
}

#[test]
fn native_edge_falls_back_to_the_scaled_estimate_without_native_stats() {
    assert_eq!(native_edge(None, 10, 2.0, 1, 100, 0.9, 0.0), 20);
    assert_eq!(native_edge(None, 10, 2.0, -1, 100, 0.9, 5.0), 20);
}

#[test]
fn label_atlas_first_region_wins_on_overlap_and_counts_match_the_labels() {
    use super::atlas::AtlasRegion;
    let a = AtlasRegion {
        rect: Rect {
            x: 0.0,
            y: 0.0,
            width: 10.0,
            height: 10.0,
        },
        exclusions: vec![],
        crop: None,
        solid: true,
        mask: None,
    };
    let b = AtlasRegion {
        rect: Rect {
            x: 5.0,
            y: 0.0,
            width: 10.0,
            height: 10.0,
        },
        exclusions: vec![],
        crop: None,
        solid: true,
        mask: None,
    };
    let mut out = vec![0u8; 15 * 10];
    let counts = label_atlas(&[a, b], 15, 10, &mut out).unwrap();
    // The overlap (x in [5,10)) belongs to the FIRST region (a), matching `regionContains` first-wins order.
    assert_eq!(out[5], 1);
    assert_eq!(out[12], 2);
    assert_eq!(out[0], 1);
    assert_eq!(counts.len(), 3);
    assert_eq!(counts[1] as usize, out.iter().filter(|&&c| c == 1).count());
    assert_eq!(counts[2] as usize, out.iter().filter(|&&c| c == 2).count());
}

/// Blank/no-evidence run (zero informative frames, no reference frame): every threshold check that requires
/// `informativeFrames >= 2` is skipped, so top/bottom/left/right stay full-frame, evidence/split are both
/// zero (accepted as "not enough evidence to split", per `e < max(2, informativeFrames*.04)`), and the whole
/// grid unions into one region. `finalize`'s single-full-pane rule then makes it solid and fills `content`
/// exactly — the same fallback `LayerLearner.finish()` produces for a learner that never saw an informative
/// frame.
#[test]
fn finish_falls_back_to_one_solid_pane_with_no_evidence() {
    let width = 4usize;
    let height = 4usize;
    let cell = 24usize; // cols = rows = 1
    let zeros = vec![0.0; 4];
    let input = FinishInput {
        width,
        height,
        cell,
        informative_frames: 0.0,
        native_frames: 0.0,
        row_change: &zeros,
        col_change: &zeros,
        col_moving: &zeros,
        col_mean: &zeros,
        col_gain: &zeros,
        horizontal_gain: &zeros,
        split: &[0.0, 0.0],
        evidence: &[0.0, 0.0],
        activity: &[0.0],
        observations: &[0.0],
        pixel_fixed: &zeros,
        pixel_moving: &zeros,
        native_row_change: None,
        native_col_change: None,
        row_fixed: None,
        row_moving: None,
        reference: None,
    };
    let regions = finish(&input, 96.0, 96.0, 24);
    assert_eq!(regions.len(), 1);
    assert_eq!(regions[0].kind, Kind::Moving);
    assert!(regions[0].solid);
    assert_eq!(
        regions[0].rect,
        Rect {
            x: 0.0,
            y: 0.0,
            width: 96.0,
            height: 96.0
        }
    );
}

/// Runs analysis frames through the learner (one model moving 4 px down, every cell confident), then `finish()` at
/// factor 1 without a native reference, so the left/right band test reads the column statistics alone.
fn learn(width: usize, height: usize, frames: &[Vec<u8>]) -> Vec<RegionOut> {
    use crate::kernels::layers::{Field, FieldMotion, Learner};
    let mut learner = Learner::new(width, height);
    let motions = [FieldMotion {
        x: 0.0,
        y: 4.0,
        support: 100,
        confidence: 1.0,
    }];
    let cells = learner.cols * learner.rows;
    let (labels, confidence, dynamic) = (vec![0u8; cells], vec![255u8; cells], vec![0u8; cells]);
    let field = Field {
        motions: &motions,
        labels: &labels,
        confidence: &confidence,
        dynamic: &dynamic,
        cols: learner.cols,
        rows: learner.rows,
        difference: 1.0,
        unknown: false,
    };
    for pair in frames.windows(2) {
        assert!(learner.add(&field, &pair[0], &pair[1], None));
    }
    let input = FinishInput {
        width,
        height,
        cell: learner.cell,
        informative_frames: learner.informative_frames as f64,
        native_frames: 0.0,
        row_change: &learner.row_change,
        col_change: &learner.col_change,
        col_moving: &learner.col_moving,
        col_mean: &learner.col_mean,
        col_gain: &learner.col_gain,
        horizontal_gain: &learner.horizontal_gain,
        split: &learner.split,
        evidence: &learner.evidence,
        activity: &learner.activity,
        observations: &learner.observations,
        pixel_fixed: &learner.pixel_fixed,
        pixel_moving: &learner.pixel_moving,
        native_row_change: None,
        native_col_change: None,
        row_fixed: None,
        row_moving: None,
        reference: None,
    };
    finish(&input, width as f64, height as f64, 1)
}

/// A page scrolling 4 px a frame beside a 24-px sidebar that stands still except at `bounce` frames, where
/// the whole window (sidebar included) is shifted down 4 px, as macOS's elastic overscroll does at a page's end.
fn sidebar_frames(
    count: usize,
    bounce: &[usize],
    sparse_right: Option<&dyn Fn(usize) -> bool>,
) -> Vec<Vec<u8>> {
    let (w, h) = (120usize, 72usize);
    (0..count)
        .map(|f| {
            let shift = if bounce.contains(&f) { 4 } else { 0 };
            let mut g = vec![0u8; w * h];
            for y in 0..h {
                for x in 0..w {
                    let v = if x < 24 {
                        // Sidebar: icon-like blocks, distinct per column so the band has visible structure.
                        let sy = y + 80 - shift;
                        if (sy / 6) % 2 == 0 && x % 8 < 5 {
                            200 - x as i32 * 4
                        } else {
                            30
                        }
                    } else if x >= 96 && sparse_right.is_some() {
                        // A sparse right-hand pane: one faint text line, present (and scrolling) only in some frames.
                        let sy = y + f * 4;
                        if sparse_right.unwrap()(f) && sy % 36 < 2 {
                            50
                        } else {
                            30
                        }
                    } else {
                        // Scrolling page content.
                        let sy = y + f * 4 + 80 - shift;
                        (((x * 7) ^ (sy * 13)) % 97 + 60) as i32
                    };
                    g[y * w + x] = v as u8;
                }
            }
            g
        })
        .collect()
}

/// Failure case (g.mov): a fixed sidebar that the whole window's bounce moved in 20 of 479 frames lost its band,
/// because the mean change those frames added crossed 0.7, and the sidebar was painted into the scrolling canvas.
#[test]
fn a_sidebar_still_but_for_a_few_bounces_is_a_fixed_band() {
    for bounce in [&[][..], &[10, 11, 30, 31][..]] {
        let regions = learn(120, 72, &sidebar_frames(41, bounce, None));
        let fixed: Vec<_> = regions
            .iter()
            .filter(|r| r.kind == Kind::Fixed)
            .map(|r| r.rect)
            .collect();
        assert!(
            fixed.iter().any(|r| r.x == 0.0 && r.width == 24.0),
            "bounce at {bounce:?}: expected a fixed 24-px left band, got {fixed:?}"
        );
    }
}

/// Failure case the other way: a sparse pane whose content moves in most frames (faint, so its mean change per
/// frame is small) must stay with the moving page, not be frozen as a band.
#[test]
fn a_sparse_pane_that_moves_in_most_frames_is_not_a_band() {
    let present = |f: usize| !f.is_multiple_of(4);
    let frames = sidebar_frames(41, &[], Some(&present));
    let regions = learn(120, 72, &frames);
    let fixed_right: Vec<_> = regions
        .iter()
        .filter(|r| r.kind == Kind::Fixed && r.rect.x + r.rect.width == 120.0 && r.rect.x > 0.0)
        .map(|r| r.rect)
        .collect();
    assert!(
        fixed_right.is_empty(),
        "the moving pane was frozen as a right band: {fixed_right:?}"
    );
}

/// A 100×60 window seen at factor 1: a sidebar over x 0..20 (lines of text in `sidebar_text`, else blank) with its
/// edge at x 20, an empty dark margin over x 20..60 that never changes, and page content over x 60..100 that moves in
/// every informative frame. Returns the bands.
fn wide_margin_bands(sidebar_text: bool) -> super::bands::Bands {
    let (w, h) = (100usize, 60usize);
    let mut rgba = vec![255u8; w * h * 4];
    for y in 0..h {
        for x in 0..w {
            let v = if x < 20 {
                if sidebar_text && y % 6 == 0 && (3..17).contains(&x) {
                    200
                } else {
                    60
                }
            } else if x < 60 {
                10
            } else if (y + x) % 7 < 3 {
                230
            } else {
                40
            };
            rgba[(y * w + x) * 4..(y * w + x) * 4 + 3].fill(v);
        }
    }
    let reference = Rgba {
        width: w,
        height: h,
        data: &rgba,
    };
    let frames = 10.0;
    let row_change = vec![frames; h];
    let col_moving: Vec<f64> = (0..w).map(|x| if x < 60 { 0.0 } else { frames }).collect();
    let col_mean = vec![0.0; w];
    super::bands::detect_bands(
        w as i64,
        h as i64,
        frames,
        &row_change,
        None,
        (&[], &[]),
        &col_moving,
        &col_mean,
        Some(&reference),
        w as f64,
        h as f64,
        1.0,
    )
}

// test_2: the browser's tab panel and ChatGPT's sidebar stand still, and so does the empty dark margin of the chat
// beside them, so the walk over stationary columns ran past 45% of the width and the whole left band was thrown
// away; the sidebar stayed in the moving layer and tore. At the cap, the sidebar's own edge is still looked for.
#[test]
fn a_sidebar_beside_an_empty_margin_wider_than_the_cap_is_a_left_band() {
    let bands = wide_margin_bands(true);
    assert_eq!(bands.left, 20);
    assert_eq!(bands.exact_left, Some(20.0));
}

// A blank strip with an edge is still page geometry, not a sidebar (§十: 侧边带要有可见结构).
#[test]
fn a_blank_strip_beside_an_empty_margin_is_not_a_left_band() {
    let bands = wide_margin_bands(false);
    assert_eq!(bands.left, 0);
    assert_eq!(bands.exact_left, None);
}

/// One frame's motion field for `learn_fields`: the models (dx, dy) and each analysis cell's model index.
type FrameField = (Vec<(f64, f64)>, Vec<u8>);

/// Runs `frames` through the learner with a per-frame motion field: `field(f)` gives frame f's models (the first
/// is the page's, whatever moves) and the model each analysis cell is labelled with. Then `finish()` at factor 1.
fn learn_fields(
    width: usize,
    height: usize,
    frames: &[Vec<u8>],
    field: &dyn Fn(usize, usize, usize) -> FrameField,
) -> Vec<RegionOut> {
    learn_fields_seeing(width, height, frames, field, false)
}

/// `learn_fields`, with the last frame as the appearance reference when `with_reference` is set.
fn learn_fields_seeing(
    width: usize,
    height: usize,
    frames: &[Vec<u8>],
    field: &dyn Fn(usize, usize, usize) -> FrameField,
    with_reference: bool,
) -> Vec<RegionOut> {
    use crate::kernels::layers::{Field, FieldMotion, Learner};
    let mut learner = Learner::new(width, height);
    let (cols, rows) = (learner.cols, learner.rows);
    let cells = cols * rows;
    let (confidence, dynamic) = (vec![255u8; cells], vec![0u8; cells]);
    for (f, pair) in frames.windows(2).enumerate() {
        let (models, labels) = field(f + 1, cols, rows);
        let motions: Vec<FieldMotion> = models
            .iter()
            .map(|&(x, y)| FieldMotion {
                x,
                y,
                support: 100,
                confidence: 1.0,
            })
            .collect();
        let field = Field {
            motions: &motions,
            labels: &labels,
            confidence: &confidence,
            dynamic: &dynamic,
            cols,
            rows,
            difference: 1.0,
            unknown: false,
        };
        assert!(learner.add(&field, &pair[0], &pair[1], None));
    }
    let rgba: Vec<u8> = frames
        .last()
        .unwrap()
        .iter()
        .flat_map(|&v| [v, v, v, 255])
        .collect();
    let input = FinishInput {
        width,
        height,
        cell: learner.cell,
        informative_frames: learner.informative_frames as f64,
        native_frames: 0.0,
        row_change: &learner.row_change,
        col_change: &learner.col_change,
        col_moving: &learner.col_moving,
        col_mean: &learner.col_mean,
        col_gain: &learner.col_gain,
        horizontal_gain: &learner.horizontal_gain,
        split: &learner.split,
        evidence: &learner.evidence,
        activity: &learner.activity,
        observations: &learner.observations,
        pixel_fixed: &learner.pixel_fixed,
        pixel_moving: &learner.pixel_moving,
        native_row_change: None,
        native_col_change: None,
        reference: with_reference.then(|| Rgba {
            width,
            height,
            data: &rgba,
        }),
        row_fixed: None,
        row_moving: None,
    };
    finish(&input, width as f64, height as f64, 1)
}

/// Textured content: a pattern that changes along both axes, sampled at world position (x, y).
fn texture(x: usize, y: usize) -> u8 {
    (((x * 7) ^ (y * 13)) % 97 + 60) as u8
}

/// Failure case (new_ip_1's header, new_ip_9's glass tab bar, new_mac_1's YouTube masthead and sidebar): a bar
/// that stays on screen while the page scrolls 4 px a frame, but whose pixels still change a little every frame
/// (the page shows through it, a title collapses), so its rows' mean change is over the band walk's 0.9 and no
/// top band is found. The field gives its cells the page's motion in half the frames, as a field does where the
/// page shows through, so its activity is far above 8 % of the page's. It must be learned as fixed UI, not as a
/// second scroll layer that the solve then tears into one fragment per state.
#[test]
fn a_bar_that_stays_put_while_its_pixels_flicker_is_fixed_ui() {
    for with_reference in [false, true] {
        let (moving, fixed) = flickering_bar(&|x, y| texture(x + 500, y), with_reference);
        assert_eq!(
            moving.len(),
            1,
            "expected one scroll layer, got {moving:?} (fixed {fixed:?})"
        );
        assert!(
            fixed
                .iter()
                .any(|r| r.y == 0.0 && r.height == 48.0 && r.width == 96.0),
            "expected the bar as fixed UI, got fixed {fixed:?}, moving {moving:?}"
        );
    }
}

/// Failure case (pub_2's empty chat margin, 584 × 504 px of black under the app's top bar): an area that stays put
/// while the page scrolls, but whose only structure is the one line where it meets the bar above. The line's pixels
/// vote for standing still, the blank ones for nothing, so its votes alone made it a fixed canvas of an empty
/// image. With an appearance reference it must stay what it was before: a moving region, not screen-fixed UI.
#[test]
fn a_blank_area_whose_only_structure_is_one_line_is_not_fixed_ui() {
    let line = |_: usize, y: usize| if y == 20 { 200 } else { 0 };
    let (moving, fixed) = flickering_bar(&line, true);
    assert!(
        fixed.is_empty() && moving.len() == 2,
        "expected the blank area to stay a moving region, got moving {moving:?}, fixed {fixed:?}"
    );
    // Without a reference there is nothing to look at, and the votes decide as before.
    let (_, fixed) = flickering_bar(&line, false);
    assert_eq!(fixed.len(), 1, "{fixed:?}");
}

/// A 48-row bar painted by `bar(x, y)` stays on screen with a 2-level flicker on top (alternating frames) over a
/// page scrolling 4 px a frame; the field gives the bar's cells the page's motion in half the frames, as a field
/// does where the page shows through. Returns the (moving, fixed) region rects.
fn flickering_bar(
    bar_paint: &dyn Fn(usize, usize) -> u8,
    with_reference: bool,
) -> (Vec<Rect>, Vec<Rect>) {
    let (w, h, bar) = (96usize, 144usize, 48usize);
    let frames: Vec<Vec<u8>> = (0..41)
        .map(|f| {
            let mut g = vec![0u8; w * h];
            for y in 0..h {
                for x in 0..w {
                    g[y * w + x] = if y < bar {
                        bar_paint(x, y) + if f % 2 == 0 { 2 } else { 0 }
                    } else {
                        texture(x, y + f * 4)
                    };
                }
            }
            g
        })
        .collect();
    let regions = learn_fields_seeing(
        w,
        h,
        &frames,
        &|f, cols, rows| {
            let mut labels = vec![0u8; cols * rows];
            if f % 2 == 1 {
                labels[..cols * (bar / 24)].fill(1);
            }
            let _ = rows;
            (vec![(0.0, 4.0), (0.0, 0.0)], labels)
        },
        with_reference,
    );
    let moving: Vec<_> = regions
        .iter()
        .filter(|r| r.kind == Kind::Moving)
        .map(|r| r.rect)
        .collect();
    let fixed: Vec<_> = regions
        .iter()
        .filter(|r| r.kind == Kind::Fixed)
        .map(|r| r.rect)
        .collect();
    (moving, fixed)
}

/// Failure case the other way: a narrower pane that scrolls on its own in more frames than it stands still, beside
/// a wider pane that scrolls in the rest, is a second scroll layer and stays one.
#[test]
fn a_second_pane_that_mostly_scrolls_stays_a_scroll_layer() {
    let (w, h, split) = (144usize, 144usize, 96usize);
    let right_moves = |f: usize| f > 12;
    let frames: Vec<Vec<u8>> = (0..41)
        .map(|f| {
            let (left_offset, right_offset) = if right_moves(f) {
                (12 * 4, (f - 12) * 4)
            } else {
                (f * 4, 0)
            };
            let mut g = vec![0u8; w * h];
            for y in 0..h {
                for x in 0..w {
                    g[y * w + x] = if x < split {
                        texture(x, y + left_offset)
                    } else {
                        texture(x + 300, y + right_offset)
                    };
                }
            }
            g
        })
        .collect();
    let regions = learn_fields(w, h, &frames, &|f, cols, rows| {
        let mut labels = vec![0u8; cols * rows];
        for y in 0..rows {
            for x in 0..cols {
                let right = x * 24 >= split;
                labels[y * cols + x] = if right == right_moves(f) { 0 } else { 1 };
            }
        }
        (vec![(0.0, 4.0), (0.0, 0.0)], labels)
    });
    let moving: Vec<_> = regions
        .iter()
        .filter(|r| r.kind == Kind::Moving)
        .map(|r| r.rect)
        .collect();
    assert_eq!(
        moving.len(),
        2,
        "expected both panes as scroll layers, got {moving:?}"
    );
}

// Translucent chrome: every row of an iOS 26 glass bar changes as the page scrolls beneath it, so the change test
// finds no band on that side. The bar's own icons and text still stand still, which the row votes record
// (`Learner::row_fixed` against `Learner::row_moving`). `fixed`/`moving` are per-frame vote counts for the rows of
// `[0, chrome)`; every other row votes like scrolling content.
fn glass_bands(chrome: usize, fixed: f64, moving: f64, still_rows: usize) -> super::bands::Bands {
    glass_bands_over(chrome, fixed, moving, still_rows, &[])
}

/// `glass_bands`, with fixed objects floating on the page: in the rows of each `(from, to, samples)`, that many of
/// the row's sampled pixels stand still in every frame and never follow the page, while the rows' totals still vote
/// like scrolling content (the page around the objects is far larger than they are).
fn glass_bands_over(
    chrome: usize,
    fixed: f64,
    moving: f64,
    still_rows: usize,
    objects: &[(usize, usize, usize)],
) -> super::bands::Bands {
    let (w, h) = (204usize, 300usize);
    let frames = 10.0;
    let samples = ((w - 4).div_ceil(4)) as f64;
    let row_change: Vec<f64> = (0..h)
        .map(|y| if y < still_rows { 0.0 } else { 5.0 * frames })
        .collect();
    let row_fixed: Vec<f64> = (0..h)
        .map(|y| frames * if y < chrome { fixed } else { 0.02 * samples })
        .collect();
    let row_moving: Vec<f64> = (0..h)
        .map(|y| frames * if y < chrome { moving } else { 0.3 * samples })
        .collect();
    let col_moving = vec![frames; w];
    let col_mean = vec![0.0; w];
    let mut pixel_fixed = vec![0.0; w * h];
    let pixel_moving = vec![0.0; w * h];
    for &(from, to, samples) in objects {
        for y in from..to {
            for k in 0..samples {
                pixel_fixed[y * w + 2 + 4 * k] = frames;
            }
        }
    }
    super::bands::detect_bands(
        w as i64,
        h as i64,
        frames,
        &row_change,
        Some((&row_fixed, &row_moving)),
        (&pixel_fixed, &pixel_moving),
        &col_moving,
        &col_mean,
        None,
        w as f64,
        h as f64,
        1.0,
    )
}

#[test]
fn a_glass_bar_whose_icons_stand_still_is_a_top_band() {
    let bands = glass_bands(40, 15.0, 2.0, 0);
    assert_eq!((bands.top, bands.bottom), (40, 300));
}

#[test]
fn rows_that_mostly_follow_the_page_are_not_a_band() {
    // Standing still wins at some pixels of scrolling content too (sub-pixel steps, loading images), but not
    // 1.5 times as often as the motion does.
    let bands = glass_bands(40, 15.0, 12.0, 0);
    assert_eq!(bands.top, 0);
}

#[test]
fn a_handful_of_still_pixels_in_a_bare_row_is_not_a_band() {
    // 1 vote per frame in a row of 50 samples is under the 3% floor, however few the moving votes.
    let bands = glass_bands(40, 1.0, 0.0, 0);
    assert_eq!(bands.top, 0);
}

#[test]
fn a_fade_over_the_page_without_icons_is_not_a_band() {
    // Standing still wins at a fade because each row dims the page differently, but on no row at the density of
    // a bar's icons and text (5 of 50 samples here, against a fifth or more).
    let bands = glass_bands(40, 5.0, 1.0, 0);
    assert_eq!(bands.top, 0);
}

#[test]
fn a_side_the_change_test_already_bounds_keeps_its_edge() {
    // Rows 0..12 pass the change test, so the votes of rows 12..40 are not consulted on that side.
    let bands = glass_bands(40, 15.0, 2.0, 12);
    assert_eq!(bands.top, 12);
}

// The lower part of an iOS 26 glass bar: the blur fades out downwards, the page shows through ever more clearly and
// votes for the motion, so the row votes stop the band early (new_ip_2 at 285 of 480 px, new_ip_3 at 155), while
// the bar's buttons, avatar and name capsule still float there. Counted per sampled pixel, they stand still.

#[test]
fn objects_floating_right_under_a_glass_band_belong_to_it() {
    let bands = glass_bands_over(40, 15.0, 2.0, 0, &[(40, 110, 8)]);
    assert_eq!(bands.top, 110);
}

#[test]
fn a_short_gap_between_the_objects_does_not_end_the_band() {
    let bands = glass_bands_over(40, 15.0, 2.0, 0, &[(40, 70, 8), (85, 110, 8)]);
    assert_eq!(bands.top, 110);
}

#[test]
fn a_float_button_past_a_stretch_of_page_stays_out_of_the_band() {
    // A button floating on the page past a stretch of rows with no standing-still pixels (25 rows at factor 1 here)
    // is not part of the bar above it.
    let bands = glass_bands_over(40, 15.0, 2.0, 0, &[(40, 105, 8), (130, 134, 8)]);
    assert_eq!(bands.top, 105);
}

#[test]
fn a_bar_soft_edge_of_a_few_rows_does_not_move_the_band() {
    // The halo above new_ip_3's input bar: dense standing-still rows right past the band's edge, 35 px of them,
    // where the page shows through sharply. Only objects as tall as `FIXED_ROW_RUN` move the band.
    let bands = glass_bands_over(40, 15.0, 2.0, 0, &[(40, 75, 40)]);
    assert_eq!(bands.top, 40);
}

#[test]
fn a_few_still_pixels_in_a_row_do_not_extend_the_band() {
    // Under an icon's width of samples: a scrollbar or a stray still pixel of the page.
    let bands = glass_bands_over(40, 15.0, 2.0, 0, &[(40, 110, 4)]);
    assert_eq!(bands.top, 40);
}

#[test]
fn a_band_found_by_the_change_test_is_not_extended() {
    let bands = glass_bands_over(40, 15.0, 2.0, 12, &[(12, 110, 8)]);
    assert_eq!(bands.top, 12);
}

#[test]
fn still_pixels_down_the_whole_screen_do_not_extend_the_band() {
    // A sidebar (or anything else fixed beside the page) stands still in every row; a walk that reaches the 45 % cap
    // has found no bar edge, and the band stays as the votes found it.
    let bands = glass_bands_over(40, 15.0, 2.0, 0, &[(0, 300, 8)]);
    assert_eq!((bands.top, bands.bottom), (40, 300));
}