/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 | 0 | #define HLFPI2 2.46740110027233965467 /* (pi/2)^2 */ |
9 | 0 | #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 | 0 | static PJ_XY bacon_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ |
23 | 0 | PJ_XY xy = {0.0, 0.0}; |
24 | 0 | struct pj_bacon *Q = static_cast<struct pj_bacon *>(P->opaque); |
25 | 0 | double ax, f; |
26 | |
|
27 | 0 | xy.y = Q->bacn ? M_HALFPI * sin(lp.phi) : lp.phi; |
28 | 0 | ax = fabs(lp.lam); |
29 | 0 | if (ax >= EPS) { |
30 | 0 | if (Q->ortl && ax >= M_HALFPI) |
31 | 0 | xy.x = sqrt(HLFPI2 - lp.phi * lp.phi + EPS) + ax - M_HALFPI; |
32 | 0 | else { |
33 | 0 | f = 0.5 * (HLFPI2 / ax + ax); |
34 | 0 | xy.x = ax - f + sqrt(f * f - xy.y * xy.y); |
35 | 0 | } |
36 | 0 | if (lp.lam < 0.) |
37 | 0 | xy.x = -xy.x; |
38 | 0 | } else |
39 | 0 | xy.x = 0.; |
40 | 0 | return (xy); |
41 | 0 | } |
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 | 15 | PJ *PJ_PROJECTION(apian) { |
58 | 15 | struct pj_bacon *Q = |
59 | 15 | static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon))); |
60 | 15 | if (nullptr == Q) |
61 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
62 | 15 | P->opaque = Q; |
63 | | |
64 | 15 | Q->bacn = Q->ortl = 0; |
65 | 15 | P->es = 0.; |
66 | 15 | P->fwd = bacon_s_forward; |
67 | 15 | return P; |
68 | 15 | } |
69 | | |
70 | 11 | PJ *PJ_PROJECTION(ortel) { |
71 | 11 | struct pj_bacon *Q = |
72 | 11 | static_cast<struct pj_bacon *>(calloc(1, sizeof(struct pj_bacon))); |
73 | 11 | if (nullptr == Q) |
74 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
75 | 11 | P->opaque = Q; |
76 | | |
77 | 11 | Q->bacn = 0; |
78 | 11 | Q->ortl = 1; |
79 | 11 | P->es = 0.; |
80 | 11 | P->fwd = bacon_s_forward; |
81 | 11 | return P; |
82 | 11 | } |
83 | | |
84 | | #undef HLFPI2 |
85 | | #undef EPS |