Coverage Report

Created: 2026-09-01 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PROJ/src/projections/bacon.cpp
Line
Count
Source
1
2
#include <errno.h>
3
#include <math.h>
4
5
#include "proj.h"
6
#include "proj_internal.h"
7
8
336
#define HLFPI2 2.46740110027233965467 /* (pi/2)^2 */
9
336
#define EPS 1e-10
10
11
namespace { // anonymous namespace
12
struct pj_bacon {
13
    int bacn;
14
    int ortl;
15
};
16
} // anonymous namespace
17
18
PROJ_HEAD(apian, "Apian Globular I") "\n\tMisc Sph, no inv";
19
PROJ_HEAD(ortel, "Ortelius Oval") "\n\tMisc Sph, no inv";
20
PROJ_HEAD(bacon, "Bacon Globular") "\n\tMisc Sph, no inv";
21
22
336
static PJ_XY bacon_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */
23
336
    PJ_XY xy = {0.0, 0.0};
24
336
    struct pj_bacon *Q = static_cast<struct pj_bacon *>(P->opaque);
25
336
    double ax, f;
26
27
336
    xy.y = Q->bacn ? M_HALFPI * sin(lp.phi) : lp.phi;
28
336
    ax = fabs(lp.lam);
29
336
    if (ax >= EPS) {
30
336
        if (Q->ortl && ax >= M_HALFPI)
31
0
            xy.x = sqrt(HLFPI2 - lp.phi * lp.phi + EPS) + ax - M_HALFPI;
32
336
        else {
33
336
            f = 0.5 * (HLFPI2 / ax + ax);
34
336
            xy.x = ax - f + sqrt(f * f - xy.y * xy.y);
35
336
        }
36
336
        if (lp.lam < 0.)
37
252
            xy.x = -xy.x;
38
336
    } else
39
0
        xy.x = 0.;
40
336
    return (xy);
41
336
}
42
43
11
PJ *PJ_PROJECTION(bacon) {
44
11
    struct pj_bacon *Q =
45
11
        static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon)));
46
11
    if (nullptr == Q)
47
0
        return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
48
11
    P->opaque = Q;
49
50
11
    Q->bacn = 1;
51
11
    Q->ortl = 0;
52
11
    P->es = 0.;
53
11
    P->fwd = bacon_s_forward;
54
11
    return P;
55
11
}
56
57
9
PJ *PJ_PROJECTION(apian) {
58
9
    struct pj_bacon *Q =
59
9
        static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon)));
60
9
    if (nullptr == Q)
61
0
        return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
62
9
    P->opaque = Q;
63
64
9
    Q->bacn = Q->ortl = 0;
65
9
    P->es = 0.;
66
9
    P->fwd = bacon_s_forward;
67
9
    return P;
68
9
}
69
70
14
PJ *PJ_PROJECTION(ortel) {
71
14
    struct pj_bacon *Q =
72
14
        static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon)));
73
14
    if (nullptr == Q)
74
0
        return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
75
14
    P->opaque = Q;
76
77
14
    Q->bacn = 0;
78
14
    Q->ortl = 1;
79
14
    P->es = 0.;
80
14
    P->fwd = bacon_s_forward;
81
14
    return P;
82
14
}
83
84
#undef HLFPI2
85
#undef EPS