Coverage Report

Created: 2026-08-13 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PROJ/src/projections/putp2.cpp
Line
Count
Source
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
336
#define C_x 1.89490
11
336
#define C_y 1.71848
12
336
#define C_p 0.6141848493043784
13
1.00k
#define EPS 1e-10
14
336
#define NITER 10
15
0
#define PI_DIV_3 1.0471975511965977
16
17
336
static PJ_XY putp2_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */
18
336
    PJ_XY xy = {0.0, 0.0};
19
336
    int i;
20
336
    (void)P;
21
22
336
    const double p = C_p * sin(lp.phi);
23
336
    const double phi_pow_2 = lp.phi * lp.phi;
24
336
    lp.phi *= 0.615709 + phi_pow_2 * (0.00909953 + phi_pow_2 * 0.0046292);
25
1.00k
    for (i = NITER; i; --i) {
26
1.00k
        const double c = cos(lp.phi);
27
1.00k
        const double s = sin(lp.phi);
28
1.00k
        const double V =
29
1.00k
            (lp.phi + s * (c - 1.) - p) / (1. + c * (c - 1.) - s * s);
30
1.00k
        lp.phi -= V;
31
1.00k
        if (fabs(V) < EPS)
32
336
            break;
33
1.00k
    }
34
336
    if (!i)
35
0
        lp.phi = lp.phi < 0 ? -PI_DIV_3 : PI_DIV_3;
36
336
    xy.x = C_x * lp.lam * (cos(lp.phi) - 0.5);
37
336
    xy.y = C_y * sin(lp.phi);
38
39
336
    return xy;
40
336
}
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
19
PJ *PJ_PROJECTION(putp2) {
54
19
    P->es = 0.;
55
19
    P->inv = putp2_s_inverse;
56
19
    P->fwd = putp2_s_forward;
57
58
19
    return P;
59
19
}
60
61
#undef C_x
62
#undef C_y
63
#undef C_p
64
#undef EPS
65
#undef NITER
66
#undef PI_DIV_3