aboutsummaryrefslogtreecommitdiff
path: root/src/PJ_merc.c
diff options
context:
space:
mode:
authorThomas Knudsen <lastname DOT firstname AT gmail DOT com>2016-04-01 23:10:44 +0200
committerThomas Knudsen <lastname DOT firstname AT gmail DOT com>2016-04-01 23:10:44 +0200
commit186c6e3303ccef8e833026e4e9dbaa76be6cb93b (patch)
treeb806475ab8896a3a9841cad737da0b8ee0d30859 /src/PJ_merc.c
parenta648ae934034924f15e1468b04bd986e007fd381 (diff)
downloadPROJ-186c6e3303ccef8e833026e4e9dbaa76be6cb93b.tar.gz
PROJ-186c6e3303ccef8e833026e4e9dbaa76be6cb93b.zip
First steps toward simplified macros/internals
The brief version:: In an attempt to make proj.4 code slightly more secure and much easier to read and maintain, I'm trying to eliminate a few unfortunate design decisions from the early days of proj.4 The work will be *very* intrusive, especially in the PJ_xxx segment of the code tree, but great care has been taken to design a process that can be implemented stepwise and localized, one projection at a time, then finalized with a relatively small and concentrated work package. The (very) long version: See the comments in PJ_minimal.c
Diffstat (limited to 'src/PJ_merc.c')
-rw-r--r--src/PJ_merc.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/PJ_merc.c b/src/PJ_merc.c
index 4b991c1c..89913e50 100644
--- a/src/PJ_merc.c
+++ b/src/PJ_merc.c
@@ -1,31 +1,53 @@
#define PJ_LIB__
#include <projects.h>
PROJ_HEAD(merc, "Mercator") "\n\tCyl, Sph&Ell\n\tlat_ts=";
+
#define EPS10 1.e-10
-FORWARD(e_forward); /* ellipsoid */
- if (fabs(fabs(lp.phi) - HALFPI) <= EPS10) F_ERROR;
+
+
+static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
+ XY xy = {0.0,0.0};
+ if (fabs(fabs(lp.phi) - HALFPI) <= EPS10)
+ F_ERROR;
xy.x = P->k0 * lp.lam;
xy.y = - P->k0 * log(pj_tsfn(lp.phi, sin(lp.phi), P->e));
- return (xy);
+ return xy;
}
-FORWARD(s_forward); /* spheroid */
- if (fabs(fabs(lp.phi) - HALFPI) <= EPS10) F_ERROR;
+
+
+static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
+ XY xy = {0.0,0.0};
+ if (fabs(fabs(lp.phi) - HALFPI) <= EPS10)
+ F_ERROR;
xy.x = P->k0 * lp.lam;
xy.y = P->k0 * log(tan(FORTPI + .5 * lp.phi));
- return (xy);
+ return xy;
}
-INVERSE(e_inverse); /* ellipsoid */
- if ((lp.phi = pj_phi2(P->ctx, exp(- xy.y / P->k0), P->e)) == HUGE_VAL) I_ERROR;
+
+
+static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
+ LP lp = {0.0,0.0};
+ if ((lp.phi = pj_phi2(P->ctx, exp(- xy.y / P->k0), P->e)) == HUGE_VAL)
+ I_ERROR;
lp.lam = xy.x / P->k0;
- return (lp);
+ return lp;
}
-INVERSE(s_inverse); /* spheroid */
+
+
+static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
+ LP lp = {0.0,0.0};
lp.phi = HALFPI - 2. * atan(exp(-xy.y / P->k0));
lp.lam = xy.x / P->k0;
- return (lp);
+ return lp;
}
-FREEUP; if (P) pj_dalloc(P); }
-ENTRY0(merc)
+
+
+static void freeup(PJ *P) { /* Destructor */
+ pj_dealloc(P);
+}
+
+
+PJ *PROJECTION(merc) {
double phits=0.0;
int is_phits;
@@ -33,15 +55,20 @@ ENTRY0(merc)
phits = fabs(pj_param(P->ctx, P->params, "rlat_ts").f);
if (phits >= HALFPI) E_ERROR(-24);
}
+
if (P->es) { /* ellipsoid */
if (is_phits)
P->k0 = pj_msfn(sin(phits), cos(phits), P->es);
P->inv = e_inverse;
P->fwd = e_forward;
- } else { /* sphere */
+ }
+
+ else { /* sphere */
if (is_phits)
P->k0 = cos(phits);
P->inv = s_inverse;
P->fwd = s_forward;
}
-ENDENTRY(P)
+
+ return P;
+}