Skip to content

Use safe_divide for the pole scaling in meters_to_degrees#37

Merged
vadmbertr merged 1 commit into
mainfrom
fix/geo-pole-guard
Jul 8, 2026
Merged

Use safe_divide for the pole scaling in meters_to_degrees#37
vadmbertr merged 1 commit into
mainfrom
fix/geo-pole-guard

Conversation

@vadmbertr

@vadmbertr vadmbertr commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Context

meters_to_degrees divides the zonal component by cos(lat), which is exactly zero only in the degenerate pole case.

Scope, stated plainly: this is a corner-case guard, not a fix for the near-pole blowup. At lat = 90°, cos(radians(90.0)) is ~6e-17 in floating point — not zero — so the result is already a huge-but-finite number today, and safe_divide does not change it (its denominator == 0 branch never fires). safe_divide only affects an exactly zero denominator (finite gradient, returns 0), and the flat-Earth longitude scaling genuinely diverges at the poles regardless. The docstring now says this outright.

Change

  • Route the cos(lat) division through safe_divide.
  • Document that results within a cell of the poles are unreliable and that the guard only covers the exactly-zero corner.

Tests

  • test_meters_to_degrees_finite_and_safe_at_pole: forward value and gradient finite at lat = 90°.
  • test_meters_to_degrees_unchanged_at_normal_lat: identical to the naive division where cos(lat) != 0 (no regression from the swap).

Full suite: 331 passed.

meters_to_degrees divides the zonal component by cos(lat), which is exactly
zero only in the degenerate pole case. Route it through safe_divide so an
exactly-zero cos yields 0 with a finite gradient instead of inf/nan.

This is a corner-case guard: the flat-Earth longitude scaling genuinely
diverges at the poles, and near (but not at) +-90 deg — where cos(lat) is
tiny but nonzero — the zonal component is still legitimately huge. The
docstring now states this limitation explicitly.
@vadmbertr
vadmbertr marked this pull request as ready for review July 8, 2026 12:19
@vadmbertr
vadmbertr merged commit 3136005 into main Jul 8, 2026
1 check passed
@vadmbertr
vadmbertr deleted the fix/geo-pole-guard branch July 8, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant