/src/PROJ/src/projections/bacon.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | #include <errno.h> |
3 | | #include <math.h> |
4 | | |
5 | | #include "proj.h" |
6 | | #include "proj_internal.h" |
7 | | |
8 | 5.04k | #define HLFPI2 2.46740110027233965467 /* (pi/2)^2 */ |
9 | 7.32k | #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 | 5.04k | static PJ_XY bacon_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ |
23 | 5.04k | PJ_XY xy = {0.0, 0.0}; |
24 | 5.04k | struct pj_bacon *Q = static_cast<struct pj_bacon *>(P->opaque); |
25 | 5.04k | double ax, f; |
26 | | |
27 | 5.04k | xy.y = Q->bacn ? M_HALFPI * sin(lp.phi) : lp.phi; |
28 | 5.04k | ax = fabs(lp.lam); |
29 | 5.04k | if (ax >= EPS) { |
30 | 5.04k | if (Q->ortl && ax >= M_HALFPI) |
31 | 2.28k | xy.x = sqrt(HLFPI2 - lp.phi * lp.phi + EPS) + ax - M_HALFPI; |
32 | 2.75k | else { |
33 | 2.75k | f = 0.5 * (HLFPI2 / ax + ax); |
34 | 2.75k | xy.x = ax - f + sqrt(f * f - xy.y * xy.y); |
35 | 2.75k | } |
36 | 5.04k | if (lp.lam < 0.) |
37 | 4.87k | xy.x = -xy.x; |
38 | 5.04k | } else |
39 | 0 | xy.x = 0.; |
40 | 5.04k | return (xy); |
41 | 5.04k | } |
42 | | |
43 | 2 | PJ *PJ_PROJECTION(bacon) { |
44 | 2 | struct pj_bacon *Q = |
45 | 2 | static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon))); |
46 | 2 | if (nullptr == Q) |
47 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
48 | 2 | P->opaque = Q; |
49 | | |
50 | 2 | Q->bacn = 1; |
51 | 2 | Q->ortl = 0; |
52 | 2 | P->es = 0.; |
53 | 2 | P->fwd = bacon_s_forward; |
54 | 2 | return P; |
55 | 2 | } |
56 | | |
57 | 21 | PJ *PJ_PROJECTION(apian) { |
58 | 21 | struct pj_bacon *Q = |
59 | 21 | static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon))); |
60 | 21 | if (nullptr == Q) |
61 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
62 | 21 | P->opaque = Q; |
63 | | |
64 | 21 | Q->bacn = Q->ortl = 0; |
65 | 21 | P->es = 0.; |
66 | 21 | P->fwd = bacon_s_forward; |
67 | 21 | return P; |
68 | 21 | } |
69 | | |
70 | 42 | PJ *PJ_PROJECTION(ortel) { |
71 | 42 | struct pj_bacon *Q = |
72 | 42 | static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon))); |
73 | 42 | if (nullptr == Q) |
74 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
75 | 42 | P->opaque = Q; |
76 | | |
77 | 42 | Q->bacn = 0; |
78 | 42 | Q->ortl = 1; |
79 | 42 | P->es = 0.; |
80 | 42 | P->fwd = bacon_s_forward; |
81 | 42 | return P; |
82 | 42 | } |
83 | | |
84 | | #undef HLFPI2 |
85 | | #undef EPS |