aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Puchert <aaron.puchert@sap.com>2017-11-06 17:52:29 +0100
committerAaron Puchert <aaron.puchert@sap.com>2017-11-06 18:04:54 +0100
commitc0c95e33abf2f724e5827cbf41ede41e2939e188 (patch)
treee14c3a6ce8322d3185670ce51d7a376152c25678
parente7e86d14f86eb66365d6aa725c5e9b496b3ba7f7 (diff)
downloadPROJ-c0c95e33abf2f724e5827cbf41ede41e2939e188.tar.gz
PROJ-c0c95e33abf2f724e5827cbf41ede41e2939e188.zip
Use enumerations where appropriate
Enumerations have the following advantages over #define: - they clearly connect a variable and the allowed constants, - the meaning of code is not obfuscated by integer values, - they are visible to the compiler, which can warn about (possibly) incorrect usage. There should be no functional change.
-rw-r--r--src/PJ_aeqd.c14
-rw-r--r--src/PJ_airy.c14
-rw-r--r--src/PJ_aitoff.c17
-rw-r--r--src/PJ_gnom.c13
-rw-r--r--src/PJ_imw_p.c24
-rw-r--r--src/PJ_laea.c13
-rw-r--r--src/PJ_nsper.c13
-rw-r--r--src/PJ_ortho.c13
-rw-r--r--src/PJ_qsc.c34
-rw-r--r--src/PJ_sconics.c21
-rw-r--r--src/PJ_stere.c13
11 files changed, 113 insertions, 76 deletions
diff --git a/src/PJ_aeqd.c b/src/PJ_aeqd.c
index f0c813f5..aa1597e4 100644
--- a/src/PJ_aeqd.c
+++ b/src/PJ_aeqd.c
@@ -31,6 +31,13 @@
#include <errno.h>
#include "projects.h"
+enum Mode {
+ N_POLE = 0,
+ S_POLE = 1,
+ EQUIT = 2,
+ OBLIQ = 3,
+};
+
struct pj_opaque {
double sinph0;
double cosph0;
@@ -40,7 +47,7 @@ struct pj_opaque {
double Mp;
double He;
double G;
- int mode;
+ enum Mode mode;
struct geod_geodesic g;
};
@@ -49,11 +56,6 @@ PROJ_HEAD(aeqd, "Azimuthal Equidistant") "\n\tAzi, Sph&Ell\n\tlat_0 guam";
#define EPS10 1.e-10
#define TOL 1.e-14
-#define N_POLE 0
-#define S_POLE 1
-#define EQUIT 2
-#define OBLIQ 3
-
static void *destructor (PJ *P, int errlev) { /* Destructor */
if (0==P)
diff --git a/src/PJ_airy.c b/src/PJ_airy.c
index a5ee1f24..3b145475 100644
--- a/src/PJ_airy.c
+++ b/src/PJ_airy.c
@@ -34,22 +34,24 @@
PROJ_HEAD(airy, "Airy") "\n\tMisc Sph, no inv.\n\tno_cut lat_b=";
+enum Mode {
+ N_POLE = 0,
+ S_POLE = 1,
+ EQUIT = 2,
+ OBLIQ = 3,
+};
+
struct pj_opaque {
double p_halfpi;
double sinph0;
double cosph0;
double Cb;
- int mode;
+ enum Mode mode;
int no_cut; /* do not cut at hemisphere limit */
};
# define EPS 1.e-10
-# define N_POLE 0
-# define S_POLE 1
-# define EQUIT 2
-# define OBLIQ 3
-
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
diff --git a/src/PJ_aitoff.c b/src/PJ_aitoff.c
index 8e9201d0..4e2f2092 100644
--- a/src/PJ_aitoff.c
+++ b/src/PJ_aitoff.c
@@ -34,9 +34,14 @@
#include "projects.h"
+enum Mode {
+ AITOFF = 0,
+ WINKEL_TRIPEL = 1
+};
+
struct pj_opaque {
double cosphi1;
- int mode;
+ enum Mode mode;
};
@@ -60,7 +65,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
xy.y *= d * sin(lp.phi);
} else
xy.x = xy.y = 0.;
- if (Q->mode) { /* Winkel Tripel */
+ if (Q->mode == WINKEL_TRIPEL) {
xy.x = (xy.x + lp.lam * Q->cosphi1) * 0.5;
xy.y = (xy.y + lp.phi) * 0.5;
}
@@ -112,7 +117,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
f1l = cp * cp * sl * sl / C + D * cp * cl * sp * sp;
f2p = sp * sp * cl / C + D * sl * sl * cp;
f2l = 0.5 * (sp * cp * sl / C - D * sp * cp * cp * sl * cl);
- if (Q->mode) { /* Winkel Tripel */
+ if (Q->mode == WINKEL_TRIPEL) {
f1 = 0.5 * (f1 + lp.lam * Q->cosphi1);
f2 = 0.5 * (f2 + lp.phi);
f1p *= 0.5;
@@ -128,7 +133,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
} while ((fabs(dp) > EPSILON || fabs(dl) > EPSILON) && (iter++ < MAXITER));
if (lp.phi > M_PI_2) lp.phi -= 2.*(lp.phi-M_PI_2); /* correct if symmetrical solution for Aitoff */
if (lp.phi < -M_PI_2) lp.phi -= 2.*(lp.phi+M_PI_2); /* correct if symmetrical solution for Aitoff */
- if ((fabs(fabs(lp.phi) - M_PI_2) < EPSILON) && (!Q->mode)) lp.lam = 0.; /* if pole in Aitoff, return longitude of 0 */
+ if ((fabs(fabs(lp.phi) - M_PI_2) < EPSILON) && (Q->mode == AITOFF)) lp.lam = 0.; /* if pole in Aitoff, return longitude of 0 */
/* calculate x,y coordinates with solution obtained */
if((D = acos(cos(lp.phi) * cos(C = 0.5 * lp.lam))) != 0.0) {/* Aitoff */
@@ -167,7 +172,7 @@ PJ *PROJECTION(aitoff) {
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
- Q->mode = 0;
+ Q->mode = AITOFF;
return setup(P);
}
@@ -178,7 +183,7 @@ PJ *PROJECTION(wintri) {
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
- Q->mode = 1;
+ Q->mode = WINKEL_TRIPEL;
if (pj_param(P->ctx, P->params, "tlat_1").i) {
if ((Q->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_1").f)) == 0.)
return pj_default_destructor (P, PJD_ERR_LAT_LARGER_THAN_90);
diff --git a/src/PJ_gnom.c b/src/PJ_gnom.c
index 2aedefec..e5822f4f 100644
--- a/src/PJ_gnom.c
+++ b/src/PJ_gnom.c
@@ -6,15 +6,18 @@
PROJ_HEAD(gnom, "Gnomonic") "\n\tAzi, Sph.";
#define EPS10 1.e-10
-#define N_POLE 0
-#define S_POLE 1
-#define EQUIT 2
-#define OBLIQ 3
+
+enum Mode {
+ N_POLE = 0,
+ S_POLE = 1,
+ EQUIT = 2,
+ OBLIQ = 3
+};
struct pj_opaque {
double sinph0;
double cosph0;
- int mode;
+ enum Mode mode;
};
diff --git a/src/PJ_imw_p.c b/src/PJ_imw_p.c
index 29ed3457..7fd31fbb 100644
--- a/src/PJ_imw_p.c
+++ b/src/PJ_imw_p.c
@@ -9,11 +9,17 @@ PROJ_HEAD(imw_p, "International Map of the World Polyconic")
#define TOL 1e-10
#define EPS 1e-10
+enum Mode {
+ NONE_IS_ZERO = 0, /* phi_1 and phi_2 != 0 */
+ PHI_1_IS_ZERO = 1, /* phi_1 = 0 */
+ PHI_2_IS_ZERO = -1 /* phi_2 = 0 */
+};
+
struct pj_opaque {
- double P, Pp, Q, Qp, R_1, R_2, sphi_1, sphi_2, C2; \
- double phi_1, phi_2, lam_1; \
- double *en; \
- int mode; /* = 0, phi_1 and phi_2 != 0, = 1, phi_1 = 0, = -1 phi_2 = 0 */
+ double P, Pp, Q, Qp, R_1, R_2, sphi_1, sphi_2, C2;
+ double phi_1, phi_2, lam_1;
+ double *en;
+ enum Mode mode;
};
@@ -53,7 +59,7 @@ static XY loc_for(LP lp, PJ *P, double *yc) {
C = sqrt(R * R - xa * xa);
if (lp.phi < 0.) C = - C;
C += ya - R;
- if (Q->mode < 0) {
+ if (Q->mode == PHI_2_IS_ZERO) {
xb = lp.lam;
yb = Q->C2;
} else {
@@ -61,7 +67,7 @@ static XY loc_for(LP lp, PJ *P, double *yc) {
xb = Q->R_2 * sin(t);
yb = Q->C2 + Q->R_2 * (1. - cos(t));
}
- if (Q->mode > 0) {
+ if (Q->mode == PHI_1_IS_ZERO) {
xc = lp.lam;
*yc = 0.;
} else {
@@ -171,18 +177,18 @@ PJ *PROJECTION(imw_p) {
else sig = 8.;
Q->lam_1 = sig * DEG_TO_RAD;
}
- Q->mode = 0;
+ Q->mode = NONE_IS_ZERO;
if (Q->phi_1 != 0.0)
xy(P, Q->phi_1, &x1, &y1, &Q->sphi_1, &Q->R_1);
else {
- Q->mode = 1;
+ Q->mode = PHI_1_IS_ZERO;
y1 = 0.;
x1 = Q->lam_1;
}
if (Q->phi_2 != 0.0)
xy(P, Q->phi_2, &x2, &T2, &Q->sphi_2, &Q->R_2);
else {
- Q->mode = -1;
+ Q->mode = PHI_2_IS_ZERO;
T2 = 0.;
x2 = Q->lam_1;
}
diff --git a/src/PJ_laea.c b/src/PJ_laea.c
index 270b8dc8..0c5d5db9 100644
--- a/src/PJ_laea.c
+++ b/src/PJ_laea.c
@@ -5,6 +5,13 @@
PROJ_HEAD(laea, "Lambert Azimuthal Equal Area") "\n\tAzi, Sph&Ell";
+enum Mode {
+ N_POLE = 0,
+ S_POLE = 1,
+ EQUIT = 2,
+ OBLIQ = 3
+};
+
struct pj_opaque {
double sinb1;
double cosb1;
@@ -15,16 +22,12 @@ struct pj_opaque {
double dd;
double rq;
double *apa;
- int mode;
+ enum Mode mode;
};
#define EPS10 1.e-10
#define NITER 20
#define CONV 1.e-10
-#define N_POLE 0
-#define S_POLE 1
-#define EQUIT 2
-#define OBLIQ 3
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
diff --git a/src/PJ_nsper.c b/src/PJ_nsper.c
index 4975bb17..6c8ef74a 100644
--- a/src/PJ_nsper.c
+++ b/src/PJ_nsper.c
@@ -3,6 +3,13 @@
#include <proj.h>
#include "projects.h"
+enum Mode {
+ N_POLE = 0,
+ S_POLE = 1,
+ EQUIT = 2,
+ OBLIQ = 3
+};
+
struct pj_opaque {
double height;
double sinph0;
@@ -16,7 +23,7 @@ struct pj_opaque {
double sg;
double sw;
double cw;
- int mode;
+ enum Mode mode;
int tilt;
};
@@ -24,10 +31,6 @@ PROJ_HEAD(nsper, "Near-sided perspective") "\n\tAzi, Sph\n\th=";
PROJ_HEAD(tpers, "Tilted perspective") "\n\tAzi, Sph\n\ttilt= azi= h=";
# define EPS10 1.e-10
-# define N_POLE 0
-# define S_POLE 1
-# define EQUIT 2
-# define OBLIQ 3
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
diff --git a/src/PJ_ortho.c b/src/PJ_ortho.c
index 3179189b..14e228f7 100644
--- a/src/PJ_ortho.c
+++ b/src/PJ_ortho.c
@@ -5,17 +5,20 @@
PROJ_HEAD(ortho, "Orthographic") "\n\tAzi, Sph.";
+enum Mode {
+ N_POLE = 0,
+ S_POLE = 1,
+ EQUIT = 2,
+ OBLIQ = 3
+};
+
struct pj_opaque {
double sinph0;
double cosph0;
- int mode;
+ enum Mode mode;
};
#define EPS10 1.e-10
-#define N_POLE 0
-#define S_POLE 1
-#define EQUIT 2
-#define OBLIQ 3
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
diff --git a/src/PJ_qsc.c b/src/PJ_qsc.c
index f8c760a9..f30a7048 100644
--- a/src/PJ_qsc.c
+++ b/src/PJ_qsc.c
@@ -42,8 +42,18 @@
#include <errno.h>
#include "projects.h"
+/* The six cube faces. */
+enum Face {
+ FACE_FRONT = 0,
+ FACE_RIGHT = 1,
+ FACE_BACK = 2,
+ FACE_LEFT = 3,
+ FACE_TOP = 4,
+ FACE_BOTTOM = 5
+};
+
struct pj_opaque {
- int face;
+ enum Face face;
double a_squared;
double b;
double one_minus_f;
@@ -53,24 +63,18 @@ PROJ_HEAD(qsc, "Quadrilateralized Spherical Cube") "\n\tAzi, Sph.";
#define EPS10 1.e-10
-/* The six cube faces. */
-#define FACE_FRONT 0
-#define FACE_RIGHT 1
-#define FACE_BACK 2
-#define FACE_LEFT 3
-#define FACE_TOP 4
-#define FACE_BOTTOM 5
-
/* The four areas on a cube face. AREA_0 is the area of definition,
* the other three areas are counted counterclockwise. */
-#define AREA_0 0
-#define AREA_1 1
-#define AREA_2 2
-#define AREA_3 3
+enum Area {
+ AREA_0 = 0,
+ AREA_1 = 1,
+ AREA_2 = 2,
+ AREA_3 = 3
+};
/* Helper function for forward projection: compute the theta angle
* and determine the area number. */
-static double qsc_fwd_equat_face_theta(double phi, double y, double x, int *area) {
+static double qsc_fwd_equat_face_theta(double phi, double y, double x, enum Area *area) {
double theta;
if (phi < EPS10) {
*area = AREA_0;
@@ -111,7 +115,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
double lat, lon;
double theta, phi;
double t, mu; /* nu; */
- int area;
+ enum Area area;
/* Convert the geodetic latitude to a geocentric latitude.
* This corresponds to the shift from the ellipsoid to the sphere
diff --git a/src/PJ_sconics.c b/src/PJ_sconics.c
index 7f6e094c..b434c430 100644
--- a/src/PJ_sconics.c
+++ b/src/PJ_sconics.c
@@ -4,23 +4,26 @@
#include "projects.h"
+enum Type {
+ EULER = 0,
+ MURD1 = 1,
+ MURD2 = 2,
+ MURD3 = 3,
+ PCONIC = 4,
+ TISSOT = 5,
+ VITK1 = 6
+};
+
struct pj_opaque {
double n;
double rho_c;
double rho_0;
double sig;
double c1, c2;
- int type;
+ enum Type type;
};
-#define EULER 0
-#define MURD1 1
-#define MURD2 2
-#define MURD3 3
-#define PCONIC 4
-#define TISSOT 5
-#define VITK1 6
#define EPS10 1.e-10
#define EPS 1e-10
#define LINE2 "\n\tConic, Sph\n\tlat_1= and lat_2="
@@ -106,7 +109,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, (and ellipsoidal?) inverse
}
-static PJ *setup(PJ *P, int type) {
+static PJ *setup(PJ *P, enum Type type) {
double del, cs;
int err;
struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
diff --git a/src/PJ_stere.c b/src/PJ_stere.c
index 02b73507..500b512d 100644
--- a/src/PJ_stere.c
+++ b/src/PJ_stere.c
@@ -7,12 +7,19 @@ PROJ_HEAD(stere, "Stereographic") "\n\tAzi, Sph&Ell\n\tlat_ts=";
PROJ_HEAD(ups, "Universal Polar Stereographic") "\n\tAzi, Sph&Ell\n\tsouth";
+enum Mode {
+ S_POLE = 0,
+ N_POLE = 1,
+ OBLIQ = 2,
+ EQUIT = 3
+};
+
struct pj_opaque {
double phits;
double sinX1;
double cosX1;
double akm1;
- int mode;
+ enum Mode mode;
};
#define sinph0 P->opaque->sinX1
@@ -21,10 +28,6 @@ struct pj_opaque {
#define TOL 1.e-8
#define NITER 8
#define CONV 1.e-10
-#define S_POLE 0
-#define N_POLE 1
-#define OBLIQ 2
-#define EQUIT 3
static double ssfn_ (double phit, double sinphi, double eccen) {
sinphi *= eccen;