Skip to main content

mln_engine/camera/transform/
animation.rs

1//! Animated camera commands: easing and flying to a camera.
2
3use std::f64::consts::PI;
4use std::time::Duration;
5
6use mln_style::geo::{LatLngBounds, WrapMode};
7use mln_style::interpolate::interpolate;
8
9use super::transition::{AlongFn, FrameFn};
10use super::{
11    CameraCommandId, Transform, frame_edge_insets, frame_unproject, lat_lng, nanos_from_secs, normalize_angle,
12};
13use crate::camera::{
14    AnimationOptions, CameraOptions, TransformState, TransitionOutcome, VerticalPerspectiveProjection,
15};
16use crate::geo::EdgeInsets;
17use crate::geo::projection::Projection;
18
19/// An animation frame's padding, `t` of the way from `start` to `end`; `None`
20/// when it has none (see [`frame_edge_insets`]). Insets that don't change are
21/// kept as they are, so that infinite insets don't log on every frame.
22fn interpolate_edge_insets(start: &EdgeInsets, end: &EdgeInsets, t: f64) -> Option<EdgeInsets> {
23    if start == end {
24        return Some(*end);
25    }
26    frame_edge_insets(
27        interpolate(&start.top, &end.top, t),
28        interpolate(&start.left, &end.left, t),
29        interpolate(&start.bottom, &end.bottom, t),
30        interpolate(&start.right, &end.right, t),
31    )
32}
33
34impl Transform {
35    /// Change any combination of center, zoom, bearing, pitch and edgeInsets,
36    /// with a smooth animation between old and new values. Omitted options
37    /// keep their current animations and timing.
38    pub fn ease_to(&mut self, camera: &CameraOptions, animation: &AnimationOptions) -> CameraCommandId {
39        self.command(|transform| transform.ease(camera, animation))
40    }
41
42    pub(super) fn ease(&mut self, input_camera: &CameraOptions, animation: &AnimationOptions) {
43        let mut camera = *input_camera;
44        let globe = self.state.view().is_globe();
45
46        let duration = animation.duration.unwrap_or(Duration::ZERO);
47        if !globe
48            && self.state.limits().bounds == LatLngBounds::default()
49            && !self.is_gesture_in_progress()
50            && duration != Duration::ZERO
51            && animation.easing.is_none()
52        {
53            // A plain timed ease flies without the zoom-out. The flight's
54            // ground speed rises and falls along its path even at a constant
55            // zoom, so an ease given an easing interpolates instead, and
56            // moves as that easing says, as GL JS's easeTo does.
57            self.fly_to(&camera, animation, true);
58            return;
59        }
60
61        let mut zoom = camera.zoom.unwrap_or(self.view().zoom());
62        if camera.zoom.is_none()
63            && let Some(center) = camera.center
64            && globe
65        {
66            zoom += VerticalPerspectiveProjection::zoom_adjustment(
67                self.view().center(WrapMode::Wrapped).latitude(),
68                center.latitude(),
69            );
70        }
71        self.state.constrain_camera_and_zoom_to_bounds(&mut camera, &mut zoom);
72
73        let padding = camera.padding.unwrap_or(self.state.view().padding());
74        let mut start_lat_lng = self.view().center(WrapMode::Unwrapped);
75        let unwrapped_lat_lng = camera.center.unwrap_or(start_lat_lng);
76        // On the globe the ease heads for the center the zoom it was given
77        // allows, or else the zoom it starts from, as GL JS's does; its last
78        // frame is bounded by the zoom it ends on.
79        let lat_lng_end = self.state.constrained_center(
80            &if self.state.limits().bounds == LatLngBounds::default() {
81                unwrapped_lat_lng.wrapped()
82            } else {
83                unwrapped_lat_lng
84            },
85            if camera.zoom.is_some() { zoom } else { self.view().zoom() },
86        );
87
88        let mut bearing = match camera.bearing {
89            Some(b) => mln_style::math::deg2rad(-b),
90            None => self.view().angle(),
91        };
92        let mut pitch = match camera.pitch {
93            Some(p) => mln_style::math::deg2rad(p),
94            None => self.view().pitch(),
95        };
96        let mut fov = match camera.fov {
97            Some(f) => mln_style::math::deg2rad(f),
98            None => self.view().fov(),
99        };
100        let center_alt = camera.center_altitude.unwrap_or(self.state.view().center_altitude());
101        let roll = match camera.roll {
102            Some(r) => mln_style::math::deg2rad(r),
103            None => self.view().roll(),
104        };
105
106        if zoom.is_nan() || bearing.is_nan() || pitch.is_nan() || roll.is_nan() || fov.is_nan() {
107            self.end_unstarted(animation, TransitionOutcome::Cancelled);
108            return;
109        }
110
111        if self.state.limits().bounds == LatLngBounds::default() {
112            if self.is_gesture_in_progress() {
113                // If gesture in progress, we transfer the wrap rounds from the
114                // end longitude into start, so the "scroll effect" of rounding
115                // the world is the same while assuring the end longitude
116                // remains wrapped.
117                let wrap = unwrapped_lat_lng.longitude() - lat_lng_end.longitude();
118                start_lat_lng = lat_lng(start_lat_lng.latitude(), start_lat_lng.longitude() - wrap);
119            } else {
120                // Find the shortest path otherwise.
121                start_lat_lng.unwrap_for_shortest_path(&lat_lng_end);
122            }
123        }
124        let start_center_alt = self.state.view().center_altitude();
125
126        let start_scale = self.state.view().scale();
127        let start_point = Projection::project(&start_lat_lng, start_scale);
128        let end_point = Projection::project(&lat_lng_end, start_scale);
129
130        // Constrain camera options.
131        // The target is drawn in the projection the style gives at its zoom,
132        // which the animation may cross into.
133        let target_globe = match &self.projection_for_zoom {
134            Some(projection_for_zoom) => projection_for_zoom(zoom).transition_state() > 0.0,
135            None => globe,
136        };
137        zoom = mln_style::math::clamp_f64(
138            zoom,
139            self.state.min_zoom_at_latitude_with(lat_lng_end.latitude(), target_globe),
140            self.state.limits().max_zoom,
141        );
142        pitch = mln_style::math::clamp_f64(pitch, self.state.limits().min_pitch, self.state.limits().max_pitch);
143        fov = mln_style::math::clamp_f64(fov, crate::camera::MIN_FIELD_OF_VIEW, crate::camera::MAX_FIELD_OF_VIEW);
144
145        // Minimize rotation by taking the shorter path around the circle.
146        bearing = normalize_angle(bearing, self.state.view().angle());
147
148        let start_zoom = self.state.view().zoom();
149        let start_bearing = normalize_angle(self.state.view().angle(), bearing);
150        let start_pitch = self.state.view().pitch();
151        let start_roll = self.state.view().roll();
152        let start_fov = self.state.view().fov();
153        let start_edge_insets = self.state.view().padding();
154
155        // On the globe the zoom is eased in equator terms so the planet holds
156        // its size as the latitude changes, and the center moves the way GL
157        // JS moves it: longitude paced at 1 / cos(latitude), sped up ahead of
158        // a zoom in.
159        let normalized_start_zoom = if globe {
160            start_zoom + VerticalPerspectiveProjection::zoom_adjustment(start_lat_lng.latitude(), 0.0)
161        } else {
162            start_zoom
163        };
164        let normalized_zoom = if globe {
165            zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0)
166        } else {
167            zoom
168        };
169        let final_scale = crate::camera::zoom_scale(normalized_zoom - normalized_start_zoom);
170        let base = if normalized_zoom > normalized_start_zoom {
171            f64::min(2.0, final_scale)
172        } else {
173            f64::max(0.5, final_scale)
174        };
175        let delta_latitude = if globe {
176            VerticalPerspectiveProjection::difference_of_angles_degrees(
177                start_lat_lng.latitude(),
178                lat_lng_end.latitude(),
179            )
180        } else {
181            0.0
182        };
183        let delta_longitude = if globe {
184            VerticalPerspectiveProjection::difference_of_angles_degrees(
185                start_lat_lng.longitude(),
186                lat_lng_end.longitude(),
187            )
188        } else {
189            0.0
190        };
191        let moves_around_anchor = camera.anchor.is_some() && camera.center.is_none();
192
193        let frame: FrameFn = Box::new(move |state: &TransformState, t: f64| {
194            let (frame_lat_lng, frame_zoom) = if globe {
195                // An anchor moves the center a frame at a time (see
196                // apply_transitions), so it stays, and the zoom follows its
197                // latitude to keep the planet's size.
198                let mut frame_lat_lng =
199                    if moves_around_anchor { state.view().center(WrapMode::Unwrapped) } else { lat_lng_end };
200                let mut frame_zoom = zoom;
201                if moves_around_anchor {
202                    frame_zoom = interpolate(&normalized_start_zoom, &normalized_zoom, t)
203                        + VerticalPerspectiveProjection::zoom_adjustment(0.0, frame_lat_lng.latitude());
204                } else if t < 1.0 {
205                    let factor = t * base.powf(1.0 - t);
206                    frame_lat_lng = VerticalPerspectiveProjection::interpolate_lat_lng(
207                        &start_lat_lng,
208                        delta_latitude,
209                        delta_longitude,
210                        factor,
211                    )
212                    .wrapped();
213                    frame_zoom = if zoom == start_zoom {
214                        start_zoom
215                    } else {
216                        interpolate(&normalized_start_zoom, &normalized_zoom, t)
217                            + VerticalPerspectiveProjection::zoom_adjustment(0.0, frame_lat_lng.latitude())
218                    };
219                }
220                (Some(frame_lat_lng), frame_zoom)
221            } else if t == 1.0 {
222                (Some(lat_lng_end), zoom)
223            } else {
224                let frame_point = interpolate(&start_point, &end_point, t);
225                (frame_unproject(&frame_point, start_scale, WrapMode::Unwrapped), interpolate(&start_zoom, &zoom, t))
226            };
227            CameraOptions {
228                center: frame_lat_lng,
229                zoom: Some(frame_zoom),
230                center_altitude: Some(interpolate(&start_center_alt, &center_alt, t)),
231                bearing: Some(-mln_style::math::rad2deg(mln_style::math::wrap(
232                    interpolate(&start_bearing, &bearing, t),
233                    -PI,
234                    PI,
235                ))),
236                padding: interpolate_edge_insets(&start_edge_insets, &padding, t),
237                pitch: Some(mln_style::math::rad2deg(interpolate(&start_pitch, &pitch, t))),
238                roll: Some(mln_style::math::rad2deg(interpolate(&start_roll, &roll, t))),
239                fov: Some(mln_style::math::rad2deg(interpolate(&start_fov, &fov, t))),
240                ..Default::default()
241            }
242        });
243
244        // On the globe the zoom keeps the planet's size as the center's
245        // latitude changes, and a zoom moves the center when it bounds it
246        // closer to the equator, so an ease that moves the center sets both
247        // (an anchored one gets its center from the anchor).
248        let moves_center = input_camera.center.is_some() || lat_lng_end.wrapped() != start_lat_lng.wrapped();
249        let fields = if globe && moves_around_anchor {
250            CameraOptions { zoom: Some(zoom), ..*input_camera }
251        } else if globe && moves_center {
252            CameraOptions { center: Some(lat_lng_end), zoom: Some(zoom), ..*input_camera }
253        } else {
254            *input_camera
255        };
256        self.start_transition(&fields, animation, frame, None, duration, false);
257    }
258
259    /// This method implements an “optimal path” animation, as detailed in:
260    ///
261    /// Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and
262    /// panning.” INFOVIS ’03. pp. 15–22.
263    /// <https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5>.
264    ///
265    /// Where applicable, local variable documentation begins with the
266    /// associated variable or function in van Wijk (2003).
267    pub(crate) fn fly_to(
268        &mut self,
269        camera: &CameraOptions,
270        animation: &AnimationOptions,
271        linear_zoom_interpolation: bool,
272    ) -> CameraCommandId {
273        self.command(|transform| transform.fly(camera, animation, linear_zoom_interpolation))
274    }
275
276    pub(super) fn fly(
277        &mut self,
278        input_camera: &CameraOptions,
279        animation: &AnimationOptions,
280        linear_zoom_interpolation: bool,
281    ) {
282        let mut camera = *input_camera;
283        let globe = self.state.view().is_globe();
284
285        let mut zoom = camera.zoom.unwrap_or(self.view().zoom());
286        if camera.zoom.is_none()
287            && let Some(center) = camera.center
288            && globe
289        {
290            zoom += VerticalPerspectiveProjection::zoom_adjustment(
291                self.view().center(WrapMode::Wrapped).latitude(),
292                center.latitude(),
293            );
294        }
295        self.state.constrain_camera_and_zoom_to_bounds(&mut camera, &mut zoom);
296
297        let padding = camera.padding.unwrap_or(self.state.view().padding());
298        // As in easeTo, the globe's flight heads for the center the zoom it
299        // was given, or else starts from, allows.
300        let lat_lng_end = self.state.constrained_center(
301            &camera.center.unwrap_or(self.view().center(WrapMode::Unwrapped)).wrapped(),
302            if camera.zoom.is_some() { zoom } else { self.view().zoom() },
303        );
304        let center_alt = camera.center_altitude.unwrap_or(self.state.view().center_altitude());
305        let mut bearing = match camera.bearing {
306            Some(b) => mln_style::math::deg2rad(-b),
307            None => self.view().angle(),
308        };
309        let mut pitch = match camera.pitch {
310            Some(p) => mln_style::math::deg2rad(p),
311            None => self.view().pitch(),
312        };
313        let roll = match camera.roll {
314            Some(r) => mln_style::math::deg2rad(r),
315            None => self.view().roll(),
316        };
317        let mut fov = match camera.fov {
318            Some(f) => mln_style::math::deg2rad(f),
319            None => self.view().fov(),
320        };
321
322        if zoom.is_nan()
323            || bearing.is_nan()
324            || pitch.is_nan()
325            || roll.is_nan()
326            || fov.is_nan()
327            || self.state.view().size().is_empty()
328        {
329            self.end_unstarted(animation, TransitionOutcome::Cancelled);
330            return;
331        }
332
333        // Determine endpoints.
334        let mut start_lat_lng = self.view().center(WrapMode::Unwrapped).wrapped();
335        start_lat_lng.unwrap_for_shortest_path(&lat_lng_end);
336        let start_center_alt = self.state.view().center_altitude();
337
338        let start_point = Projection::project(&start_lat_lng, self.state.view().scale());
339        let end_point = Projection::project(&lat_lng_end, self.state.view().scale());
340
341        // Constrain camera options.
342        // The target is drawn in the projection the style gives at its zoom,
343        // which the animation may cross into.
344        let target_globe = match &self.projection_for_zoom {
345            Some(projection_for_zoom) => projection_for_zoom(zoom).transition_state() > 0.0,
346            None => globe,
347        };
348        zoom = mln_style::math::clamp_f64(
349            zoom,
350            self.state.min_zoom_at_latitude_with(lat_lng_end.latitude(), target_globe),
351            self.state.limits().max_zoom,
352        );
353        pitch = mln_style::math::clamp_f64(pitch, self.state.limits().min_pitch, self.state.limits().max_pitch);
354        fov = mln_style::math::clamp_f64(fov, crate::camera::MIN_FIELD_OF_VIEW, crate::camera::MAX_FIELD_OF_VIEW);
355
356        // Minimize rotation by taking the shorter path around the circle.
357        bearing = normalize_angle(bearing, self.state.view().angle());
358        let start_zoom = crate::camera::scale_zoom(self.state.view().scale());
359        let start_bearing = normalize_angle(self.state.view().angle(), bearing);
360        let start_pitch = self.state.view().pitch();
361        let start_roll = self.state.view().roll();
362        let start_fov = self.state.view().fov();
363
364        // w₀: Initial visible span, measured in pixels at the initial scale.
365        // Known henceforth as a <i>screenful</i>.
366        let size = self.state.view().size();
367        let w0 = f64::max(
368            f64::from(size.width) - padding.left - padding.right,
369            f64::from(size.height) - padding.top - padding.bottom,
370        );
371        // The globe counts zoom in equator terms and distance along the
372        // surface, so the arc is the same at any latitude.
373        let normalized_start_zoom = if globe {
374            start_zoom + VerticalPerspectiveProjection::zoom_adjustment(start_lat_lng.latitude(), 0.0)
375        } else {
376            start_zoom
377        };
378        let normalized_zoom = if globe {
379            zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0)
380        } else {
381            zoom
382        };
383        // w₁: Final visible span, measured in pixels with respect to the
384        // initial scale.
385        let w1 = w0 / crate::camera::zoom_scale(normalized_zoom - normalized_start_zoom);
386        // Length of the flight path as projected onto the ground plane,
387        // measured in pixels from the world image origin at the initial scale.
388        let u1 = if globe {
389            VerticalPerspectiveProjection::surface_distance_pixels(
390                Projection::world_size(self.state.view().scale()),
391                start_lat_lng.latitude(),
392                &start_lat_lng,
393                &lat_lng_end,
394            )
395        } else {
396            (end_point.x - start_point.x).hypot(end_point.y - start_point.y)
397        };
398
399        // ρ: The relative amount of zooming that takes place along the flight
400        // path. A high value maximizes zooming for an exaggerated animation,
401        // while a low value minimizes zooming for something closer to
402        // easeTo().
403        //
404        // 1.42 is the average value selected by participants in the user
405        // study in van Wijk (2003). A value of 6<sup>¼</sup> would be
406        // equivalent to the root mean squared average velocity,
407        // V<sub>RMS</sub>. A value of 1 produces a circular motion.
408        let mut rho = 1.42;
409        if globe {
410            // GL JS: the arc may not dip below the map's or the flight's
411            // minimum zoom, and that only ever lowers ρ.
412            let floor_zoom = f64::max(animation.min_zoom.unwrap_or(self.state.min_zoom()), self.state.min_zoom());
413            let normalized_floor_zoom = f64::min(
414                f64::min(
415                    floor_zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0),
416                    normalized_start_zoom,
417                ),
418                normalized_zoom,
419            );
420            let min_zoom = mln_style::math::clamp_f64(
421                normalized_floor_zoom + VerticalPerspectiveProjection::zoom_adjustment(0.0, lat_lng_end.latitude()),
422                self.state.min_zoom_at_latitude(lat_lng_end.latitude()),
423                self.state.limits().max_zoom,
424            );
425            let w_max = w0
426                / crate::camera::zoom_scale(
427                    min_zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0)
428                        - normalized_start_zoom,
429                );
430            if u1 != 0.0 {
431                rho = f64::min(rho, (w_max / u1 * 2.0).sqrt());
432            }
433        } else if animation.min_zoom.is_some() || linear_zoom_interpolation {
434            // util::min(a, b, c) = min(a, min(b, c)), fmin on doubles
435            let mut min_zoom = mln_style::math::fmin(
436                animation.min_zoom.unwrap_or(start_zoom),
437                mln_style::math::fmin(start_zoom, zoom),
438            );
439            min_zoom = mln_style::math::clamp_f64(
440                min_zoom,
441                self.state.min_zoom_at_latitude(lat_lng_end.latitude()),
442                self.state.limits().max_zoom,
443            );
444            // w<sub>m</sub>: Maximum visible span, measured in pixels with
445            // respect to the initial scale.
446            let w_max = w0 / crate::camera::zoom_scale(min_zoom - start_zoom);
447            rho = if u1 == 0.0 { 1.0 } else { (w_max / u1 * 2.0).sqrt() };
448        }
449        // ρ²
450        let rho2 = rho * rho;
451
452        // rᵢ: Returns the zoom-out factor at one end of the animation.
453        //
454        // @param i 0 for the ascent or 1 for the descent.
455        let r = |i: f64| -> f64 {
456            // bᵢ
457            let b = (w1 * w1 - w0 * w0 + if i == 0.0 { 1.0 } else { -1.0 } * rho2 * rho2 * u1 * u1)
458                / (2.0 * if i == 0.0 { w0 } else { w1 } * rho2 * u1);
459            ((b * b + 1.0).sqrt() - b).ln()
460        };
461
462        // r₀: Zoom-out factor during ascent.
463        let r0 = if u1 == 0.0 { f64::INFINITY } else { r(0.0) }; // Silence division by 0 on sanitize bot.
464        let r1 = if u1 == 0.0 { f64::INFINITY } else { r(1.0) };
465
466        // When u₀ = u₁, the optimal path doesn’t require both ascent and
467        // descent.
468        let is_close = u1.abs() < 0.000_001 || !r0.is_finite() || !r1.is_finite();
469
470        // w(s): Returns the visible span on the ground, measured in pixels
471        // with respect to the initial scale.
472        //
473        // Assumes an angular field of view of 2 arctan ½ ≈ 53°.
474        let w = move |s: f64| -> f64 {
475            if is_close {
476                ((if w1 < w0 { -1.0 } else { 1.0 }) * rho * s).exp()
477            } else {
478                r0.cosh() / (r0 + rho * s).cosh()
479            }
480        };
481        // u(s): Returns the distance along the flight path as projected onto
482        // the ground plane, measured in pixels from the world image origin at
483        // the initial scale.
484        let u = move |s: f64| -> f64 {
485            if is_close { 0.0 } else { w0 * (r0.cosh() * (r0 + rho * s).tanh() - r0.sinh()) / rho2 / u1 }
486        };
487        // S: Total length of the flight path, measured in ρ-screenfuls.
488        let total_s = if is_close { (w1 / w0).ln().abs() / rho } else { (r1 - r0) / rho };
489        // Where the center stays, the share of the time stands in.
490        let along: Option<AlongFn> = if is_close { None } else { Some(Box::new(move |k| u(k * total_s))) };
491
492        let duration = if let Some(duration) = animation.duration {
493            duration
494        } else {
495            // V: Average velocity, measured in ρ-screenfuls per second.
496            let mut velocity = 1.2;
497            if let Some(v) = animation.velocity {
498                velocity = v / rho;
499            }
500            // A duration that a `Duration` can't hold jumps, as one past
501            // max_duration does, rather than saturating to a flight that
502            // never ends.
503            nanos_from_secs(total_s / velocity).unwrap_or_default()
504        };
505        let duration = match animation.max_duration {
506            Some(max) if !linear_zoom_interpolation && duration > max => Duration::ZERO,
507            _ => duration,
508        };
509        let start_scale = self.state.view().scale();
510        let start_edge_insets = self.state.view().padding();
511        let delta_latitude = if globe {
512            VerticalPerspectiveProjection::difference_of_angles_degrees(
513                start_lat_lng.latitude(),
514                lat_lng_end.latitude(),
515            )
516        } else {
517            0.0
518        };
519        let delta_longitude = if globe {
520            VerticalPerspectiveProjection::difference_of_angles_degrees(
521                start_lat_lng.longitude(),
522                lat_lng_end.longitude(),
523            )
524        } else {
525            0.0
526        };
527
528        let frame: FrameFn = Box::new(move |_: &TransformState, k: f64| {
529            // s: The distance traveled along the flight path, measured in
530            // ρ-screenfuls.
531            let s = k * total_s;
532            let us = if k == 1.0 { 1.0 } else { u(s) };
533
534            let (frame_lat_lng, frame_zoom) = if globe {
535                let mut frame_lat_lng = lat_lng_end;
536                let mut frame_zoom = zoom;
537                if k < 1.0 {
538                    frame_lat_lng = VerticalPerspectiveProjection::interpolate_lat_lng(
539                        &start_lat_lng,
540                        delta_latitude,
541                        delta_longitude,
542                        us,
543                    )
544                    .wrapped();
545                    let frame_normalized_zoom = if linear_zoom_interpolation {
546                        interpolate(&normalized_start_zoom, &normalized_zoom, k)
547                    } else {
548                        normalized_start_zoom + crate::camera::scale_zoom(1.0 / w(s))
549                    };
550                    frame_zoom = frame_normalized_zoom
551                        + VerticalPerspectiveProjection::zoom_adjustment(0.0, frame_lat_lng.latitude());
552                    if frame_zoom.is_nan() {
553                        frame_zoom = zoom;
554                    }
555                }
556                (Some(frame_lat_lng), frame_zoom)
557            } else {
558                // Calculate the current point and zoom level along the flight
559                // path.
560                let frame_point = interpolate(&start_point, &end_point, us);
561                let mut frame_zoom = if linear_zoom_interpolation {
562                    interpolate(&start_zoom, &zoom, k)
563                } else {
564                    start_zoom + crate::camera::scale_zoom(1.0 / w(s))
565                };
566
567                // Zoom can be NaN if size is empty.
568                if frame_zoom.is_nan() {
569                    frame_zoom = zoom;
570                }
571
572                // Convert to geographic coordinates and set the new viewpoint.
573                (frame_unproject(&frame_point, start_scale, WrapMode::Unwrapped), frame_zoom)
574            };
575            CameraOptions {
576                center: frame_lat_lng,
577                zoom: Some(frame_zoom),
578                center_altitude: Some(interpolate(&start_center_alt, &center_alt, us)),
579                bearing: Some(-mln_style::math::rad2deg(mln_style::math::wrap(
580                    interpolate(&start_bearing, &bearing, k),
581                    -PI,
582                    PI,
583                ))),
584                padding: interpolate_edge_insets(&start_edge_insets, &padding, k),
585                pitch: Some(mln_style::math::rad2deg(interpolate(&start_pitch, &pitch, k))),
586                roll: Some(mln_style::math::rad2deg(interpolate(&start_roll, &roll, k))),
587                fov: Some(mln_style::math::rad2deg(interpolate(&start_fov, &fov, k))),
588                ..Default::default()
589            }
590        });
591
592        self.start_transition(input_camera, animation, frame, along, duration, !linear_zoom_interpolation);
593    }
594}