aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2016-05-02 18:05:52 +0200
committerKristian Evers <kristianevers@gmail.com>2016-05-02 18:05:52 +0200
commit70f936b29189c07d4dc50044f7bcc1ff4f8612a8 (patch)
tree505e5c64f0658e892917157d31d4c504a13d00dc /src
parent359c182fa6f4d834192bb01b0f8170bc2b306247 (diff)
downloadPROJ-70f936b29189c07d4dc50044f7bcc1ff4f8612a8.tar.gz
PROJ-70f936b29189c07d4dc50044f7bcc1ff4f8612a8.zip
Converted oea. And removed parentheses in return statements in ocea.
Diffstat (limited to 'src')
-rw-r--r--src/PJ_aea.c1
-rw-r--r--src/PJ_ocea.c4
-rw-r--r--src/PJ_oea.c152
3 files changed, 120 insertions, 37 deletions
diff --git a/src/PJ_aea.c b/src/PJ_aea.c
index ddf92a45..aadefd89 100644
--- a/src/PJ_aea.c
+++ b/src/PJ_aea.c
@@ -365,7 +365,6 @@ int pj_lonlat_selftest (void) {return 10000;}
int pj_longlat_selftest (void) {return 10000;}
int pj_ob_tran_selftest (void) {return 10000;}
-int pj_oea_selftest (void) {return 10000;}
int pj_omerc_selftest (void) {return 10000;}
int pj_ortho_selftest (void) {return 10000;}
int pj_patterson_selftest (void) {return 10000;}
diff --git a/src/PJ_ocea.c b/src/PJ_ocea.c
index 4727b09a..72414e7f 100644
--- a/src/PJ_ocea.c
+++ b/src/PJ_ocea.c
@@ -26,7 +26,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
xy.x += PI;
xy.x *= Q->rtk;
xy.y = Q->rok * (Q->sinphi * sin(lp.phi) - Q->cosphi * cos(lp.phi) * xy.y);
- return (xy);
+ return xy;
}
@@ -41,7 +41,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
lp.phi = asin(xy.y * Q->sinphi + t * Q->cosphi * (s = sin(xy.x)));
lp.lam = atan2(t * Q->sinphi * s - xy.y * Q->cosphi,
t * cos(xy.x));
- return (lp);
+ return lp;
}
diff --git a/src/PJ_oea.c b/src/PJ_oea.c
index b84a7ea6..50ab6b52 100644
--- a/src/PJ_oea.c
+++ b/src/PJ_oea.c
@@ -1,58 +1,142 @@
-#define PROJ_PARMS__ \
- double theta; \
- double m, n; \
- double two_r_m, two_r_n, rm, rn, hm, hn; \
- double cp0, sp0;
#define PJ_LIB__
#include <projects.h>
+
PROJ_HEAD(oea, "Oblated Equal Area") "\n\tMisc Sph\n\tn= m= theta=";
-FORWARD(s_forward); /* sphere */
+
+struct pj_opaque {
+ double theta;
+ double m, n;
+ double two_r_m, two_r_n, rm, rn, hm, hn;
+ double cp0, sp0;
+};
+
+
+static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
+ XY xy = {0.0,0.0};
+ struct pj_opaque *Q = P->opaque;
double Az, M, N, cp, sp, cl, shz;
cp = cos(lp.phi);
sp = sin(lp.phi);
cl = cos(lp.lam);
- Az = aatan2(cp * sin(lp.lam), P->cp0 * sp - P->sp0 * cp * cl) + P->theta;
- shz = sin(0.5 * aacos(P->ctx, P->sp0 * sp + P->cp0 * cp * cl));
+ Az = aatan2(cp * sin(lp.lam), Q->cp0 * sp - Q->sp0 * cp * cl) + Q->theta;
+ shz = sin(0.5 * aacos(P->ctx, Q->sp0 * sp + Q->cp0 * cp * cl));
M = aasin(P->ctx, shz * sin(Az));
- N = aasin(P->ctx, shz * cos(Az) * cos(M) / cos(M * P->two_r_m));
- xy.y = P->n * sin(N * P->two_r_n);
- xy.x = P->m * sin(M * P->two_r_m) * cos(N) / cos(N * P->two_r_n);
- return (xy);
+ N = aasin(P->ctx, shz * cos(Az) * cos(M) / cos(M * Q->two_r_m));
+ xy.y = Q->n * sin(N * Q->two_r_n);
+ xy.x = Q->m * sin(M * Q->two_r_m) * cos(N) / cos(N * Q->two_r_n);
+
+ return xy;
}
-INVERSE(s_inverse); /* sphere */
+
+
+static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
+ LP lp = {0.0,0.0};
+ struct pj_opaque *Q = P->opaque;
double N, M, xp, yp, z, Az, cz, sz, cAz;
- N = P->hn * aasin(P->ctx,xy.y * P->rn);
- M = P->hm * aasin(P->ctx,xy.x * P->rm * cos(N * P->two_r_n) / cos(N));
+ N = Q->hn * aasin(P->ctx,xy.y * Q->rn);
+ M = Q->hm * aasin(P->ctx,xy.x * Q->rm * cos(N * Q->two_r_n) / cos(N));
xp = 2. * sin(M);
- yp = 2. * sin(N) * cos(M * P->two_r_m) / cos(M);
- cAz = cos(Az = aatan2(xp, yp) - P->theta);
+ yp = 2. * sin(N) * cos(M * Q->two_r_m) / cos(M);
+ cAz = cos(Az = aatan2(xp, yp) - Q->theta);
z = 2. * aasin(P->ctx, 0.5 * hypot(xp, yp));
sz = sin(z);
cz = cos(z);
- lp.phi = aasin(P->ctx, P->sp0 * cz + P->cp0 * sz * cAz);
+ lp.phi = aasin(P->ctx, Q->sp0 * cz + Q->cp0 * sz * cAz);
lp.lam = aatan2(sz * sin(Az),
- P->cp0 * cz - P->sp0 * sz * cAz);
- return (lp);
+ Q->cp0 * cz - Q->sp0 * sz * cAz);
+
+ return lp;
+}
+
+
+static void *freeup_new (PJ *P) { /* Destructor */
+ if (0==P)
+ return 0;
+ if (0==P->opaque)
+ return pj_dealloc (P);
+
+ pj_dealloc (P->opaque);
+ return pj_dealloc(P);
+}
+
+static void freeup (PJ *P) {
+ freeup_new (P);
+ return;
}
-FREEUP; if (P) pj_dalloc(P); }
-ENTRY0(oea)
- if (((P->n = pj_param(P->ctx, P->params, "dn").f) <= 0.) ||
- ((P->m = pj_param(P->ctx, P->params, "dm").f) <= 0.))
+
+
+PJ *PROJECTION(oea) {
+ struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
+ if (0==Q)
+ return freeup_new (P);
+ P->opaque = Q;
+
+ P->pfree = freeup;
+ P->descr = des_oea;
+ if (((Q->n = pj_param(P->ctx, P->params, "dn").f) <= 0.) ||
+ ((Q->m = pj_param(P->ctx, P->params, "dm").f) <= 0.))
E_ERROR(-39)
else {
- P->theta = pj_param(P->ctx, P->params, "rtheta").f;
- P->sp0 = sin(P->phi0);
- P->cp0 = cos(P->phi0);
- P->rn = 1./ P->n;
- P->rm = 1./ P->m;
- P->two_r_n = 2. * P->rn;
- P->two_r_m = 2. * P->rm;
- P->hm = 0.5 * P->m;
- P->hn = 0.5 * P->n;
+ Q->theta = pj_param(P->ctx, P->params, "rtheta").f;
+ Q->sp0 = sin(P->phi0);
+ Q->cp0 = cos(P->phi0);
+ Q->rn = 1./ Q->n;
+ Q->rm = 1./ Q->m;
+ Q->two_r_n = 2. * Q->rn;
+ Q->two_r_m = 2. * Q->rm;
+ Q->hm = 0.5 * Q->m;
+ Q->hn = 0.5 * Q->n;
P->fwd = s_forward;
P->inv = s_inverse;
P->es = 0.;
}
-ENDENTRY(P)
+
+ return P;
+}
+
+
+#ifdef PJ_OMIT_SELFTEST
+int pj_oea_selftest (void) {return 0;}
+#else
+
+int pj_oea_selftest (void) {
+ double tolerance_lp = 1e-10;
+ double tolerance_xy = 1e-7;
+
+ char s_args[] = {"+proj=oea +a=6400000 +lat_1=0.5 +lat_2=2 +n=1 +m=2 +theta=3"};
+
+ LP fwd_in[] = {
+ { 2, 1},
+ { 2,-1},
+ {-2, 1},
+ {-2,-1}
+ };
+
+ XY s_fwd_expect[] = {
+ { 228926.872097864107, 99870.4884300760023},
+ { 217242.584036940476, -123247.885607474513},
+ {-217242.584036940476, 123247.885607474556},
+ {-228926.872097864078, -99870.4884300760168},
+ };
+
+ XY inv_in[] = {
+ { 200, 100},
+ { 200,-100},
+ {-200, 100},
+ {-200,-100}
+ };
+
+ LP s_inv_expect[] = {
+ { 0.0017411857167771369, 0.000987726819566195693},
+ { 0.00183489288577854998, -0.000800312481495174641},
+ {-0.00183489288577854954, 0.000800312481495174966},
+ {-0.00174118571677713712, -0.000987726819566195043},
+ };
+
+ return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 4, fwd_in, 0, s_fwd_expect, inv_in, 0, s_inv_expect);
+}
+
+
+#endif