1 # define HLFPI2 2.46740110027233965467 /* (pi/2)^2 */
2 # define EPS 1e-10
3 #define PJ_LIB__
4 #include <projects.h>
5
6
7 struct pj_opaque {
8 int bacn;
9 int ortl;
10 };
11
12 PROJ_HEAD(apian, "Apian Globular I") "\n\tMisc Sph, no inv.";
13 PROJ_HEAD(ortel, "Ortelius Oval") "\n\tMisc Sph, no inv.";
14 PROJ_HEAD(bacon, "Bacon Globular") "\n\tMisc Sph, no inv.";
15
16
s_forward(LP lp,PJ * P)17 static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
18 XY xy = {0.0,0.0};
19 struct pj_opaque *Q = P->opaque;
20 double ax, f;
21
22 xy.y = Q->bacn ? M_HALFPI * sin(lp.phi) : lp.phi;
23 if ((ax = fabs(lp.lam)) >= EPS) {
24 if (Q->ortl && ax >= M_HALFPI)
25 xy.x = sqrt(HLFPI2 - lp.phi * lp.phi + EPS) + ax - M_HALFPI;
26 else {
27 f = 0.5 * (HLFPI2 / ax + ax);
28 xy.x = ax - f + sqrt(f * f - xy.y * xy.y);
29 }
30 if (lp.lam < 0.) xy.x = - xy.x;
31 } else
32 xy.x = 0.;
33 return (xy);
34 }
35
36
freeup_new(PJ * P)37 static void *freeup_new (PJ *P) { /* Destructor */
38 if (0==P)
39 return 0;
40 if (0==P->opaque)
41 return pj_dealloc (P);
42
43 pj_dealloc (P->opaque);
44 return pj_dealloc(P);
45 }
46
freeup(PJ * P)47 static void freeup (PJ *P) {
48 freeup_new (P);
49 return;
50 }
51
52
PROJECTION(bacon)53 PJ *PROJECTION(bacon) {
54 struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
55 if (0==Q)
56 return freeup_new (P);
57 P->opaque = Q;
58
59 Q->bacn = 1;
60 Q->ortl = 0;
61 P->es = 0.;
62 P->fwd = s_forward;
63 return P;
64 }
65
66
PROJECTION(apian)67 PJ *PROJECTION(apian) {
68 struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
69 if (0==Q)
70 return freeup_new (P);
71 P->opaque = Q;
72
73 Q->bacn = Q->ortl = 0;
74 P->es = 0.;
75 P->fwd = s_forward;
76 return P;
77 }
78
79
PROJECTION(ortel)80 PJ *PROJECTION(ortel) {
81 struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
82 if (0==Q)
83 return freeup_new (P);
84 P->opaque = Q;
85
86 Q->bacn = 0;
87 Q->ortl = 1;
88 P->es = 0.;
89 P->fwd = s_forward;
90 return P;
91 }
92
93
94 #ifndef PJ_SELFTEST
pj_bacon_selftest(void)95 int pj_bacon_selftest (void) {return 0;}
96 #else
pj_bacon_selftest(void)97 int pj_bacon_selftest (void) {
98 double tolerance_lp = 1e-10;
99 double tolerance_xy = 1e-7;
100
101 char s_args[] = {"+proj=bacon +a=6400000 +lat_1=0 +lat_2=2"};
102
103 LP fwd_in[] = {
104 { 2, 1},
105 { 2,-1},
106 {-2, 1},
107 {-2,-1}
108 };
109
110 XY s_fwd_expect[] = {
111 {223334.13255596498, 175450.72592266591},
112 {223334.13255596498, -175450.72592266591},
113 {-223334.13255596498, 175450.72592266591},
114 {-223334.13255596498, -175450.72592266591},
115 };
116
117 return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 0, fwd_in, 0, s_fwd_expect, 0, 0, 0);
118 }
119 #endif
120
121
122
123
124 #ifndef PJ_SELFTEST
pj_apian_selftest(void)125 int pj_apian_selftest (void) {return 0;}
126 #else
pj_apian_selftest(void)127 int pj_apian_selftest (void) {
128 double tolerance_lp = 1e-10;
129 double tolerance_xy = 1e-7;
130
131 char s_args[] = {"+proj=apian +a=6400000 +lat_1=0 +lat_2=2"};
132
133 LP fwd_in[] = {
134 { 2, 1},
135 { 2,-1},
136 {-2, 1},
137 {-2,-1}
138 };
139
140 XY s_fwd_expect[] = {
141 { 223374.57735525275, 111701.07212763709},
142 { 223374.57735525275, -111701.07212763709},
143 {-223374.57735525275, 111701.07212763709},
144 {-223374.57735525275, -111701.07212763709},
145 };
146
147 return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 0, fwd_in, 0, s_fwd_expect, 0, 0, 0);
148 }
149 #endif
150
151
152
153
154 #ifndef PJ_SELFTEST
pj_ortel_selftest(void)155 int pj_ortel_selftest (void) {return 0;}
156 #else
pj_ortel_selftest(void)157 int pj_ortel_selftest (void) {
158 double tolerance_lp = 1e-10;
159 double tolerance_xy = 1e-7;
160
161 char s_args[] = {"+proj=ortel +a=6400000 +lat_1=0 +lat_2=2"};
162
163 LP fwd_in[] = {
164 { 2, 1},
165 { 2,-1},
166 {-2, 1},
167 {-2,-1}
168 };
169
170 XY s_fwd_expect[] = {
171 { 223374.57735525275, 111701.07212763709},
172 { 223374.57735525275, -111701.07212763709},
173 {-223374.57735525275, 111701.07212763709},
174 {-223374.57735525275, -111701.07212763709},
175 };
176 return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 0, fwd_in, 0, s_fwd_expect, 0, 0, 0);
177 }
178 #endif
179
180