Skip to content

Commit

Permalink
Portability cleanups for the code in PR OSGeo#5
Browse files Browse the repository at this point in the history
Eliminated load time non-constant initializers, mixed code/declarations
and C++ style comments.

A lot of non-constant initializers remain in PJ_healpix. Should probably
be handled before next release.
  • Loading branch information
Thomas Knudsen authored and Thomas Knudsen committed Apr 20, 2016
1 parent 7a4841d commit 9687e69
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 65 deletions.
18 changes: 6 additions & 12 deletions src/PJ_goode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph.";
#define Y_COR 0.05280
#define PHI_LIM 0.71093078197902358062

C_NAMESPACE PJ *pj_sinu(PJ *), *pj_moll(PJ *);

struct pj_opaque {
struct PJconsts *sinu; \
struct PJconsts *moll;
PJ *sinu;
PJ *moll;
};


Expand Down Expand Up @@ -101,11 +103,7 @@ int pj_goode_selftest (void) {
};

XY s_fwd_expect[] = {
{ 223368.11902663155, 111701.07212763709},
{ 223368.11902663155, -111701.07212763709},
{-223368.11902663155, 111701.07212763709},
{-223368.11902663155, -111701.07212763709},
};
{ 223368.11902663155, 111701.07212763709}, { 223368.11902663155, -111701.07212763709}, {-223368.11902663155, 111701.07212763709}, {-223368.11902663155, -111701.07212763709}, };

XY inv_in[] = {
{ 200, 100},
Expand All @@ -115,11 +113,7 @@ int pj_goode_selftest (void) {
};

LP s_inv_expect[] = {
{ 0.0017904931100023887, 0.00089524655489191132},
{ 0.0017904931100023887, -0.00089524655489191132},
{-0.0017904931100023887, 0.00089524655489191132},
{-0.0017904931100023887, -0.00089524655489191132},
};
{ 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/PJ_healpix.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ static XY s_rhealpix_forward(LP lp, PJ *P) { /* sphere */

static XY e_rhealpix_forward(LP lp, PJ *P) { /* ellipsoid */
struct pj_opaque *Q = P->opaque;

XY xy;
lp.phi = auth_lat(P, lp.phi, 0);
XY xy = healpix_sphere(lp);
xy = healpix_sphere(lp);
return combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 0);
}

Expand Down
96 changes: 52 additions & 44 deletions src/PJ_igh.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
PROJ_HEAD(igh, "Interrupted Goode Homolosine") "\n\tPCyl, Sph.";

C_NAMESPACE PJ *pj_sinu(PJ *), *pj_moll(PJ *);
static const double d4044118 = (40 + 44/60. + 11.8/3600.) * DEG_TO_RAD; // 40d 44' 11.8" [degrees]

/* 40d 44' 11.8" [degrees] */
/*
static const double d4044118 = (40 + 44/60. + 11.8/3600.) * DEG_TO_RAD;
has been replaced by this define, to eliminate portability issue:
Initializer element not computable at load time
*/
#define d4044118 ((40 + 44/60. + 11.8/3600.) * DEG_TO_RAD)

static const double d10 = 10 * DEG_TO_RAD;
static const double d20 = 20 * DEG_TO_RAD;
Expand All @@ -19,7 +26,7 @@ static const double d140 = 140 * DEG_TO_RAD;
static const double d160 = 160 * DEG_TO_RAD;
static const double d180 = 180 * DEG_TO_RAD;

static const double EPSLN = 1.e-10; // allow a little 'slack' on zone edge positions
static const double EPSLN = 1.e-10; /* allow a little 'slack' on zone edge positions */

struct pj_opaque {
struct PJconsts* pj[12]; \
Expand All @@ -32,23 +39,23 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
struct pj_opaque *Q = P->opaque;
int z;

if (lp.phi >= d4044118) { // 1|2
if (lp.phi >= d4044118) { /* 1|2 */
z = (lp.lam <= -d40 ? 1: 2);
}
else if (lp.phi >= 0) { // 3|4
else if (lp.phi >= 0) { /* 3|4 */
z = (lp.lam <= -d40 ? 3: 4);
}
else if (lp.phi >= -d4044118) { // 5|6|7|8
if (lp.lam <= -d100) z = 5; // 5
else if (lp.lam <= -d20) z = 6; // 6
else if (lp.lam <= d80) z = 7; // 7
else z = 8; // 8
else if (lp.phi >= -d4044118) { /* 5|6|7|8 */
if (lp.lam <= -d100) z = 5; /* 5 */
else if (lp.lam <= -d20) z = 6; /* 6 */
else if (lp.lam <= d80) z = 7; /* 7 */
else z = 8; /* 8 */
}
else { // 9|10|11|12
if (lp.lam <= -d100) z = 9; // 9
else if (lp.lam <= -d20) z = 10; // 10
else if (lp.lam <= d80) z = 11; // 11
else z = 12; // 12
else { /* 9|10|11|12 */
if (lp.lam <= -d100) z = 9; /* 9 */
else if (lp.lam <= -d20) z = 10; /* 10 */
else if (lp.lam <= d80) z = 11; /* 11 */
else z = 12; /* 12 */
}

lp.lam -= Q->pj[z-1]->lam0;
Expand All @@ -63,26 +70,26 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
struct pj_opaque *Q = P->opaque;
const double y90 = Q->dy0 + sqrt(2); // lt=90 corresponds to y=y0+sqrt(2)
const double y90 = Q->dy0 + sqrt(2); /* lt=90 corresponds to y=y0+sqrt(2) */

int z = 0;
if (xy.y > y90+EPSLN || xy.y < -y90+EPSLN) // 0
if (xy.y > y90+EPSLN || xy.y < -y90+EPSLN) /* 0 */
z = 0;
else if (xy.y >= d4044118) // 1|2
else if (xy.y >= d4044118) /* 1|2 */
z = (xy.x <= -d40? 1: 2);
else if (xy.y >= 0) // 3|4
else if (xy.y >= 0) /* 3|4 */
z = (xy.x <= -d40? 3: 4);
else if (xy.y >= -d4044118) { // 5|6|7|8
if (xy.x <= -d100) z = 5; // 5
else if (xy.x <= -d20) z = 6; // 6
else if (xy.x <= d80) z = 7; // 7
else z = 8; // 8
else if (xy.y >= -d4044118) { /* 5|6|7|8 */
if (xy.x <= -d100) z = 5; /* 5 */
else if (xy.x <= -d20) z = 6; /* 6 */
else if (xy.x <= d80) z = 7; /* 7 */
else z = 8; /* 8 */
}
else { // 9|10|11|12
if (xy.x <= -d100) z = 9; // 9
else if (xy.x <= -d20) z = 10; // 10
else if (xy.x <= d80) z = 11; // 11
else z = 12; // 12
else { /* 9|10|11|12 */
if (xy.x <= -d100) z = 9; /* 9 */
else if (xy.x <= -d20) z = 10; /* 10 */
else if (xy.x <= d80) z = 11; /* 11 */
else z = 12; /* 12 */
}

if (z) {
Expand Down Expand Up @@ -113,7 +120,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
case 11: ok = (lp.lam >= -d20-EPSLN && lp.lam <= d80+EPSLN); break;
case 12: ok = (lp.lam >= d80-EPSLN && lp.lam <= d180+EPSLN); break;
}
z = (!ok? 0: z); // projectable?
z = (!ok? 0: z); /* projectable? */
}

if (!z) lp.lam = HUGE_VAL;
Expand All @@ -124,12 +131,12 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */


static void *freeup_new (PJ *P) { /* Destructor */
int i;
if (0==P)
return 0;
if (0==P->opaque)
return pj_dealloc (P);

int i;
for (i = 0; i < 12; ++i) {
if (P->opaque->pj[i])
pj_dealloc(P->opaque->pj[i]);
Expand All @@ -146,11 +153,6 @@ static void freeup (PJ *P) {
}


PJ *PROJECTION(igh) {
struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
if (0==Q)
return freeup_new (P);
P->opaque = Q;

/*
Zones:
Expand Down Expand Up @@ -179,30 +181,36 @@ PJ *PROJECTION(igh) {
Q->pj[n-1]->y0 = y_0; \
Q->pj[n-1]->lam0 = lon_0;


PJ *PROJECTION(igh) {
XY xy1, xy3;
LP lp = { 0, d4044118 };
XY xy1;
XY xy3;
struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
if (0==Q)
return freeup_new (P);
P->opaque = Q;


// sinusoidal zones
/* sinusoidal zones */
SETUP(3, sinu, -d100, 0, -d100);
SETUP(4, sinu, d30, 0, d30);
SETUP(5, sinu, -d160, 0, -d160);
SETUP(6, sinu, -d60, 0, -d60);
SETUP(7, sinu, d20, 0, d20);
SETUP(8, sinu, d140, 0, d140);

// mollweide zones
/* mollweide zones */
SETUP(1, moll, -d100, 0, -d100);

// y0 ?
xy1 = Q->pj[0]->fwd(lp, Q->pj[0]); // zone 1
xy3 = Q->pj[2]->fwd(lp, Q->pj[2]); // zone 3
// y0 + xy1.y = xy3.y for lt = 40d44'11.8"
/* y0 ? */
xy1 = Q->pj[0]->fwd(lp, Q->pj[0]); /* zone 1 */
xy3 = Q->pj[2]->fwd(lp, Q->pj[2]); /* zone 3 */
/* y0 + xy1.y = xy3.y for lt = 40d44'11.8" */
Q->dy0 = xy3.y - xy1.y;

Q->pj[0]->y0 = Q->dy0;

// mollweide zones (cont'd)
/* mollweide zones (cont'd) */
SETUP( 2, moll, d30, Q->dy0, d30);
SETUP( 9, moll, -d160, -Q->dy0, -d160);
SETUP(10, moll, -d60, -Q->dy0, -d60);
Expand Down
5 changes: 2 additions & 3 deletions src/PJ_imw_p.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,13 @@ static void freeup (PJ *P) {


PJ *PROJECTION(imw_p) {
double del, sig, s, t, x1, x2, T2, y1, m1, m2, y2;
int i;
struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
if (0==Q)
return freeup_new (P);
P->opaque = Q;

double del, sig, s, t, x1, x2, T2, y1, m1, m2, y2;
int i;

if (!(Q->en = pj_enfn(P->es))) E_ERROR_0;
if( (i = phi12(P, &del, &sig)) != 0)
E_ERROR(i);
Expand Down
2 changes: 1 addition & 1 deletion src/PJ_isea.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,12 @@ static void freeup (PJ *P) {


PJ *PROJECTION(isea) {
char *opt;
struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
if (0==Q)
return freeup_new (P);
P->opaque = Q;

char *opt;

P->fwd = s_forward;
isea_grid_init(&Q->dgg);
Expand Down
7 changes: 4 additions & 3 deletions src/PJ_krovak.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct pj_opaque {

static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
struct pj_opaque *Q = P->opaque;

/* calculate xy from lat/lon */

/* Constants, identical to inverse transform function */
Expand Down Expand Up @@ -131,7 +131,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */

static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
struct pj_opaque *Q = P->opaque;

/* calculate lat/lon from xy */

/* Constants, identisch wie in der Umkehrfunktion */
Expand Down Expand Up @@ -227,14 +227,15 @@ static void freeup (PJ *P) {


PJ *PROJECTION(krovak) {
double ts;
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_krovak;
double ts;

/* read some Parameters,
* here Latitude Truescale */

Expand Down

0 comments on commit 9687e69

Please sign in to comment.