aboutsummaryrefslogtreecommitdiff
path: root/src/projections/poly.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-03-06 20:38:38 +0100
committerKristian Evers <kristianevers@gmail.com>2020-03-09 11:08:58 +0100
commitf830121a2f7a4d631b906e5f22f5a96dac55f084 (patch)
treeb32ba74fe3e249d9bd2eeb5e224a126cabd2c228 /src/projections/poly.cpp
parent04f74f53962de4149aa32c35c13148268fd37cd2 (diff)
downloadPROJ-f830121a2f7a4d631b906e5f22f5a96dac55f084.tar.gz
PROJ-f830121a2f7a4d631b906e5f22f5a96dac55f084.zip
src/projections/: remove assignments in expression and multiple statements per line
Should hopefully result in no change in results, and hopefully more readable code...
Diffstat (limited to 'src/projections/poly.cpp')
-rw-r--r--src/projections/poly.cpp62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/projections/poly.cpp b/src/projections/poly.cpp
index 08a4aaad..10d93ed2 100644
--- a/src/projections/poly.cpp
+++ b/src/projections/poly.cpp
@@ -33,8 +33,10 @@ static PJ_XY poly_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward
xy.y = -Q->ml0;
} else {
sp = sin(lp.phi);
- ms = fabs(cp = cos(lp.phi)) > TOL ? pj_msfn(sp, cp, P->es) / sp : 0.;
- xy.x = ms * sin(lp.lam *= sp);
+ cp = cos(lp.phi);
+ ms = fabs(cp) > TOL ? pj_msfn(sp, cp, P->es) / sp : 0.;
+ lp.lam *= sp;
+ xy.x = ms * sin(lp.lam);
xy.y = (pj_mlfn(lp.phi, sp, cp, Q->en) - Q->ml0) + ms * (1. - cos(lp.lam));
}
@@ -45,14 +47,14 @@ static PJ_XY poly_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward
static PJ_XY poly_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
- double cot, E;
if (fabs(lp.phi) <= TOL) {
xy.x = lp.lam;
xy.y = Q->ml0;
} else {
- cot = 1. / tan(lp.phi);
- xy.x = sin(E = lp.lam * sin(lp.phi)) * cot;
+ const double cot = 1. / tan(lp.phi);
+ const double E = lp.lam * sin(lp.phi);
+ xy.x = sin(E) * cot;
xy.y = lp.phi - P->phi0 + cot * (1. - cos(E));
}
@@ -69,26 +71,28 @@ static PJ_LP poly_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
lp.lam = xy.x;
lp.phi = 0.;
} else {
- double r, c, sp, cp, s2ph, ml, mlb, mlp, dPhi;
int i;
- r = xy.y * xy.y + xy.x * xy.x;
+ const double r = xy.y * xy.y + xy.x * xy.x;
lp.phi = xy.y;
for (i = I_ITER; i ; --i) {
- sp = sin(lp.phi);
- s2ph = sp * ( cp = cos(lp.phi));
+ const double sp = sin(lp.phi);
+ const double cp = cos(lp.phi);
+ const double s2ph = sp * cp;
if (fabs(cp) < ITOL) {
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
return lp;
}
- c = sp * (mlp = sqrt(1. - P->es * sp * sp)) / cp;
- ml = pj_mlfn(lp.phi, sp, cp, Q->en);
- mlb = ml * ml + r;
+ double mlp = sqrt(1. - P->es * sp * sp);
+ const double c = sp * mlp / cp;
+ const double ml = pj_mlfn(lp.phi, sp, cp, Q->en);
+ const double mlb = ml * ml + r;
mlp = P->one_es / (mlp * mlp * mlp);
- lp.phi += ( dPhi =
+ const double dPhi =
( ml + ml + c * mlb - 2. * xy.y * (c * ml + 1.) ) / (
P->es * s2ph * (mlb - 2. * xy.y * ml) / c +
- 2.* (xy.y - ml) * (c * mlp - 1. / s2ph) - mlp - mlp ));
+ 2.* (xy.y - ml) * (c * mlp - 1. / s2ph) - mlp - mlp );
+ lp.phi += dPhi;
if (fabs(dPhi) <= ITOL)
break;
}
@@ -96,7 +100,7 @@ static PJ_LP poly_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
return lp;
}
- c = sin(lp.phi);
+ const double c = sin(lp.phi);
lp.lam = asin(xy.x * tan(lp.phi) * sqrt(1. - P->es * c * c)) / sin(lp.phi);
}
@@ -106,25 +110,27 @@ static PJ_LP poly_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse
static PJ_LP poly_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
- double B, dphi, tp;
- int i;
if (fabs(xy.y = P->phi0 + xy.y) <= TOL) {
lp.lam = xy.x;
lp.phi = 0.;
} else {
lp.phi = xy.y;
- B = xy.x * xy.x + xy.y * xy.y;
- i = N_ITER;
- do {
- tp = tan(lp.phi);
- lp.phi -= (dphi = (xy.y * (lp.phi * tp + 1.) - lp.phi -
- .5 * ( lp.phi * lp.phi + B) * tp) /
- ((lp.phi - xy.y) / tp - 1.));
- } while (fabs(dphi) > CONV && --i);
- if (! i) {
- proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
- return lp;
+ const double B = xy.x * xy.x + xy.y * xy.y;
+ int i = N_ITER;
+ while(true) {
+ const double tp = tan(lp.phi);
+ const double dphi = (xy.y * (lp.phi * tp + 1.) - lp.phi -
+ .5 * ( lp.phi * lp.phi + B) * tp) /
+ ((lp.phi - xy.y) / tp - 1.);
+ lp.phi -= dphi;
+ if( !(fabs(dphi) > CONV) )
+ break;
+ --i;
+ if( i == 0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return lp;
+ }
}
lp.lam = asin(xy.x * tan(lp.phi)) / sin(lp.phi);
}