/src/proj/src/projections/vandg2.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | |
3 | | #include <errno.h> |
4 | | #include <math.h> |
5 | | |
6 | | #include "proj.h" |
7 | | #include "proj_internal.h" |
8 | | |
9 | | namespace { // anonymous namespace |
10 | | struct pj_vandg2 { |
11 | | int vdg3; |
12 | | }; |
13 | | } // anonymous namespace |
14 | | |
15 | | PROJ_HEAD(vandg2, "van der Grinten II") "\n\tMisc Sph, no inv"; |
16 | | PROJ_HEAD(vandg3, "van der Grinten III") "\n\tMisc Sph, no inv"; |
17 | | |
18 | 0 | #define TOL 1e-10 |
19 | | |
20 | 0 | static PJ_XY vandg2_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ |
21 | 0 | PJ_XY xy = {0.0, 0.0}; |
22 | 0 | struct pj_vandg2 *Q = static_cast<struct pj_vandg2 *>(P->opaque); |
23 | 0 | double x1, at, bt, ct; |
24 | |
|
25 | 0 | bt = fabs(M_TWO_D_PI * lp.phi); |
26 | 0 | ct = 1. - bt * bt; |
27 | 0 | if (ct < 0.) |
28 | 0 | ct = 0.; |
29 | 0 | else |
30 | 0 | ct = sqrt(ct); |
31 | 0 | if (fabs(lp.lam) < TOL) { |
32 | 0 | xy.x = 0.; |
33 | 0 | xy.y = M_PI * (lp.phi < 0. ? -bt : bt) / (1. + ct); |
34 | 0 | } else { |
35 | 0 | at = 0.5 * fabs(M_PI / lp.lam - lp.lam / M_PI); |
36 | 0 | if (Q->vdg3) { |
37 | 0 | x1 = bt / (1. + ct); |
38 | 0 | xy.x = M_PI * (sqrt(at * at + 1. - x1 * x1) - at); |
39 | 0 | xy.y = M_PI * x1; |
40 | 0 | } else { |
41 | 0 | x1 = (ct * sqrt(1. + at * at) - at * ct * ct) / |
42 | 0 | (1. + at * at * bt * bt); |
43 | 0 | xy.x = M_PI * x1; |
44 | 0 | xy.y = M_PI * sqrt(1. - x1 * (x1 + 2. * at) + TOL); |
45 | 0 | } |
46 | 0 | if (lp.lam < 0.) |
47 | 0 | xy.x = -xy.x; |
48 | 0 | if (lp.phi < 0.) |
49 | 0 | xy.y = -xy.y; |
50 | 0 | } |
51 | |
|
52 | 0 | return xy; |
53 | 0 | } |
54 | | |
55 | 0 | PJ *PJ_PROJECTION(vandg2) { |
56 | 0 | struct pj_vandg2 *Q = |
57 | 0 | static_cast<struct pj_vandg2 *>(calloc(1, sizeof(struct pj_vandg2))); |
58 | 0 | if (nullptr == Q) |
59 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
60 | 0 | P->opaque = Q; |
61 | |
|
62 | 0 | Q->vdg3 = 0; |
63 | 0 | P->fwd = vandg2_s_forward; |
64 | |
|
65 | 0 | return P; |
66 | 0 | } |
67 | | |
68 | 0 | PJ *PJ_PROJECTION(vandg3) { |
69 | 0 | struct pj_vandg2 *Q = |
70 | 0 | static_cast<struct pj_vandg2 *>(calloc(1, sizeof(struct pj_vandg2))); |
71 | 0 | if (nullptr == Q) |
72 | 0 | return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); |
73 | 0 | P->opaque = Q; |
74 | |
|
75 | 0 | Q->vdg3 = 1; |
76 | 0 | P->es = 0.; |
77 | 0 | P->fwd = vandg2_s_forward; |
78 | |
|
79 | 0 | return P; |
80 | 0 | } |
81 | | |
82 | | #undef TOL |