1 #define PJ_LIB__
2
3 #include <float.h>
4 #include <math.h>
5
6 #include "proj.h"
7 #include "proj_internal.h"
8 #include <math.h>
9
10 PROJ_HEAD(tobmerc, "Tobler-Mercator") "\n\tCyl, Sph";
11
12 #define EPS10 1.e-10
logtanpfpim1(double x)13 static double logtanpfpim1(double x) { /* log(tan(x/2 + M_FORTPI)) */
14 if (fabs(x) <= DBL_EPSILON) {
15 /* tan(M_FORTPI + .5 * x) can be approximated by 1.0 + x */
16 return log1p(x);
17 }
18 return log(tan(M_FORTPI + .5 * x));
19 }
20
tobmerc_s_forward(PJ_LP lp,PJ * P)21 static PJ_XY tobmerc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
22 PJ_XY xy = {0.0, 0.0};
23 double cosphi;
24
25 if (fabs(fabs(lp.phi) - M_HALFPI) <= EPS10) {
26 proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
27 return xy;
28 }
29
30 cosphi = cos(lp.phi);
31 xy.x = P->k0 * lp.lam * cosphi * cosphi;
32 xy.y = P->k0 * logtanpfpim1(lp.phi);
33 return xy;
34 }
35
tobmerc_s_inverse(PJ_XY xy,PJ * P)36 static PJ_LP tobmerc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
37 PJ_LP lp = {0.0, 0.0};
38 double cosphi;
39
40 lp.phi = atan(sinh(xy.y / P->k0));
41 cosphi = cos(lp.phi);
42 lp.lam = xy.x / P->k0 / (cosphi * cosphi);
43 return lp;
44 }
45
PROJECTION(tobmerc)46 PJ *PROJECTION(tobmerc) {
47 P->inv = tobmerc_s_inverse;
48 P->fwd = tobmerc_s_forward;
49 return P;
50 }
51