aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2016-04-19 09:37:35 +0200
committerKristian Evers <kristianevers@gmail.com>2016-04-19 09:37:35 +0200
commiteca42acae89ad5892cb14a29ae7be46891e5c059 (patch)
treef4a68c0d9c46eac476c33010cf45b7e1472a9224 /src
parent0d0f7dbc29d464d555ac37000e80f17476bcce84 (diff)
downloadPROJ-eca42acae89ad5892cb14a29ae7be46891e5c059.tar.gz
PROJ-eca42acae89ad5892cb14a29ae7be46891e5c059.zip
Converted goode
Diffstat (limited to 'src')
-rw-r--r--src/PJ_aea.c1
-rw-r--r--src/PJ_goode.c177
2 files changed, 128 insertions, 50 deletions
diff --git a/src/PJ_aea.c b/src/PJ_aea.c
index 539f829a..de3d6c03 100644
--- a/src/PJ_aea.c
+++ b/src/PJ_aea.c
@@ -359,7 +359,6 @@ int pj_eqc_selftest (void) {return 10000;}
int pj_eqdc_selftest (void) {return 10000;}
int pj_etmerc_selftest (void) {return 10000;}
int pj_geocent_selftest (void) {return 10000;}
-int pj_goode_selftest (void) {return 10000;}
int pj_gs48_selftest (void) {return 10000;}
int pj_gs50_selftest (void) {return 10000;}
int pj_hammer_selftest (void) {return 10000;}
diff --git a/src/PJ_goode.c b/src/PJ_goode.c
index b03e15d1..d577f901 100644
--- a/src/PJ_goode.c
+++ b/src/PJ_goode.c
@@ -1,49 +1,128 @@
-#define PROJ_PARMS__ \
- struct PJconsts *sinu; \
- struct PJconsts *moll;
-#define PJ_LIB__
-#include <projects.h>
-PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph.";
- C_NAMESPACE PJ
-*pj_sinu(PJ *), *pj_moll(PJ *);
-#define Y_COR 0.05280
-#define PHI_LIM .71093078197902358062
-FORWARD(s_forward); /* spheroid */
- if (fabs(lp.phi) <= PHI_LIM)
- xy = P->sinu->fwd(lp, P->sinu);
- else {
- xy = P->moll->fwd(lp, P->moll);
- xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR;
- }
- return (xy);
-}
-INVERSE(s_inverse); /* spheroid */
- if (fabs(xy.y) <= PHI_LIM)
- lp = P->sinu->inv(xy, P->sinu);
- else {
- xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR;
- lp = P->moll->inv(xy, P->moll);
- }
- return (lp);
-}
-FREEUP;
- if (P) {
- if (P->sinu)
- (*(P->sinu->pfree))(P->sinu);
- if (P->moll)
- (*(P->moll->pfree))(P->moll);
- pj_dalloc(P);
- }
-}
-ENTRY2(goode, sinu, moll)
- P->es = 0.;
- if (!(P->sinu = pj_sinu(0)) || !(P->moll = pj_moll(0)))
- E_ERROR_0;
- P->sinu->es = 0.;
- P->sinu->ctx = P->ctx;
- P->moll->ctx = P->ctx;
- if (!(P->sinu = pj_sinu(P->sinu)) || !(P->moll = pj_moll(P->moll)))
- E_ERROR_0;
- P->fwd = s_forward;
- P->inv = s_inverse;
-ENDENTRY(P)
+#define PJ_LIB__
+#include <projects.h>
+
+PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph.";
+
+#define Y_COR 0.05280
+#define PHI_LIM 0.71093078197902358062
+
+struct pj_opaque {
+ struct PJconsts *sinu; \
+ struct PJconsts *moll;
+};
+
+
+static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
+ XY xy = {0.0,0.0};
+ struct pj_opaque *Q = P->opaque;
+
+ if (fabs(lp.phi) <= PHI_LIM)
+ xy = Q->sinu->fwd(lp, Q->sinu);
+ else {
+ xy = Q->moll->fwd(lp, Q->moll);
+ xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR;
+ }
+ return xy;
+}
+
+
+static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
+ LP lp = {0.0,0.0};
+ struct pj_opaque *Q = P->opaque;
+
+ if (fabs(xy.y) <= PHI_LIM)
+ lp = Q->sinu->inv(xy, Q->sinu);
+ else {
+ xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR;
+ lp = Q->moll->inv(xy, Q->moll);
+ }
+ return lp;
+}
+
+
+static void *freeup_new (PJ *P) { /* Destructor */
+ if (0==P)
+ return 0;
+ if (0==P->opaque)
+ return pj_dealloc(P);
+ if (P->opaque->sinu)
+ pj_dealloc(P->opaque->sinu);
+ if (P->opaque->moll)
+ pj_dealloc(P->opaque->moll);
+ pj_dealloc (P->opaque);
+ return pj_dealloc(P);
+
+}
+
+
+static void freeup (PJ *P) {
+ freeup_new (P);
+ return;
+}
+
+
+PJ *PROJECTION(goode) {
+ struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
+ if (0==Q)
+ return freeup_new (P);
+ P->opaque = Q;
+
+ P->es = 0.;
+ if (!(Q->sinu = pj_sinu(0)) || !(Q->moll = pj_moll(0)))
+ E_ERROR_0;
+ Q->sinu->es = 0.;
+ Q->sinu->ctx = P->ctx;
+ Q->moll->ctx = P->ctx;
+ if (!(Q->sinu = pj_sinu(Q->sinu)) || !(Q->moll = pj_moll(Q->moll)))
+ E_ERROR_0;
+
+ P->fwd = s_forward;
+ P->inv = s_inverse;
+
+ return P;
+}
+
+
+#ifdef PJ_OMIT_SELFTEST
+int pj_goode_selftest (void) {return 0;}
+#else
+
+int pj_goode_selftest (void) {
+ double tolerance_lp = 1e-10;
+ double tolerance_xy = 1e-7;
+
+ char s_args[] = {"+proj=goode +a=6400000 +lat_1=0.5 +lat_2=2"};
+
+ LP fwd_in[] = {
+ { 2, 1},
+ { 2,-1},
+ {-2, 1},
+ {-2,-1}
+ };
+
+ XY s_fwd_expect[] = {
+ { 223368.11902663155, 111701.07212763709 },
+ { 223368.11902663155, -111701.07212763709 },
+ {-223368.11902663155, 111701.07212763709 },
+ {-223368.11902663155, -111701.07212763709 },
+ };
+
+ XY inv_in[] = {
+ { 200, 100},
+ { 200,-100},
+ {-200, 100},
+ {-200,-100}
+ };
+
+ LP s_inv_expect[] = {
+ { 0.0017904931100023887, 0.00089524655489191132 },
+ { 0.0017904931100023887, -0.00089524655489191132 },
+ {-0.0017904931100023887, 0.00089524655489191132 },
+ {-0.0017904931100023887, -0.00089524655489191132 },
+ };
+
+ 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