Coverage Report

Created: 2024-02-25 06:14

/src/PROJ/src/projections/putp2.cpp
Line
Count
Source (jump to first uncovered line)
1
2
3
#include <math.h>
4
5
#include "proj.h"
6
#include "proj_internal.h"
7
8
PROJ_HEAD(putp2, "Putnins P2") "\n\tPCyl, Sph";
9
10
0
#define C_x 1.89490
11
0
#define C_y 1.71848
12
0
#define C_p 0.6141848493043784
13
0
#define EPS 1e-10
14
0
#define NITER 10
15
0
#define PI_DIV_3 1.0471975511965977
16
17
0
static PJ_XY putp2_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */
18
0
    PJ_XY xy = {0.0, 0.0};
19
0
    int i;
20
0
    (void)P;
21
22
0
    const double p = C_p * sin(lp.phi);
23
0
    const double phi_pow_2 = lp.phi * lp.phi;
24
0
    lp.phi *= 0.615709 + phi_pow_2 * (0.00909953 + phi_pow_2 * 0.0046292);
25
0
    for (i = NITER; i; --i) {
26
0
        const double c = cos(lp.phi);
27
0
        const double s = sin(lp.phi);
28
0
        const double V =
29
0
            (lp.phi + s * (c - 1.) - p) / (1. + c * (c - 1.) - s * s);
30
0
        lp.phi -= V;
31
0
        if (fabs(V) < EPS)
32
0
            break;
33
0
    }
34
0
    if (!i)
35
0
        lp.phi = lp.phi < 0 ? -PI_DIV_3 : PI_DIV_3;
36
0
    xy.x = C_x * lp.lam * (cos(lp.phi) - 0.5);
37
0
    xy.y = C_y * sin(lp.phi);
38
39
0
    return xy;
40
0
}
41
42
0
static PJ_LP putp2_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
43
0
    PJ_LP lp = {0.0, 0.0};
44
45
0
    lp.phi = aasin(P->ctx, xy.y / C_y);
46
0
    const double c = cos(lp.phi);
47
0
    lp.lam = xy.x / (C_x * (c - 0.5));
48
0
    lp.phi = aasin(P->ctx, (lp.phi + sin(lp.phi) * (c - 1.)) / C_p);
49
50
0
    return lp;
51
0
}
52
53
42
PJ *PJ_PROJECTION(putp2) {
54
42
    P->es = 0.;
55
42
    P->inv = putp2_s_inverse;
56
42
    P->fwd = putp2_s_forward;
57
58
42
    return P;
59
42
}
60
61
#undef C_x
62
#undef C_y
63
#undef C_p
64
#undef EPS
65
#undef NITER
66
#undef PI_DIV_3