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
committerEven Rouault <even.rouault@spatialys.com>2020-03-08 19:58:35 +0100
commit60d3df673ca224107eb63e459073fc11ab5f4f16 (patch)
tree52c871c17f0c98c90ce6415cdb79dc1e73c14f4d /src/projections/poly.cpp
parent38ec5e662a74d40e02e38dc5dca553c3ecb04356 (diff)
downloadPROJ-60d3df673ca224107eb63e459073fc11ab5f4f16.tar.gz
PROJ-60d3df673ca224107eb63e459073fc11ab5f4f16.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.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/projections/poly.cpp b/src/projections/poly.cpp
index fc7fc8bd..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,21 +110,20 @@ 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;
+ const double B = xy.x * xy.x + xy.y * xy.y;
+ int i = N_ITER;
while(true) {
- 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.));
+ 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;