mln-rs-engine 0.0.23

Part of mln-rs, a MapLibre map renderer written in Rust. Depend on mln-rs instead.
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
//! Camera deltas: the steps of a gesture, the changes they report, the
//! ground they hold under their anchors, and the deltas refused.

use approx::assert_abs_diff_eq;
use glam::DVec4;
use mln_style::math::deg2rad;

use super::super::flip_y;
use super::*;
use crate::camera::{CameraDelta, CameraError, GesturePhase, MomentumSnap};

fn delta(phase: GesturePhase) -> CameraDelta {
    CameraDelta { phase, ..CameraDelta::default() }
}

#[test]
fn a_gesture_reports_gesture_then_momentum_and_lasts_until_its_glide_ends() {
    use CameraChangeMode::{Animated, Immediate};
    use CameraChangeSource::{Gesture, Momentum};
    let mut transform = sized(1000, 1000);
    transform.jump_to(&CameraOptions { center: Some(ll(0.0, 0.0)), zoom: Some(8.0), ..Default::default() });
    take_changes(&mut transform);

    let pan = |phase| CameraDelta { offset: Some(sc(10.0, 0.0)), ..delta(phase) };
    transform.apply_camera_delta(&pan(GesturePhase::Begin)).unwrap();
    assert!(transform.is_gesture_in_progress());
    transform.apply_camera_delta(&pan(GesturePhase::Update)).unwrap();
    assert_eq!(
        take_changes(&mut transform),
        [
            ('w', moving(Immediate, Gesture, PAN)),
            ('d', moving(Immediate, Gesture, PAN)),
            ('w', moving(Immediate, Gesture, PAN)),
            ('d', moving(Immediate, Gesture, PAN)),
        ]
    );

    let (animation, ended) = record_end();
    transform
        .apply_camera_delta(&CameraDelta {
            momentum: Some(panning(sc(2000.0, 0.0), MomentumDecay::PAN)),
            animation,
            ..delta(GesturePhase::End)
        })
        .unwrap();
    assert_eq!(take_changes(&mut transform), [('w', moving(Animated, Momentum, PAN))]);
    // The gesture's input ended, but it lasts until its momentum does.
    assert!(transform.is_gesture_in_progress());
    transform.update_transitions(None);
    assert_eq!(take_changes(&mut transform), [('d', moving(Animated, Momentum, PAN))]);
    assert_eq!(outcome(&transform, &ended), Some(TransitionOutcome::Completed));
    assert!(!transform.is_gesture_in_progress());
}

#[test]
fn a_gesture_reports_the_parts_it_moves_and_not_the_center_an_anchor_holds() {
    use CameraChangeMode::{Animated, Immediate};
    use CameraChangeSource::{Gesture, Momentum};
    let mut transform = zoom_8();
    take_changes(&mut transform);

    // A pinch that moves, zooms and turns about a point: its pan and its
    // anchored ease, which repeats a pitch it doesn't change.
    transform
        .apply_camera_delta(&CameraDelta {
            offset: Some(sc(10.0, 0.0)),
            scale: Some(2.0),
            bearing: Some(5.0),
            pitch: Some(0.0),
            anchor: Some(sc(300.0, 300.0)),
            ..delta(GesturePhase::Begin)
        })
        .unwrap();
    let zoom_bearing = CameraParts { zoom: true, bearing: true, ..CameraParts::default() };
    assert_eq!(
        take_changes(&mut transform),
        [
            ('w', moving(Immediate, Gesture, PAN)),
            ('d', moving(Immediate, Gesture, PAN)),
            ('w', moving(Immediate, Gesture, zoom_bearing)),
            ('d', moving(Immediate, Gesture, zoom_bearing)),
        ]
    );

    // A zoom about a point alone doesn't pan.
    transform
        .apply_camera_delta(&CameraDelta {
            scale: Some(0.5),
            anchor: Some(sc(300.0, 300.0)),
            ..delta(GesturePhase::Update)
        })
        .unwrap();
    let zoom = CameraParts { zoom: true, ..CameraParts::default() };
    assert_eq!(
        take_changes(&mut transform),
        [('w', moving(Immediate, Gesture, zoom)), ('d', moving(Immediate, Gesture, zoom))]
    );

    // The glide pans and zooms, and the bearing, which the gesture turned,
    // snaps to north.
    let mut momentum = panning(sc(2000.0, 0.0), MomentumDecay::PAN);
    momentum.zoom.glide = Some(glide(1.0, MomentumDecay::ZOOM));
    momentum.bearing.snap = Some(MomentumSnap::BEARING);
    transform.apply_camera_delta(&CameraDelta { momentum: Some(momentum), ..delta(GesturePhase::End) }).unwrap();
    let glide = CameraParts { pan: true, zoom: true, bearing: true, pitch: false };
    assert_eq!(take_changes(&mut transform), [('w', moving(Animated, Momentum, glide))]);
    transform.update_transitions(None);
    assert_eq!(take_changes(&mut transform), [('d', moving(Animated, Momentum, glide))]);

    // A command reports no parts.
    transform.jump_to(&CameraOptions { zoom: Some(9.0), ..Default::default() });
    assert!(take_changes(&mut transform).iter().all(|(_, change)| change.parts.is_empty()));
}

#[test]
fn a_new_gesture_catches_the_last_ones_glide_and_keeps_the_gesture_going() {
    let mut transform = zoom_8();
    let start = start_clock(&mut transform);
    transform.apply_camera_delta(&CameraDelta { offset: Some(sc(10.0, 0.0)), ..delta(GesturePhase::Begin) }).unwrap();
    let (animation, ended) = record_end();
    transform
        .apply_camera_delta(&CameraDelta {
            momentum: Some(panning(sc(2000.0, 0.0), MomentumDecay::PAN)),
            animation,
            ..delta(GesturePhase::End)
        })
        .unwrap();
    transform.update_transitions(Some(start + Duration::from_millis(100)));

    // A press mid-glide: the glide is cancelled, with its speed, and the new
    // gesture is in progress.
    transform.apply_camera_delta(&CameraDelta { offset: Some(sc(1.0, 0.0)), ..delta(GesturePhase::Begin) }).unwrap();
    let end = ended.get(&transform).expect("the glide ended");
    assert_eq!(end.outcome, TransitionOutcome::Cancelled);
    assert!(end.velocity.pan.x > 500.0 && end.velocity.pan.x < 2000.0, "{:?}", end.velocity);
    assert!(transform.is_gesture_in_progress());
    assert!(!transform.in_transition());

    // An earlier gesture's momentum can't end a later gesture: start a glide
    // for the new one, then begin a third gesture with Update, which keeps
    // the glide; the glide's end leaves the third gesture in progress.
    transform
        .apply_camera_delta(&CameraDelta {
            momentum: Some(panning(sc(2000.0, 0.0), MomentumDecay::PAN)),
            ..delta(GesturePhase::End)
        })
        .unwrap();
    transform.apply_camera_delta(&CameraDelta { scale: Some(1.01), ..delta(GesturePhase::Update) }).unwrap();
    assert!(transform.in_transition());
    transform.update_transitions(None);
    assert!(!transform.in_transition());
    assert!(transform.is_gesture_in_progress());
    transform.apply_camera_delta(&delta(GesturePhase::End)).unwrap();
    assert!(!transform.is_gesture_in_progress());
}

#[test]
fn only_the_parts_a_gesture_changed_settle() {
    let mut snaps = CameraMomentum::default();
    snaps.zoom.snap = Some(MomentumSnap::ZOOM);
    snaps.bearing.snap = Some(MomentumSnap { duration: Duration::ZERO, ..MomentumSnap::BEARING });
    snaps.pitch.snap = Some(MomentumSnap::PITCH);
    let settled = |gesture: CameraDelta| {
        let mut transform = zoom_8();
        transform.jump_to(&CameraOptions {
            zoom: Some(8.3),
            bearing: Some(3.0),
            pitch: Some(4.0),
            ..Default::default()
        });
        transform.apply_camera_delta(&CameraDelta { phase: GesturePhase::Begin, ..gesture }).unwrap();
        transform.apply_camera_delta(&CameraDelta { momentum: Some(snaps), ..delta(GesturePhase::End) }).unwrap();
        transform.update_transitions(None);
        (transform.view().zoom(), bearing_degrees(&transform), pitch_degrees(&transform))
    };

    // A pan changes none of them: nothing settles.
    let (zoom, bearing, pitch) = settled(CameraDelta { offset: Some(sc(10.0, 0.0)), ..CameraDelta::default() });
    assert_abs_diff_eq!(zoom, 8.3, epsilon = 1e-9);
    assert_abs_diff_eq!(bearing, 3.0, epsilon = 1e-9);
    assert_abs_diff_eq!(pitch, 4.0, epsilon = 1e-9);

    // A turn settles the bearing alone.
    let (zoom, bearing, pitch) = settled(CameraDelta { bearing: Some(1.0), ..CameraDelta::default() });
    assert_abs_diff_eq!(zoom, 8.3, epsilon = 1e-9);
    assert_abs_diff_eq!(bearing, 0.0, epsilon = 1e-9);
    assert_abs_diff_eq!(pitch, 4.0, epsilon = 1e-9);
}

#[test]
fn an_animated_snap_settles_without_a_clock() {
    let mut transform = zoom_8();
    transform.jump_to(&CameraOptions { bearing: Some(3.0), ..Default::default() });
    transform.apply_camera_delta(&CameraDelta { bearing: Some(1.0), ..delta(GesturePhase::Begin) }).unwrap();
    let mut momentum = CameraMomentum::default();
    momentum.bearing.snap = Some(MomentumSnap::BEARING);
    transform.apply_camera_delta(&CameraDelta { momentum: Some(momentum), ..delta(GesturePhase::End) }).unwrap();
    transform.update_transitions(None);
    assert_abs_diff_eq!(bearing_degrees(&transform), 0.0, epsilon = 1e-9);
    assert!(!transform.in_transition());
}

#[test]
fn a_delta_pans_and_zooms_around_its_anchor_and_ends_once() {
    let mut transform = zoom_8();
    let anchor = sc(800.0, 300.0);
    // The pan applies first and brings this ground under the anchor, which
    // the zoom and turn then hold in place.
    let ground =
        transform.screen_coordinate_to_lat_lng(&sc(anchor.x + 50.0, anchor.y - 20.0), WrapMode::Unwrapped).unwrap();
    let (animation, ended) = record_end();
    transform
        .apply_camera_delta(&CameraDelta {
            offset: Some(sc(-50.0, 20.0)),
            scale: Some(2.0),
            bearing: Some(90.0),
            anchor: Some(anchor),
            animation,
            ..CameraDelta::default()
        })
        .unwrap();
    assert_eq!(outcome(&transform, &ended), Some(TransitionOutcome::Completed));
    assert_abs_diff_eq!(transform.view().zoom(), 9.0, epsilon = 1e-9);
    assert_abs_diff_eq!(bearing_degrees(&transform), 90.0, epsilon = 1e-9);
    let under = transform.lat_lng_to_screen_coordinate(&ground);
    assert_abs_diff_eq!(under.x, anchor.x, epsilon = 1e-6);
    assert_abs_diff_eq!(under.y, anchor.y, epsilon = 1e-6);

    // Animated, both commands end the delta's one command together.
    let (animation, ended) = record_end();
    let start = start_clock(&mut transform);
    transform
        .apply_camera_delta(&CameraDelta {
            offset: Some(sc(10.0, 0.0)),
            scale: Some(2.0),
            animation: AnimationOptions { duration: Some(Duration::from_secs(1)), ..animation },
            ..CameraDelta::default()
        })
        .unwrap();
    transform.update_transitions(Some(start + Duration::from_millis(500)));
    assert_eq!(outcome(&transform, &ended), None);
    transform.update_transitions(Some(start + Duration::from_secs(1)));
    assert_eq!(outcome(&transform, &ended), Some(TransitionOutcome::Completed));
}

#[test]
fn a_turn_around_an_anchor_keeps_the_ground_under_it() {
    let mut transform = zoom_8();
    let anchor = sc(700.0, 200.0);
    let ground = transform.screen_coordinate_to_lat_lng(&anchor, WrapMode::Unwrapped).unwrap();
    transform
        .apply_camera_delta(&CameraDelta { bearing: Some(90.0), anchor: Some(anchor), ..CameraDelta::default() })
        .unwrap();
    assert_abs_diff_eq!(bearing_degrees(&transform), 90.0, epsilon = 1e-9);
    let under = transform.lat_lng_to_screen_coordinate(&ground);
    assert_abs_diff_eq!(under.x, anchor.x, epsilon = 1e-6);
    assert_abs_diff_eq!(under.y, anchor.y, epsilon = 1e-6);
}

// A drag through apply_camera_delta holds the point its anchor names, as
// move_by_with_anchor does. On the globe the planet turns to keep
// the grabbed location under the cursor, which a drag around the view center
// doesn't; on a flat map seen from straight above at sea level every point
// moves alike, so the anchor changes nothing.
#[test]
fn a_drag_delta_holds_its_anchor() {
    let offset = sc(30.0, 12.0);
    let cursor = sc(330.0, 200.0);
    let drag = |transform: &mut Transform, anchor: Option<ScreenCoordinate>| {
        transform.apply_camera_delta(&CameraDelta { offset: Some(offset), anchor, ..CameraDelta::default() }).unwrap();
        transform.view().center(WrapMode::Unwrapped)
    };
    let globe = || square_globe(ll(30.0, 20.0), 1.0);

    let mut held = globe();
    let through_the_delta = drag(&mut held, Some(cursor));
    let mut direct = globe();
    direct.move_by_with_anchor(&offset, Some(cursor), &AnimationOptions::default()).unwrap();
    assert_eq!(through_the_delta, direct.view().center(WrapMode::Unwrapped));
    assert_eq!(held.view().zoom(), direct.view().zoom());
    let around_the_center = drag(&mut globe(), None);
    assert!(
        (through_the_delta.latitude() - around_the_center.latitude()).abs() > 0.1
            || (through_the_delta.longitude() - around_the_center.longitude()).abs() > 0.1,
        "{through_the_delta:?} {around_the_center:?}"
    );

    let flat = || {
        let mut transform = sized(512, 512);
        transform.jump_to(&CameraOptions { center: Some(ll(30.0, 20.0)), zoom: Some(3.0), ..Default::default() });
        transform
    };
    let (anchored, unanchored) = (drag(&mut flat(), Some(cursor)), drag(&mut flat(), None));
    assert_abs_diff_eq!(anchored.latitude(), unanchored.latitude(), epsilon = 1e-9);
    assert_abs_diff_eq!(anchored.longitude(), unanchored.longitude(), epsilon = 1e-9);
}

/// A 800 by 600 flat map at (30, 20), zoom 10, pitched 55 degrees and turned
/// 20, with its center `altitude` meters up, its clock started.
fn pitched_flat_map(altitude: f64) -> (Transform, Instant) {
    let mut transform = sized(800, 600);
    transform.jump_to(&CameraOptions {
        center: Some(ll(30.0, 20.0)),
        zoom: Some(10.0),
        pitch: Some(55.0),
        bearing: Some(20.0),
        center_altitude: Some(altitude),
        ..Default::default()
    });
    let start = start_clock(&mut transform);
    (transform, start)
}

/// How far, in pixels, the flat map's ground at `location` draws from
/// `point` (y down): the flat map's ground is the plane at sea level.
fn off_by(transform: &Transform, location: &LatLng, point: ScreenCoordinate) -> f64 {
    let drawn = transform.lat_lng_to_screen_coordinate(location);
    (drawn.x - point.x).hypot(drawn.y - point.y)
}

/// The flat map's ground under `point` (y down).
fn flat_ground_under(transform: &Transform, point: ScreenCoordinate) -> LatLng {
    transform.screen_coordinate_to_lat_lng(&point, WrapMode::Unwrapped).unwrap()
}

/// Where the transform's projection matrix draws `lat_lng`, `height` meters
/// above sea level (y down).
fn drawn_at(transform: &Transform, lat_lng: &LatLng, height: f64) -> ScreenCoordinate {
    let view = transform.view();
    let point = Projection::project(lat_lng, view.scale());
    let clip = view.projection_matrix() * DVec4::new(point.x, point.y, height, 1.0);
    let size = view.size();
    sc(
        f64::midpoint(clip.x / clip.w, 1.0) * f64::from(size.width),
        (1.0 - clip.y / clip.w) / 2.0 * f64::from(size.height),
    )
}

/// Where the sky starts on the screen of a flat map that isn't rolled (y
/// down): above it, a line of sight doesn't descend to the ground.
fn horizon_row(transform: &Transform) -> f64 {
    let view = transform.view();
    view.padding().center_in(view.size()).y - view.mercator_horizon()
}

// Within about a pixel: the eye can't tell a grabbed point from the pointer
// at that distance.
const ABOUT_A_PIXEL: f64 = 1.0;

/// On a pitched flat map, a drag keeps the ground it grabbed under the
/// pointer, wherever on the screen the pointer is, near the bottom edge
/// too, and its center 800 m up moves it no differently.
#[test]
fn a_drag_on_a_pitched_flat_map_keeps_the_grabbed_ground_under_the_pointer() {
    for altitude in [0.0, 800.0] {
        let (mut transform, _) = pitched_flat_map(altitude);
        let mut pointer = sc(600.0, 520.0);
        let grabbed = flat_ground_under(&transform, pointer);
        for step in 0..20 {
            let offset = sc(-6.0, -12.0);
            pointer = sc(pointer.x + offset.x, pointer.y + offset.y);
            let phase = if step == 0 { GesturePhase::Begin } else { GesturePhase::Update };
            transform
                .apply_camera_delta(&CameraDelta {
                    offset: Some(offset),
                    anchor: Some(pointer),
                    phase,
                    ..CameraDelta::default()
                })
                .unwrap();
            let off = off_by(&transform, &grabbed, pointer);
            assert!(off < ABOUT_A_PIXEL, "{altitude} m, step {step}: the grabbed ground is {off} px off");
        }
        assert_eq!(altitude, transform.view().center_altitude(), "the drag keeps the altitude");
    }
}

/// The first pan of a pitched flat map whose center stands 800 m up moves
/// the ground at the view's center by the pan, as at sea level, without a
/// jump of the altitude times the tangent of the pitch.
#[test]
fn the_first_pan_of_a_raised_flat_map_does_not_jump() {
    let (mut transform, _) = pitched_flat_map(800.0);
    let center = sc(400.0, 300.0);
    let offset = sc(0.0, 2.0);
    let moving = transform
        .screen_coordinate_to_lat_lng_at(&sc(center.x - offset.x, center.y - offset.y), 800.0, WrapMode::Unwrapped)
        .unwrap();
    transform.move_by(&offset, &AnimationOptions::default()).unwrap();
    let drawn = drawn_at(&transform, &moving, 800.0);
    let off = (drawn.x - center.x).hypot(drawn.y - center.y);
    assert!(off < ABOUT_A_PIXEL, "the ground at the center is {off} px off");
}

/// On a pitched flat map 800 m up, a pinch's zoom and turn, an anchored
/// ease, and the momentum that carries a pinch on hold the ground under
/// their anchors, at sea level, within about a pixel at each step and frame.
#[test]
fn anchored_moves_on_a_raised_pitched_flat_map_hold_their_ground() {
    let anchor = sc(600.0, 450.0);
    let (mut transform, start) = pitched_flat_map(800.0);
    let grabbed = flat_ground_under(&transform, anchor);
    for (step, delta) in [
        CameraDelta { scale: Some(1.3), bearing: Some(-12.0), phase: GesturePhase::Begin, ..CameraDelta::default() },
        CameraDelta { scale: Some(0.8), pitch: Some(5.0), phase: GesturePhase::Update, ..CameraDelta::default() },
    ]
    .into_iter()
    .enumerate()
    {
        transform.apply_camera_delta(&CameraDelta { anchor: Some(anchor), ..delta }).unwrap();
        let off = off_by(&transform, &grabbed, anchor);
        assert!(off < ABOUT_A_PIXEL, "pinch step {step}: the ground is {off} px off");
    }

    let mut momentum = CameraMomentum::default();
    momentum.zoom.glide = Some(glide(1.5, MomentumDecay::DEFAULT));
    momentum.zoom.anchor = Some(anchor);
    momentum.bearing.glide = Some(glide(40.0, MomentumDecay::DEFAULT));
    momentum.bearing.anchor = Some(anchor);
    transform
        .apply_camera_delta(&CameraDelta {
            momentum: Some(momentum),
            phase: GesturePhase::End,
            ..CameraDelta::default()
        })
        .unwrap();
    for ms in (16..2000).step_by(16) {
        transform.update_transitions(Some(start + Duration::from_millis(ms)));
        let off = off_by(&transform, &grabbed, anchor);
        assert!(off < ABOUT_A_PIXEL, "{ms} ms of momentum: the ground is {off} px off");
    }
    assert!(!transform.in_transition());

    let (mut transform, start) = pitched_flat_map(800.0);
    let grabbed = flat_ground_under(&transform, anchor);
    transform.ease_to(
        &CameraOptions {
            zoom: Some(11.5),
            bearing: Some(-30.0),
            pitch: Some(40.0),
            center_altitude: Some(1000.0),
            anchor: Some(anchor),
            ..Default::default()
        },
        &AnimationOptions { duration: Some(Duration::from_millis(500)), ..Default::default() },
    );
    for ms in (16..=512).step_by(16) {
        transform.update_transitions(Some(start + Duration::from_millis(ms)));
        let off = off_by(&transform, &grabbed, anchor);
        assert!(off < ABOUT_A_PIXEL, "{ms} ms of the ease: the ground is {off} px off");
    }
    let camera = transform.camera_options(None);
    assert_eq!((Some(11.5), Some(1000.0)), (camera.zoom, camera.center_altitude), "the ease ends where it asked");
}

/// An 800 by 600 map under `projection` at (45, 7), zoom 13, pitched 60
/// degrees, with its center `altitude` meters up.
fn raised_at_zoom_13(projection: &str, altitude: f64) -> Transform {
    let mut transform = sized(800, 600);
    transform.set_projection(ProjectionDefinition::from_name(projection).into());
    transform.jump_to(&CameraOptions {
        center: Some(ll(45.0, 7.0)),
        zoom: Some(13.0),
        pitch: Some(60.0),
        center_altitude: Some(altitude),
        ..Default::default()
    });
    transform
}

/// A pan without an anchor on a pitched globe whose center stands 3000 m up
/// moves the center as far down the screen as Mercator's pan at the same
/// camera does.
#[test]
fn a_pan_of_a_raised_globe_moves_the_center_as_far_as_on_mercator() {
    let pan = |projection: &str| {
        let mut transform = raised_at_zoom_13(projection, 3000.0);
        let center = transform.view().center(WrapMode::Unwrapped);
        transform.move_by(&sc(0.0, 50.0), &AnimationOptions::default()).unwrap();
        let view = transform.view();
        flip_y(view, &view.lat_lng_to_screen_coordinate_at(&center, 3000.0))
    };
    let (globe, mercator) = (pan("vertical-perspective"), pan("mercator"));
    let off = (globe.x - mercator.x).hypot(globe.y - mercator.y);
    assert!(off < ABOUT_A_PIXEL, "the globe's center lands at {globe:?}, Mercator's at {mercator:?}");
}

/// On a pitched globe, a drag keeps the ground it grabbed, at sea level,
/// under the pointer, and its center 3000 m up moves it no differently.
#[test]
fn a_drag_on_a_raised_globe_keeps_the_grabbed_ground_under_the_pointer() {
    for altitude in [0.0, 3000.0] {
        let mut transform = raised_at_zoom_13("vertical-perspective", altitude);
        let mut pointer = sc(600.0, 520.0);
        let grabbed = flat_ground_under(&transform, pointer);
        for step in 0..20 {
            let offset = sc(-6.0, -12.0);
            pointer = sc(pointer.x + offset.x, pointer.y + offset.y);
            let phase = if step == 0 { GesturePhase::Begin } else { GesturePhase::Update };
            transform
                .apply_camera_delta(&CameraDelta {
                    offset: Some(offset),
                    anchor: Some(pointer),
                    phase,
                    ..CameraDelta::default()
                })
                .unwrap();
            let off = off_by(&transform, &grabbed, pointer);
            assert!(off < ABOUT_A_PIXEL, "{altitude} m, step {step}: the grabbed ground is {off} px off");
        }
    }
}

/// On a map seen from straight above at sea level, a drag pans by its offset
/// at the view's center, and a pinch's zoom and turn hold the location under
/// the anchor, as the state's own conversions put them.
#[test]
fn from_straight_above_at_sea_level_gestures_move_as_the_state_converts() {
    let flipped = |point: ScreenCoordinate| sc(point.x, 600.0 - point.y);
    let mut transform = sized(800, 600);
    transform.jump_to(&CameraOptions {
        center: Some(ll(30.0, 20.0)),
        zoom: Some(10.0),
        bearing: Some(20.0),
        ..Default::default()
    });
    let anchor = sc(500.0, 400.0);

    let mut expected = transform.state().clone();
    let offset = sc(12.0, -30.0);
    transform
        .apply_camera_delta(&CameraDelta {
            offset: Some(offset),
            anchor: Some(anchor),
            phase: GesturePhase::Begin,
            ..CameraDelta::default()
        })
        .unwrap();
    let center = expected
        .view()
        .screen_coordinate_to_lat_lng(&flipped(sc(400.0 - offset.x, 300.0 - offset.y)), WrapMode::Unwrapped)
        .unwrap();
    expected.set_lat_lng_zoom(&center, 10.0);
    let (actual, expected_center) =
        (transform.view().center(WrapMode::Unwrapped), expected.view().center(WrapMode::Unwrapped));
    assert_abs_diff_eq!(expected_center.latitude(), actual.latitude(), epsilon = 1e-9);
    assert_abs_diff_eq!(expected_center.longitude(), actual.longitude(), epsilon = 1e-9);

    let mut expected = transform.state().clone();
    let before = transform.camera_options(None);
    let location = expected.view().screen_coordinate_to_lat_lng(&flipped(anchor), WrapMode::Unwrapped).unwrap();
    transform
        .apply_camera_delta(&CameraDelta {
            scale: Some(1.3),
            bearing: Some(-12.0),
            anchor: Some(anchor),
            phase: GesturePhase::Update,
            ..CameraDelta::default()
        })
        .unwrap();
    expected.set_angle(deg2rad(-(before.bearing.unwrap() - 12.0)));
    expected.set_lat_lng_zoom(&before.center.unwrap(), before.zoom.unwrap() + 1.3f64.log2());
    expected.move_lat_lng(&location, &flipped(anchor)).unwrap();
    let (expected, actual) = (expected.camera_options(None), transform.camera_options(None));
    assert_eq!((expected.zoom, expected.bearing), (actual.zoom, actual.bearing), "the pinch");
    let (expected, actual) = (expected.center.unwrap(), actual.center.unwrap());
    assert_abs_diff_eq!(expected.latitude(), actual.latitude(), epsilon = 1e-9);
    assert_abs_diff_eq!(expected.longitude(), actual.longitude(), epsilon = 1e-9);
}

/// A tilt around a point just below the horizon of a flat map, which
/// carries it above the horizon, turns the camera around the view's center
/// instead, as a tilt without an anchor does: a gesture's step, and the
/// frames of a command once they carry it there.
#[test]
fn a_tilt_that_carries_its_anchor_into_the_sky_turns_around_the_center() {
    let flat_map = |pitch: f64| {
        let mut transform = new_transform();
        limit(&mut transform, |limits| limits.max_pitch = deg2rad(85.0)).unwrap();
        transform.resize(Size::new(800, 600)).unwrap();
        transform.jump_to(&CameraOptions {
            center: Some(ll(30.0, 20.0)),
            zoom: Some(12.0),
            pitch: Some(pitch),
            ..Default::default()
        });
        transform
    };
    let tilt = |anchored: bool| {
        let mut transform = flat_map(70.0);
        let anchor = sc(330.0, horizon_row(&transform) + 10.0);
        let delta = CameraDelta {
            pitch: Some(10.0),
            anchor: anchored.then_some(anchor),
            phase: GesturePhase::Begin,
            ..Default::default()
        };
        transform.apply_camera_delta(&delta).unwrap();
        assert!(anchor.y < horizon_row(&transform), "the tilt carries the anchor into the sky");
        transform.camera_options(None)
    };
    assert_eq!(tilt(false), tilt(true), "a gesture's tilt");

    let mut transform = flat_map(60.0);
    let start = start_clock(&mut transform);
    let anchor = sc(330.0, horizon_row(&transform) + 150.0);
    let grabbed = flat_ground_under(&transform, anchor);
    transform.ease_to(
        &CameraOptions { pitch: Some(85.0), anchor: Some(anchor), ..Default::default() },
        &AnimationOptions { duration: Some(Duration::from_secs(1)), ..Default::default() },
    );
    let (mut held, mut skyward) = (0, 0);
    let mut center = transform.view().center(WrapMode::Unwrapped);
    for ms in (16..=1008).step_by(16) {
        transform.update_transitions(Some(start + Duration::from_millis(ms)));
        let now = transform.view().center(WrapMode::Unwrapped);
        if skyward > 0 || anchor.y < horizon_row(&transform) {
            skyward += 1;
            // Recomputed each frame, so equal only to rounding.
            let moved = (now.latitude() - center.latitude()).abs().max((now.longitude() - center.longitude()).abs());
            assert!(moved < 1e-9, "{ms} ms: the anchor reached the sky, and the center moved {moved}°");
        } else {
            held += 1;
            let off = off_by(&transform, &grabbed, anchor);
            assert!(off < 1e-6, "{ms} ms: the ground is {off} px off");
        }
        center = now;
    }
    assert!(held > 5 && skyward > 5, "{held} frames held the anchor, and {skyward} didn't");
}

/// Under a roll, where the horizon isn't a row of the screen, a turn around
/// a point whose line of sight doesn't descend to the ground turns around
/// the view's center, as a turn without an anchor does, and a turn around a
/// point on the ground holds that ground under it.
#[test]
fn a_turn_under_a_roll_holds_only_a_point_on_the_ground() {
    let rolled = || {
        let mut transform = new_transform();
        limit(&mut transform, |limits| limits.max_pitch = deg2rad(85.0)).unwrap();
        transform.resize(Size::new(512, 512)).unwrap();
        transform.jump_to(&CameraOptions {
            center: Some(ll(30.0, 20.0)),
            zoom: Some(12.0),
            pitch: Some(80.0),
            roll: Some(90.0),
            ..Default::default()
        });
        transform
    };
    let turn = |anchor: Option<ScreenCoordinate>| {
        let mut transform = rolled();
        let delta = CameraDelta { bearing: Some(15.0), anchor, phase: GesturePhase::Begin, ..Default::default() };
        transform.apply_camera_delta(&delta).unwrap();
        transform
    };
    let transform = rolled();
    let view = transform.view();
    let descends = |point: ScreenCoordinate| {
        let (near, far) = view.line_of_sight(&sc(point.x, 512.0 - point.y)).unwrap();
        far.z < near.z
    };
    // The roll puts the sky on one side of the screen and the ground on the
    // other.
    let (left, right) = (sc(20.0, 480.0), sc(492.0, 480.0));
    let (sky, ground) = if descends(left) { (right, left) } else { (left, right) };
    assert!(!descends(sky) && descends(ground), "the roll turns the horizon upright");
    assert!(sky.y > horizon_row(&transform), "below the row of the unrolled horizon");

    assert_eq!(turn(None).camera_options(None), turn(Some(sky)).camera_options(None), "a turn around the sky");

    let grabbed = flat_ground_under(&transform, ground);
    let off = off_by(&turn(Some(ground)), &grabbed, ground);
    assert!(off < 0.01, "the ground moved {off} px from the anchor");
}

/// A drag whose pointer comes back below the horizon after a step above it
/// grabs no ground on its way back: it moves the map on the plane at the
/// center's altitude, as a drag without an anchor does, rather than solving
/// for a point in the sky.
#[test]
fn a_drag_back_from_the_sky_pans_on_the_center_plane() {
    let pan = |anchored: bool| {
        let mut transform = new_transform();
        limit(&mut transform, |limits| limits.max_pitch = deg2rad(85.0)).unwrap();
        transform.resize(Size::new(800, 600)).unwrap();
        transform.jump_to(&CameraOptions {
            center: Some(ll(30.0, 20.0)),
            zoom: Some(12.0),
            pitch: Some(75.0),
            ..Default::default()
        });
        let below = sc(330.0, horizon_row(&transform) + 15.0);
        let offset = sc(0.0, -30.0);
        // Up across the horizon, then back.
        let steps = [(offset, sc(below.x, below.y + offset.y)), (sc(0.0, -offset.y), below)];
        for (step, (offset, pointer)) in steps.into_iter().enumerate() {
            let phase = if step == 0 { GesturePhase::Begin } else { GesturePhase::Update };
            let delta =
                CameraDelta { offset: Some(offset), anchor: anchored.then_some(pointer), phase, ..Default::default() };
            transform.apply_camera_delta(&delta).unwrap();
        }
        transform.camera_options(None)
    };
    assert_eq!(pan(false), pan(true));
}

/// At 85° pitch, dragging in the foreground holds the grabbed ground 1:1 under
/// the pointer, vertical and horizontal ground speed stay bounded all the way
/// into the sky, crossing the horizon has no speed discontinuity, off-center
/// vertical drags in the sky don't drift sideways, and dragging across the
/// horizon and back returns to the start.
#[test]
fn a_drag_at_extreme_pitch_stays_bounded_and_continuous_across_the_horizon() {
    let setup = || {
        let mut transform = new_transform();
        limit(&mut transform, |limits| limits.max_pitch = deg2rad(85.0)).unwrap();
        transform.resize(Size::new(800, 600)).unwrap();
        transform.jump_to(&CameraOptions {
            center: Some(ll(30.0, 20.0)),
            zoom: Some(12.0),
            pitch: Some(85.0),
            ..Default::default()
        });
        transform
    };
    let world_px = |transform: &Transform| {
        let view = transform.view();
        view.world().project(&view.center(WrapMode::Unwrapped), view.scale())
    };
    let step_ground_px = |from: ScreenCoordinate, offset: ScreenCoordinate| {
        let mut transform = setup();
        let before = world_px(&transform);
        let to = sc(from.x + offset.x, from.y + offset.y);
        transform
            .apply_camera_delta(&CameraDelta {
                offset: Some(offset),
                anchor: Some(to),
                phase: GesturePhase::Begin,
                ..Default::default()
            })
            .unwrap();
        let after = world_px(&transform);
        (after.x - before.x, after.y - before.y)
    };

    // Foreground dragging still pins the grabbed ground 1:1 under the pointer.
    let mut fg = setup();
    let mut pointer = sc(520.0, 520.0);
    let grabbed = flat_ground_under(&fg, pointer);
    for step in 0..10 {
        let offset = sc(-6.0, -8.0);
        pointer = sc(pointer.x + offset.x, pointer.y + offset.y);
        let phase = if step == 0 { GesturePhase::Begin } else { GesturePhase::Update };
        fg.apply_camera_delta(&CameraDelta {
            offset: Some(offset),
            anchor: Some(pointer),
            phase,
            ..Default::default()
        })
        .unwrap();
        let off = off_by(&fg, &grabbed, pointer);
        assert!(off < 0.01, "foreground step {step}: grabbed ground is {off} px off");
    }

    // Sweeping 1 px vertical and horizontal drags from foreground through the
    // horizon into the sky stays bounded and has no jump across the horizon.
    let horizon = horizon_row(&setup());
    let mut prev_vy: Option<f64> = None;
    let mut prev_hx: Option<f64> = None;
    for y in (40..=560).step_by(4) {
        let y = f64::from(y);
        let (vdx, vdy) = step_ground_px(sc(400.0, y), sc(0.0, -1.0));
        assert_abs_diff_eq!(vdx, 0.0, epsilon = 1e-6);
        assert!(vdy > 0.0 && vdy <= 3.01, "y={y}: vertical gain {vdy} out of bounds");
        if let Some(prev) = prev_vy {
            assert!((vdy - prev).abs() < 0.35, "y={y}: vertical gain jumped from {prev} to {vdy}");
        }
        prev_vy = Some(vdy);

        let (hdx, hdy) = step_ground_px(sc(400.0, y), sc(1.0, 0.0));
        assert_abs_diff_eq!(hdy, 0.0, epsilon = 1e-6);
        let hgain = -hdx;
        assert!(hgain > 0.0 && hgain <= 2.01, "y={y}: horizontal gain {hgain} out of bounds");
        if let Some(prev) = prev_hx {
            assert!((hgain - prev).abs() < 0.35, "y={y}: horizontal gain jumped from {prev} to {hgain}");
        }
        prev_hx = Some(hgain);
    }

    // Directly straddling the horizon: 1 px above and 1 px below move at the same speed.
    let (_, below_v) = step_ground_px(sc(400.0, horizon + 2.0), sc(0.0, -1.0));
    let (_, above_v) = step_ground_px(sc(400.0, horizon - 2.0), sc(0.0, -1.0));
    assert_abs_diff_eq!(below_v, above_v, epsilon = 1e-6);
    let (below_h, _) = step_ground_px(sc(400.0, horizon + 2.0), sc(1.0, 0.0));
    let (above_h, _) = step_ground_px(sc(400.0, horizon - 2.0), sc(1.0, 0.0));
    assert_abs_diff_eq!(below_h, above_h, epsilon = 1e-6);

    // Horizontal drag at screen center stays 1:1 even at 85° pitch.
    let (center_hdx, center_hdy) = step_ground_px(sc(400.0, 300.0), sc(10.0, 0.0));
    assert_abs_diff_eq!(-center_hdx, 10.0, epsilon = 1e-3);
    assert_abs_diff_eq!(center_hdy, 0.0, epsilon = 1e-6);

    // Off-center vertical drag in the sky has no sideways drift.
    let (sky_dx, sky_dy) = step_ground_px(sc(700.0, horizon - 60.0), sc(0.0, -20.0));
    assert_abs_diff_eq!(sky_dx, 0.0, epsilon = 1e-6);
    assert_abs_diff_eq!(sky_dy, 60.0, epsilon = 1e-6);

    // Dragging across the horizon and right back returns to the starting center.
    let mut roundtrip = setup();
    let start = world_px(&roundtrip);
    let mut pos = sc(620.0, 480.0);
    let step = sc(-4.0, -16.0);
    for i in 0..25 {
        pos = sc(pos.x + step.x, pos.y + step.y);
        roundtrip
            .apply_camera_delta(&CameraDelta {
                offset: Some(step),
                anchor: Some(pos),
                phase: if i == 0 { GesturePhase::Begin } else { GesturePhase::Update },
                ..Default::default()
            })
            .unwrap();
    }
    assert!(pos.y < horizon - 50.0, "crossed well into the sky");
    let back = sc(-step.x, -step.y);
    for _ in 0..25 {
        pos = sc(pos.x + back.x, pos.y + back.y);
        roundtrip
            .apply_camera_delta(&CameraDelta {
                offset: Some(back),
                anchor: Some(pos),
                phase: GesturePhase::Update,
                ..Default::default()
            })
            .unwrap();
    }
    let end = world_px(&roundtrip);
    assert_abs_diff_eq!(start.x, end.x, epsilon = 1e-6);
    assert_abs_diff_eq!(start.y, end.y, epsilon = 1e-6);
}

/// High-pitch panning respects bearing, roll, padding, and center altitude:
/// foreground drags stay 1:1 under the pointer, and sky drags move in the
/// camera's rolled screen direction at the capped speed.
#[test]
fn high_pitch_pan_respects_bearing_roll_padding_and_altitude() {
    for (bearing, roll, padding, altitude) in [
        (0.0, 0.0, EdgeInsets::default(), 0.0),
        (90.0, 0.0, EdgeInsets::default(), 0.0),
        (-135.0, 0.0, EdgeInsets::new(120.0, 40.0, 20.0, 80.0), 0.0),
        (35.0, 90.0, EdgeInsets::default(), 0.0),
        (25.0, -30.0, EdgeInsets::new(60.0, 30.0, 10.0, 50.0), 600.0),
    ] {
        let mut transform = new_transform();
        limit(&mut transform, |limits| limits.max_pitch = deg2rad(85.0)).unwrap();
        transform.resize(Size::new(800, 600)).unwrap();
        transform.jump_to(&CameraOptions {
            center: Some(ll(30.0, 20.0)),
            zoom: Some(12.0),
            bearing: Some(bearing),
            pitch: Some(85.0),
            roll: Some(roll),
            padding: Some(padding),
            center_altitude: Some(altitude),
            ..Default::default()
        });
        let view = transform.view();
        let center = view.padding().center_in(view.size());
        // Screen direction pointing down into the foreground under `roll`.
        let (sin_r, cos_r) = deg2rad(roll).sin_cos();
        // Unrolled (u=0, v=-1) maps to screen (sx = sin_r, sy = -cos_r), so in
        // y-down screen coordinates: (dx = sin_r, dy = cos_r).
        let fg_start = sc(center.x + 180.0 * sin_r, center.y + 180.0 * cos_r);
        let fg_offset = sc(5.0 * cos_r - 5.0 * sin_r, -5.0 * sin_r - 5.0 * cos_r);
        let fg_to = sc(fg_start.x + fg_offset.x, fg_start.y + fg_offset.y);
        let grabbed = flat_ground_under(&transform, fg_start);
        transform
            .apply_camera_delta(&CameraDelta {
                offset: Some(fg_offset),
                anchor: Some(fg_to),
                phase: GesturePhase::Begin,
                ..Default::default()
            })
            .unwrap();
        let off = off_by(&transform, &grabbed, fg_to);
        assert!(off < 0.05, "bearing={bearing}, roll={roll}, altitude={altitude}: foreground drag is {off} px off");

        // Now drag purely toward the sky along the rolled horizon normal, well
        // into the sky: should move 3x ground pixels strictly along the
        // camera's ground-forward axis with zero sideways drift.
        let sky_from = sc(center.x - 160.0 * sin_r, center.y - 160.0 * cos_r);
        let sky_offset = sc(-10.0 * sin_r, -10.0 * cos_r);
        let sky_to = sc(sky_from.x + sky_offset.x, sky_from.y + sky_offset.y);
        let before =
            transform.view().world().project(&transform.view().center(WrapMode::Unwrapped), transform.view().scale());
        transform
            .apply_camera_delta(&CameraDelta {
                offset: Some(sky_offset),
                anchor: Some(sky_to),
                phase: GesturePhase::Begin,
                ..Default::default()
            })
            .unwrap();
        let after =
            transform.view().world().project(&transform.view().center(WrapMode::Unwrapped), transform.view().scale());
        let (dx, dy) = (after.x - before.x, after.y - before.y);
        let (sin_a, cos_a) = transform.view().angle().sin_cos();
        // Expected world shift for `dy_ground = +30`, `dx_ground = 0`.
        assert_abs_diff_eq!(dx, 30.0 * sin_a, epsilon = 1e-4);
        assert_abs_diff_eq!(dy, 30.0 * cos_a, epsilon = 1e-4);
    }
}

#[test]
fn invalid_camera_deltas_are_refused() {
    let mut transform = zoom_8();
    let mut check = |delta: CameraDelta| transform.apply_camera_delta(&delta);
    assert_eq!(
        check(CameraDelta { offset: Some(sc(f64::NAN, 0.0)), ..CameraDelta::default() }),
        Err(CameraError::NotFinite)
    );
    assert_eq!(check(CameraDelta { scale: Some(0.0), ..CameraDelta::default() }), Err(CameraError::InvalidScale));
    assert_eq!(
        check(CameraDelta { bearing: Some(f64::INFINITY), ..CameraDelta::default() }),
        Err(CameraError::NotFinite)
    );
    // An anchor with only an offset is the point a drag holds; one with
    // nothing to hold is rejected.
    assert_eq!(
        check(CameraDelta { anchor: Some(sc(1.0, 1.0)), ..CameraDelta::default() }),
        Err(CameraError::AnchorWithoutChange)
    );
    assert_eq!(
        check(CameraDelta { momentum: Some(CameraMomentum::default()), ..delta(GesturePhase::Update) }),
        Err(CameraError::MomentumOutsideEnd)
    );
    assert_eq!(
        check(CameraDelta {
            momentum: Some(CameraMomentum::default()),
            animation: AnimationOptions::new(Duration::from_secs(1)),
            ..delta(GesturePhase::End)
        }),
        Err(CameraError::MomentumWithAnimation)
    );
    assert_eq!(
        check(CameraDelta {
            offset: Some(sc(1.0, 0.0)),
            scale: Some(2.0),
            anchor: Some(sc(1.0, 1.0)),
            animation: AnimationOptions::new(Duration::from_secs(1)),
            ..CameraDelta::default()
        }),
        Err(CameraError::AnimatedAnchoredOffset)
    );
    // A rejected delta changes nothing; an empty one ends at once.
    assert_abs_diff_eq!(transform.view().zoom(), 8.0, epsilon = 1e-9);
    let (animation, ended) = record_end();
    transform.apply_camera_delta(&CameraDelta { animation, ..CameraDelta::default() }).unwrap();
    assert_eq!(outcome(&transform, &ended), Some(TransitionOutcome::Completed));
}