Repository navigation
fix(geom): Eckert IV and Equal Earth bring places near the poles back where they were - #1893
Conversation
… 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>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| // 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); |
There was a problem hiding this comment.
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.
| 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"); |
There was a problem hiding this comment.
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.
Code reviewBugs: 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, Security: None found. Performance: None found. The Equal Earth Newton loop is bounded at 20 iterations and converges monotonically from the left, since Quality (low, confidence high):
AGENTS.md: No violations found. Line widths are within Already raised: 0. Change sizeCompared with the base branch: the whole PR against main (merge base 0346b5c to PR head f44d8dc).
|
📖 Docs preview
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 |
* 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>
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'smethod 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:
1395, 1987): θ = asin(y / (2·√(π/(4+π))·R)), φ = asin((θ + sinθ·cosθ + 2·sinθ) / (2 + π/2)),
λ = x / ((2/√(π(4+π)))·R·(1 + cosθ)).
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
world::tests::places_at_and_near_the_poles_come_back_within_a_millimetre: Eckert IV andEqual 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.round_trips_and_outlines(round trips, outline rejection, the ±180° edges) andagainst_projpass 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 thewasm32-unknown-unknownbuildof
rustgis-web.Related issue
None; found by a property test.
Summary by CodeRabbit