aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Schwehr <schwehr@google.com>2018-05-03 22:59:30 -0700
committerKurt Schwehr <schwehr@google.com>2018-05-03 22:59:30 -0700
commit1760dafbabb12a6486a928c8d5e8a376a2fe5271 (patch)
treeb6e2de3136c00e1a0d361c1f9528667b8586704e
parent2f467d57d1846857eb8ac7e855646c19d6b66737 (diff)
downloadPROJ-1760dafbabb12a6486a928c8d5e8a376a2fe5271.tar.gz
PROJ-1760dafbabb12a6486a928c8d5e8a376a2fe5271.zip
Minor cleanup of pj_phi2.c
- tabs -> spaces - IWYU - #define -> static const typed - Combine definition and initialization - Define one var per statement - Use the defined symbol rather than embedding bare literals -18 -> PJD_ERR_NON_CON_INV_PHI2 Subset of fixes discussed in #971
-rw-r--r--src/pj_phi2.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/pj_phi2.c b/src/pj_phi2.c
index 00b73f70..5f73d510 100644
--- a/src/pj_phi2.c
+++ b/src/pj_phi2.c
@@ -1,28 +1,30 @@
-/* determine latitude angle phi-2 */
+/* Determine latitude angle phi-2. */
+
+#include <math.h>
+
#include "projects.h"
-#define TOL 1.0e-10
-#define N_ITER 15
+static const double TOL = 1.0e-10;
+static const int N_ITER = 15;
+
+double pj_phi2(projCtx ctx, double ts, double e) {
+ double eccnth = .5 * e;
+ double Phi = M_HALFPI - 2. * atan(ts);
+ double con;
+ int i = N_ITER;
+
+ for(;;) {
+ con = e * sin(Phi);
+ double dphi = M_HALFPI - 2. * atan(ts * pow((1. - con) /
+ (1. + con), eccnth)) - Phi;
- double
-pj_phi2(projCtx ctx, double ts, double e) {
- double eccnth, Phi, con;
- int i;
+ Phi += dphi;
- eccnth = .5 * e;
- Phi = M_HALFPI - 2. * atan (ts);
- i = N_ITER;
- for(;;) {
- double dphi;
- con = e * sin (Phi);
- dphi = M_HALFPI - 2. * atan (ts * pow((1. - con) /
- (1. + con), eccnth)) - Phi;
- Phi += dphi;
- if( fabs(dphi) > TOL && --i )
- continue;
- break;
- }
- if (i <= 0)
- pj_ctx_set_errno( ctx, -18 );
- return Phi;
+ if (fabs(dphi) > TOL && --i)
+ continue;
+ break;
+ }
+ if (i <= 0)
+ pj_ctx_set_errno(ctx, PJD_ERR_NON_CON_INV_PHI2);
+ return Phi;
}