diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/gipfel-core/src/lsq.rs | 41 | ||||
| -rw-r--r-- | crates/gipfel/src/app.rs | 9 |
2 files changed, 46 insertions, 4 deletions
diff --git a/crates/gipfel-core/src/lsq.rs b/crates/gipfel-core/src/lsq.rs index 834fdfe..c501845 100644 --- a/crates/gipfel-core/src/lsq.rs +++ b/crates/gipfel-core/src/lsq.rs @@ -308,10 +308,16 @@ pub fn comp_params( let dx = m2.x - m1.x; let two_pi = 2.0 * std::f64::consts::PI; let mut d_img = crate::projection::wrap_angle(m2.alph - m1.alph); - if dx >= 0.0 && d_img <= 0.0 { - d_img += two_pi; - } else if dx < 0.0 && d_img >= 0.0 { - d_img -= two_pi; + // The wide branch (markers >180 deg apart in the image) only + // applies to projections that can actually show more than a + // half-plane; the rectilinear projection is limited to 120 deg + // of view, so there the shortest arc is always the intended one. + if proj.get_view_angle() >= std::f64::consts::PI { + if dx >= 0.0 && d_img <= 0.0 { + d_img += two_pi; + } else if dx < 0.0 && d_img >= 0.0 { + d_img -= two_pi; + } } let scale_tmp = dx.abs() / d_img.abs(); if scale_tmp.is_nan() || scale_tmp < 50.0 { @@ -558,6 +564,33 @@ mod tests { assert_wide_fit(false, 200.0); } + /// User scenario: fit distant peaks in panorama mode, switch to + /// rectilinear (which refits with tangent-based scale), switch back. + /// Refitting in the cylindrical projection must fully recover the + /// panorama parameters - the fitted parameters of one projection are + /// allowed to be garbage for the other, but must never poison a + /// subsequent refit. + #[test] + fn refit_recovers_after_rectilinear_interlude() { + let (proj, hills, known, truth) = wide_panorama(false, 200.0); + let mut pano = ViewParams::new(); + comp_params(&*proj, &hills, &known, &mut pano, false).unwrap(); + + // reinterpret + refit in rectilinear mode (200 deg exceeds its + // domain, so the outcome is projection-weird but must stay finite) + let rect = projection_from_type(ProjectionType::Rectilinear); + let mut mixed = pano; + let _ = comp_params(&*rect, &hills, &known, &mut mixed, false); + assert!(mixed.a_center.is_finite() && mixed.scale.is_finite()); + + // switch back and refit: panorama parameters must come back + let mut back = mixed; + comp_params(&*proj, &hills, &known, &mut back, false).unwrap(); + let d = crate::projection::wrap_angle(back.a_center - truth.a_center); + assert!(d.abs() < 1e-6, "a_center {}", back.a_center); + assert!((back.scale - truth.scale).abs() < 1.0, "scale {}", back.scale); + } + /// The cylindrical projection formulas do not contain the distortion /// parameters (k0/k1/x0) at all, and its trait derivative defaults are /// NaN - so "fit distortion" must be a no-op in panorama mode: the fit diff --git a/crates/gipfel/src/app.rs b/crates/gipfel/src/app.rs index 2728635..c2a184d 100644 --- a/crates/gipfel/src/app.rs +++ b/crates/gipfel/src/app.rs @@ -925,6 +925,8 @@ pub fn app() -> Html { let pan = pan.clone(); let projection = projection.clone(); let tick = tick.clone(); + let markers = markers.clone(); + let do_refit = do_refit.clone(); Callback::from(move |e: Event| { let sel: web_sys::HtmlSelectElement = e.target_unchecked_into(); let cyl = sel.value() == "1"; @@ -934,6 +936,13 @@ pub fn app() -> Html { } else { ProjectionType::Rectilinear }); + // View parameters are projection-specific (a cylindrical scale + // is linear in azimuth, a rectilinear one is tangent-based), so + // refit to the markers after switching. Without this the old + // projection's parameters get reinterpreted by the new one and + // the next marker drag refits garbage, polluting the shared + // parameters for BOTH projections until another refit saves it. + do_refit(&markers); // The peak coordinates change with the projection (the FOV-limit // sync in the render body rebuilds them), but no CanvasView prop // changes - bump the redraw tick or the canvas keeps showing the |
