Skip to content

fix(geom): Eckert IV and Equal Earth bring places near the poles back where they were - #1893

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:fix/eckert-iv-inverse
Nov 13, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:fix/eckert-iv-inverse

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Eckert IV and Equal Earth now bring places at and near the poles back where they were. Before, an
Eckert IV round trip of the south pole came back at -89.99996° (4.5 m away; 3.8 m at the north pole),
a pole off the central meridian such as (100°, 90°) couldn't be unprojected at all, and Equal Earth
brought the poles back 2–5 m off. Eckert IV is also used to read files in that coordinate system, so
their coordinates near the poles were affected too.

Found by a property test of reprojection round trips (forward then inverse comes back within 1 cm), which will follow in its own pull request.

Cause. World::inverse (crates/geom/src/world.rs) solved every world projection by Newton's
method on the forward formula and accepted a point once the map coordinates were within 1e-9 radii.
Near a pole y barely changes with latitude, so a latitude metres off already passes. Off the central
meridian at the pole it didn't get within that tolerance at all, so the point was refused.

Fix. Eckert IV and Equal Earth get their published inverses:

  • Eckert IV in closed form, from Snyder, Map Projections: A Working Manual (USGS Professional Paper
    1395, 1987): θ = asin(y / (2·√(π/(4+π))·R)), φ = asin((θ + sinθ·cosθ + 2·sinθ) / (2 + π/2)),
    λ = x / ((2/√(π(4+π)))·R·(1 + cosθ)).
  • Equal Earth as given by Šavrič, Patterson and Jenny, "The Equal Earth map projection" (IJGIS,
    2018): θ from y by a one-variable Newton's method (y rises steadily with θ), then φ and λ in closed
    form.

Both reject points outside the map's outline as before: y past the pole line, or a longitude past
±180° (a rounding error past either still counts). Robinson, Natural Earth and Winkel Tripel keep
the Newton solve.

Testing

  • New world::tests::places_at_and_near_the_poles_come_back_within_a_millimetre: Eckert IV and
    Equal Earth round trips of both poles, on and off the central meridian, and of 89.99° and
    -89.999°, within 1 mm on the ground. Before the fix it fails (EckertIV 0,90: … 3.84 m off;
    Equal Earth alone: EqualEarth 0,90: … 4.53 m off); after it passes.
  • Existing round_trips_and_outlines (round trips, outline rejection, the ±180° edges) and
    against_proj pass unchanged.
  • cargo fmt --all, cargo clippy -p rustgis-geom --all-targets -- -D warnings, cargo test -p rustgis-geom, cargo test -p rustgis-data -p rustgis-map, and the wasm32-unknown-unknown build
    of rustgis-web.

Related issue

None; found by a property test.

Summary by CodeRabbit

  • Bug Fixes
    • Improved inverse coordinate conversion for Eckert IV and Equal Earth projections, including points near the poles.
    • Coordinates outside these projections’ outlines are now rejected, with a small tolerance for rounding and accepted longitudes limited to the valid range.
    • Robinson, Natural Earth, and Winkel Tripel continue to use their existing inverse conversion behavior.

… where they were

A round trip of the poles through Eckert IV came back 4 m off, (100°, ±90°)
couldn't be unprojected at all, and Equal Earth brought the poles back 2 to 5 m
off. World::inverse solved every world projection by Newton's method on the
forward formula and accepted a point within 1e-9 radii of the target; near a
pole y barely changes with latitude, so metres of latitude already passed.

Eckert IV now uses its closed-form inverse (Snyder, USGS Professional Paper
1395) and Equal Earth the inverse of Šavrič, Patterson and Jenny (2018). The
other world projections keep the Newton solve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

World::inverse now uses projection-specific inverse formulas for Eckert IV and Equal Earth. The formulas check map-outline bounds with rounding slack. Tests check pole and near-pole round trips within one millimetre.

Changes: Projection inverse updates

Layer / File(s) Summary
Projection-specific inverse calculations
crates/geom/src/world.rs
Added inverse calculations for Eckert IV and Equal Earth. Both check outline bounds with 1e-9 slack. The Newton helper now returns solved coordinates.
Inverse dispatch and validation
crates/geom/src/world.rs
World::inverse dispatches Eckert IV and Equal Earth to their direct inverses, while other projections retain Newton inversion. Documentation describes the methods, and tests check pole and near-pole round trips.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: bearinmindcat, giswqs

Merge Risk: Minimal · up to f44d8

This change replaces the iterative inverse for Eckert IV and Equal Earth with direct formulas, so pole coordinates should round-trip within a millimetre. No unresolved merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Eckert IV and Equal Earth inverses are fixed so places near the poles return to their original positions. The changeset adds closed-form and one-variable Newton invers…
Description check Passed The description follows the template. It has a Summary that explains the change and its cause, a Testing section that lists new and existing tests and the commands run, and a Related issue section tha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Eckert IV and Equal Earth inverses are fixed so places near the poles return to their original positions. The changeset adds closed-form and one-variable Newton inverses for these two projections in World::inverse, and the other projections keep Newton's method. The title is specific and matches the change.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the change and its cause, a Testing section that lists new and existing tests and the commands run, and a Related issue section that states none and names the property test that found the bug. The UI evidence section is missing. The template requires it, but the PR changes no visible UI, so the author should keep the 'No visible UI change.' line. The description does not include that line.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit plots a globe so wide,
Then turns the poles from side to side.
Eckert and Equal Earth come through,
Their outlines checked, their answers true.
Near the poles, the round trips land,
Within a millimetre, neat and planned.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ff4e26f7-c00f-4eef-8582-115a640be444
Commits

Reviewing files that changed from the base of the PR and between 8f3c5cc and f44d8dc.

Files selected for processing: 1

  • crates/geom/src/world.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread crates/geom/src/world.rs
// Metres along the meridian and the parallel.
let north = (back.y - lat).to_radians() * MERCATOR_R;
let east = (back.x - lon).to_radians() * lat.to_radians().cos() * MERCATOR_R;
let off = north.hypot(east);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quality (test coverage, low): at a pole the east term is multiplied by cos(lat), about 6e-17 here, so longitude at (100, 90) and (-100, -90) is never checked. A wrong λ there would still pass, because the ground distance ignores longitude. On the map, though, the pole's position does depend on λ for both projections. Adding a map-space check closes the gap. I haven't run this suggestion.

Suggested change
let off = north.hypot(east);
let off = north.hypot(east);
// At a pole the ground distance ignores longitude, but the map doesn't: the map point must come back too.
let again = w.forward(back).unwrap();
let map_off = (again.x - m.x).hypot(again.y - m.y);
assert!(off < 1e-3 && map_off < 1e-3, "{kind:?} {lon},{lat}: {back:?}, {off} m off, {map_off} m off on the map");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass: at a pole every longitude names the same place on the ground, which is what the test measures; the near-pole cases (89.99°, -89.999°) do check longitude.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs: None found. I checked the new inverses against the forward formulas. For Eckert IV, the sinθ scale, the φ relation and the λ scale all match. For Equal Earth, y_of and dy match the forward y, x and λ. The outline rejection, the ±180° wrap, and the clamp bounds are all safe, and there are no unwraps in non-test code. I did not run cargo test, so the claim that the new test passes is the author's, not mine.

Security: None found.

Performance: None found. The Equal Earth Newton loop is bounded at 20 iterations and converges monotonically from the left, since y_of is concave on [0, π/3].

Quality (low, confidence high):

  • The new pole test does not check longitude at the poles. The ground-distance term is multiplied by cos(lat), so a wrong λ at (100, 90) would still pass. Inline comment posted on crates/geom/src/world.rs:360 with a map-space check.
  • The module doc (line 8) and the inverse doc (line 196) say Equal Earth "has inverse formulas". Its θ still comes from a Newton solve, so the wording should say that. Grouped here rather than as an inline comment.

AGENTS.md: No violations found. Line widths are within max_width = 140. The references (Snyder 1987, Šavrič et al. 2018) are published sources, and no copyleft code is involved. The test's unwrap_or_else(panic!) matches the existing tests.

Already raised: 0. prior-reviews.json had no threads.

Change size

Compared with the base branch: the whole PR against main (merge base 0346b5c to PR head f44d8dc).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 13.4 KB
Size after 17.7 KB
Total size change +4.4 KB
Path Before After Change
crates/geom/src/world.rs 13.4 KB 17.7 KB +4.4 KB

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-1893/
Web app https://preview.rustgis.app/pr-1893/app/
Commit f44d8dc

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@Mavrick-F
Mavrick-F merged commit 786dd9a into opengeos:main Nov 13, 2026
18 checks passed
Mavrick-F added a commit that referenced this pull request Nov 13, 2026
* fix(geom): Eckert IV takes places on its outline again

Since #1893, Eckert IV refused the four corners of its map and places on
the ±180° edges near the poles. The forward formula solved
θ + sinθ·cosθ + 2·sinθ = (2 + π/2)·sinφ for θ by Newton's method, whose
slope is zero at the poles, so θ stopped about 1e-8 short of π/2 and the
pole line came out 1e-8 too long. The closed-form inverse from #1893 then
put the corners past ±180° and refused them. Near a corner the sides meet
the pole lines at a tangent, so a rounding error in y also moved the
side far in x.

The forward formula now solves the equation measured from the pole, in
u = π/2 - |θ| and v = π/2 - |φ|, which keeps its precision there. The
inverse takes cosθ from 1 - |sinθ| and φ from the pole the same way, and
counts a point as on the outline when it is within the slack of it in x
and y. A place 0.000001° from a pole comes back 1.1 cm away instead of
0.11 m.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(geom): a point past an Eckert IV corner uses its slack once

The outline's width was taken from y clamped to the pole line, so a
point just past it got the full width again. Also allow 5 cm, not 2,
near the poles, for another platform's rounding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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