Skip to content

Spherical precision fixes - #143

Merged
pomadchin merged 4 commits into
locationtech:masterfrom
pomadchin:spherical-precision-proj-master
Nov 14, 2026
Merged

pomadchin merged 4 commits into
locationtech:masterfrom
pomadchin:spherical-precision-proj-master

Conversation

@pomadchin

Copy link
Copy Markdown
Member

Backports some of the bug fixes from #140

@pomadchin pomadchin added the bug label Nov 14, 2026
Comment on lines +53 to +62
double sinc = Math.sin(c);
double sinphi = Math.sin(lpphi);
double cosphi = Math.cos(lpphi);
// sin(d) from hypot() and d from atan2() keep the relative accuracy near the
// origin, where acos() of a value close to 1 did not (as in PROJ)
double sind = Math.hypot(cosphi * sinc, sinphi);
// d / sin(d), with limit 1 at the origin
double a = sind == 0. ? 1. : Math.atan2(sind, cosphi * Math.cos(c)) / sind;
out.x = 2. * cosphi * sinc * a;
out.y = sinphi * a;

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.

Comment on lines +105 to +119
// c is the angular distance to (phi, lam). As in PROJ, sin(c) from hypot() and
// c from atan2() keep the forward accurate near the centre, unlike acos(cos(c));
// only points within TOL of cos(c) = -1 (the antipode) are rejected
double s0 = mode == EQUATOR ? 0. : sinphi0, c0 = mode == EQUATOR ? 1. : cosphi0;
double sinlam = Math.sin(lam);
double cosphiCoslam = cosphi * coslam;
double cosc = s0 * sinphi + c0 * cosphiCoslam;
double t = c0 * sinphi - s0 * cosphiCoslam;
double sinc = Math.hypot(cosphi * sinlam, t);
if (cosc < TOL - 1.)
throw new ProjectionException();
// c / sin(c), with limit 1 at the centre
double k = sinc == 0. ? 1. : Math.atan2(sinc, cosc) / sinc;
xy.x = k * cosphi * sinlam;
xy.y = k * t;

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.

@pomadchin
pomadchin force-pushed the spherical-precision-proj-master branch from 2d54bb8 to e4a4e27 Compare November 14, 2026 14:33
@pomadchin
pomadchin force-pushed the spherical-precision-proj-master branch from e4a4e27 to 2939cbc Compare November 14, 2026 14:35
@pomadchin
pomadchin merged commit f579695 into locationtech:master Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants