aboutsummaryrefslogtreecommitdiff
path: root/src/projections/tobmerc.cpp
blob: f05a9b6b9cb6113c531e0bfaac04db108efeabb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#define PJ_LIB__

#include <float.h>
#include <math.h>

#include "proj.h"
#include "proj_internal.h"
#include <math.h>

PROJ_HEAD(tobmerc, "Tobler-Mercator") "\n\tCyl, Sph";

static PJ_XY tobmerc_s_forward (PJ_LP lp, PJ *P) {           /* Spheroidal, forward */
    PJ_XY xy = {0.0, 0.0};
    double cosphi;

    if (fabs(lp.phi) >= M_HALFPI) {
      // builtins.gie tests "Test expected failure at the poles:".  However
      // given that M_HALFPI is strictly less than pi/2 in double precision,
      // it's not clear why shouldn't just return a large result for xy.y (and
      // it's not even that large, merely 38.025...).  Even if the logic was
      // such that phi was strictly equal to pi/2, allowing xy.y = inf would be
      // a reasonable result.
        proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
        return xy;
    }

    cosphi = cos(lp.phi);
    xy.x = P->k0 * lp.lam * cosphi * cosphi;
    xy.y = P->k0 * asinh(tan(lp.phi));
    return xy;
}

static PJ_LP tobmerc_s_inverse (PJ_XY xy, PJ *P) {           /* Spheroidal, inverse */
    PJ_LP lp = {0.0, 0.0};
    double cosphi;

    lp.phi = atan(sinh(xy.y / P->k0));
    cosphi = cos(lp.phi);
    lp.lam = xy.x / P->k0 / (cosphi * cosphi);
    return lp;
}

PJ *PROJECTION(tobmerc) {
    P->inv = tobmerc_s_inverse;
    P->fwd = tobmerc_s_forward;
    return P;
}