Skip to content

Commit e1733c3

Browse files
authored
Merge pull request #4386 from rouault/fix_4385
Inverse +proj=cass: fix non-convergence on inputs where easting=false_easting or northing=false_northing
2 parents c524721 + 90ad86d commit e1733c3

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

src/generic_inverse.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,23 @@ PJ_LP pj_generic_inverse_2d(PJ_XY xy, PJ *P, PJ_LP lpInitial,
8787
}
8888
}
8989

90-
if (xy.x != 0) {
91-
// Limit the amplitude of correction to avoid overshoots due to
92-
// bad initial guess
93-
const double delta_lam = std::max(
94-
std::min(deltaX * deriv_lam_X + deltaY * deriv_lam_Y, 0.3),
95-
-0.3);
96-
lp.lam -= delta_lam;
97-
if (lp.lam < -M_PI)
98-
lp.lam = -M_PI;
99-
else if (lp.lam > M_PI)
100-
lp.lam = M_PI;
101-
}
90+
// Limit the amplitude of correction to avoid overshoots due to
91+
// bad initial guess
92+
const double delta_lam = std::max(
93+
std::min(deltaX * deriv_lam_X + deltaY * deriv_lam_Y, 0.3), -0.3);
94+
lp.lam -= delta_lam;
95+
if (lp.lam < -M_PI)
96+
lp.lam = -M_PI;
97+
else if (lp.lam > M_PI)
98+
lp.lam = M_PI;
10299

103-
if (xy.y != 0) {
104-
const double delta_phi = std::max(
105-
std::min(deltaX * deriv_phi_X + deltaY * deriv_phi_Y, 0.3),
106-
-0.3);
107-
lp.phi -= delta_phi;
108-
if (lp.phi < -M_HALFPI)
109-
lp.phi = -M_HALFPI;
110-
else if (lp.phi > M_HALFPI)
111-
lp.phi = M_HALFPI;
112-
}
100+
const double delta_phi = std::max(
101+
std::min(deltaX * deriv_phi_X + deltaY * deriv_phi_Y, 0.3), -0.3);
102+
lp.phi -= delta_phi;
103+
if (lp.phi < -M_HALFPI)
104+
lp.phi = -M_HALFPI;
105+
else if (lp.phi > M_HALFPI)
106+
lp.phi = M_HALFPI;
113107
}
114108
proj_context_errno_set(P->ctx,
115109
PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);

test/gie/builtins.gie

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,21 @@ accept 179.99433652777776 -16.841456527777776
920920
expect 16015.28901692 13369.66005367
921921
roundtrip 1
922922

923+
924+
-------------------------------------------------------------------------------
925+
# Scenario of https://github.com/OSGeo/PROJ/issues/4385
926+
-------------------------------------------------------------------------------
927+
operation +proj=cass +lat_0=50.6177 +lon_0=-1.19725 +x_0=500000 +y_0=100000 +ellps=airy +units=m
928+
929+
tolerance 0.1 mm
930+
direction inverse
931+
932+
accept 300000 100000
933+
expect -4.022094267169 50.583438725252
934+
935+
accept 500000 100000
936+
expect -1.19725 50.6177
937+
923938
===============================================================================
924939
# Central Conic
925940
# Sph

0 commit comments

Comments
 (0)