Skip to main content

fold_bd09_to_gcj02

Function fold_bd09_to_gcj02 

Source
pub fn fold_bd09_to_gcj02(
    input: Bd09Coord,
) -> Result<(f64, f64), DatumFoldError>
Expand description

Fold a BD-09 input coordinate to GCJ-02 at the input edge, returning the (lat, lon) to store under GpsDatum::Gcj02.

Only gcj02_to_bd09 — the forward direction — is closed-form, so this is the error-bounded iterative inverse of it: seed with the offset-removed coordinate, then repeatedly push the estimate forward, measure the residual against the input, and correct by it. The forward map is the identity plus a small perturbation, so the iteration contracts sharply and reaches BD09_FOLD_TOLERANCE_DEGREES in a handful of steps.

The result is certified before it is returned: the accepted estimate is pushed forward one last time and must land on the input within tolerance, so a successful fold is always inside BD09_FOLD_BOUND_METRES. It is deterministic — pure f64 arithmetic on a fixed schedule, so the same input yields bit-identical output on every run.

BD-09 MUST NOT be stored verbatim — it is not a storable GpsDatum. Callers store the result as datum = gcj02.