From 6902c44a6e0b9dc591923da203e2d9983458cd4c Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Thu, 12 Nov 2026 22:51:46 +0100 Subject: core: fix fit for wide panoramas (markers >180 deg apart in image) The initial guess in comp_params assumed the two markers are less than 180 deg apart: a_center started on the first marker and the scale came from the shortest-arc azimuth difference. In panoramas wider than 180 deg the markers can straddle the seam - e.g. at -170 deg and +170 deg of the view center they are 340 deg apart in the image but only 20 deg on the compass. The start was then off by up to 170 deg in azimuth and a factor of 17 in scale, and the fit never recovered. Fix: derive the image-space azimuth difference from the SIGN OF THE PIXEL DIFFERENCE (the user's marker placement tells us which branch was meant; the magnitude is unique modulo 2pi for panoramas below 360 deg), and start the view center between the markers in that branch. The golden fit tests now compare a_center modulo 2pi: the C harness settles wherever its >2pi input azimuths put it (380 deg), the Rust port normalizes (20 deg) - same physical solution. Tests: fits with markers 340 deg apart, 350 deg apart in reversed marker order, and 200 deg apart (just over the seam). All three fail without the fix (verified), pass with it. --- crates/gipfel-core/tests/golden.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/gipfel-core/tests/golden.rs') diff --git a/crates/gipfel-core/tests/golden.rs b/crates/gipfel-core/tests/golden.rs index fb12e40..2027800 100644 --- a/crates/gipfel-core/tests/golden.rs +++ b/crates/gipfel-core/tests/golden.rs @@ -253,10 +253,18 @@ fn fit_golden(projtype: ProjectionType, file: &str) { pan.parms.k1, pan.parms.x0, ]; - for (m, t) in mine.iter().zip(g.iter()) { + for (idx, (m, t)) in mine.iter().zip(g.iter()).enumerate() { // solver results: allow small drift, exact zeros must stay ~zero + // a_center (idx 0) is an angle: the C harness settles wherever its + // (possibly > 2pi) input azimuths put it; the Rust port normalizes. + // Compare modulo 2pi. + let d = if idx == 0 { + gipfel_core::projection::wrap_angle(m - t) + } else { + m - t + }; assert!( - (m - t).abs() <= 1e-6f64.max(m.abs() * 1e-6), + d.abs() <= 1e-6f64.max(m.abs() * 1e-6), "fit param {} vs {}", m, t -- cgit v1.2.3