diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/gipfel-core/src/lsq.rs | 66 | ||||
| -rw-r--r-- | crates/gipfel/src/app.rs | 8 | ||||
| -rw-r--r-- | crates/gipfel/www/style.css | 11 |
3 files changed, 83 insertions, 2 deletions
diff --git a/crates/gipfel-core/src/lsq.rs b/crates/gipfel-core/src/lsq.rs index f85e0ef..834fdfe 100644 --- a/crates/gipfel-core/src/lsq.rs +++ b/crates/gipfel-core/src/lsq.rs @@ -325,7 +325,20 @@ pub fn comp_params( new_parms.a_center = crate::projection::wrap_angle(m1.alph + d_img / 2.0); } - if n > 3 && fit_distortion { + // Capability probe: the cylindrical projection has no distortion terms + // (its derivative trait defaults return NaN), so a distortion fit there + // is impossible - and the calibration reset below would silently zero + // distortion parameters a rectilinear fit had established. + let supports_distortion = { + let probe = crate::projection::ProjArgs::from_params( + &new_parms, + hills[known[0]].alph, + hills[known[0]].a_elev, + ); + proj.mac_x_dk0(probe).is_finite() + }; + + if n > 3 && fit_distortion && supports_distortion { new_parms.k0 = 0.0; new_parms.k1 = 0.0; new_parms.x0 = 0.0; @@ -334,7 +347,7 @@ pub fn comp_params( let level = if n == 1 { 0 } else { 1 }; lsq(proj, hills, known, &mut new_parms, level); - if n >= 4 && fit_distortion { + if n >= 4 && fit_distortion && supports_distortion { lsq(proj, hills, known, &mut new_parms, 2); } @@ -544,4 +557,53 @@ mod tests { fn fit_wide_panorama_just_over_half_circle() { assert_wide_fit(false, 200.0); } + + /// 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 + /// still succeeds and the distortion params stay exactly where they + /// were. This is what the web app relies on when it greys out the + /// distortion controls in cylindrical mode. + #[test] + fn distortion_fit_is_a_noop_for_cylindrical() { + let proj = projection_from_type(ProjectionType::Cylindrical); + let truth = ViewParams { + a_center: 0.3, + scale: 2000.0, + a_pitch: 0.05, + a_roll: 0.0, + k0: 0.0, + k1: 0.0, + x0: 0.0, + }; + let mut hills = Vec::new(); + let mut known = Vec::new(); + for i in 0..5 { + let mut h = Hill::new(&format!("c{i}"), 0.0, 0.0, 2000.0); + h.alph = 0.15 + i as f64 * 0.07; + h.a_elev = 0.02 + i as f64 * 0.015; + let (x, y) = proj.get_coordinates(h.alph, h.a_elev, &truth); + h.x = x; + h.y = y; + hills.push(h); + known.push(i); + } + // start slightly off, with nonzero distortion params that must + // survive untouched + let mut p = truth; + p.a_center -= 0.01; + p.scale *= 1.02; + p.k0 = -0.001; + p.k1 = 1e-5; + p.x0 = 3.0; + comp_params(&*proj, &hills, &known, &mut p, true).unwrap(); + assert!( + (p.a_center - truth.a_center).abs() < 1e-6, + "a_center {}", + p.a_center + ); + assert_eq!(p.k0, -0.001, "k0 moved in cylindrical distortion fit"); + assert_eq!(p.k1, 1e-5, "k1 moved in cylindrical distortion fit"); + assert_eq!(p.x0, 3.0, "x0 moved in cylindrical distortion fit"); + } } diff --git a/crates/gipfel/src/app.rs b/crates/gipfel/src/app.rs index 9fff27a..c3fb430 100644 --- a/crates/gipfel/src/app.rs +++ b/crates/gipfel/src/app.rs @@ -1450,6 +1450,13 @@ pub fn app() -> Html { <option value="0" selected={*projection == 0}>{ "Rectilinear projection" }</option> <option value="1" selected={*projection == 1}>{ "Cylindrical (panoramic)" }</option> </select> + // Distortion only affects the rectilinear + // projection: the cylindrical formulas do not + // contain k0/k1/x0 and its derivative trait + // defaults are NaN, so a level-2 fit is a provable + // no-op there. Grey the whole group out in + // panorama mode (native fieldset disabling). + <fieldset class="distortion" disabled={*projection == 1}> <label class="row"> <input type="checkbox" checked={*fit_distortion} onchange={on_distortion_toggle} /> { "Fit distortion (needs ≥ 4 markers)" } @@ -1476,6 +1483,7 @@ pub fn app() -> Html { } </select> } + </fieldset> <div class="section">{ "Display" }</div> <label class="row"> <input type="checkbox" checked={*show_hidden} onchange={on_show_hidden} /> diff --git a/crates/gipfel/www/style.css b/crates/gipfel/www/style.css index 942c569..7e01c5c 100644 --- a/crates/gipfel/www/style.css +++ b/crates/gipfel/www/style.css @@ -405,3 +405,14 @@ select.textinput { .zoomctrl button + button { border-top: 1px solid rgba(255, 255, 255, 0.15); } + +/* distortion controls group; greyed out and disabled in panorama mode */ +fieldset.distortion { + border: none; + margin: 0; + padding: 0; + min-width: 0; +} +fieldset.distortion:disabled { + opacity: 0.45; +} |
