From b8296cd58aac02c93b1bc13b22c39d5cd76ec84f Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Sat, 12 May 2018 19:37:43 -0700 Subject: ISEA_STATIC -> static As this is a part of PROJ, having these functions possibly not static is confusing. Time to declare this is just a part of PROJ. --- src/PJ_isea.c | 82 +++++++++++++++++------------------------------------------ 1 file changed, 24 insertions(+), 58 deletions(-) diff --git a/src/PJ_isea.c b/src/PJ_isea.c index 750587a3..6751a716 100644 --- a/src/PJ_isea.c +++ b/src/PJ_isea.c @@ -12,24 +12,13 @@ # define M_PI 3.14159265358979323846 #endif -/* - * Proj 4 provides its own entry points into - * the code, so none of the library functions - * need to be global - */ -#define ISEA_STATIC static -#ifndef ISEA_STATIC -#define ISEA_STATIC -#endif - struct hex { int iso; int x, y, z; }; /* y *must* be positive down as the xy /iso conversion assumes this */ -ISEA_STATIC -void hex_xy(struct hex *h) { +static void hex_xy(struct hex *h) { if (!h->iso) return; if (h->x >= 0) { h->y = -h->y - (h->x+1)/2; @@ -40,8 +29,7 @@ void hex_xy(struct hex *h) { h->iso = 0; } -ISEA_STATIC -void hex_iso(struct hex *h) { +static void hex_iso(struct hex *h) { if (h->iso) return; if (h->x >= 0) { @@ -55,8 +43,7 @@ void hex_iso(struct hex *h) { h->iso = 1; } -ISEA_STATIC -void hexbin2(double width, double x, double y, int *i, int *j) { +static void hexbin2(double width, double x, double y, int *i, int *j) { double z, rx, ry, rz; double abs_dx, abs_dy, abs_dz; int ix, iy, iz, s; @@ -102,9 +89,6 @@ void hexbin2(double width, double x, double y, int *i, int *j) { *i = h.x; *j = h.y; } -#ifndef ISEA_STATIC -#define ISEA_STATIC -#endif enum isea_poly { ISEA_NONE, ISEA_ICOSAHEDRON = 20 }; enum isea_topology { ISEA_HEXAGON=6, ISEA_TRIANGLE=3, ISEA_DIAMOND=4 }; @@ -150,7 +134,7 @@ struct snyder_constants { }; /* TODO put these in radians to avoid a later conversion */ -ISEA_STATIC const +static const struct snyder_constants constants[] = { {23.80018260, 62.15458023, 60.0, 3.75, 1.033, 0.968, 5.09, 1.195, 1.0}, {20.07675127, 55.69063953, 54.0, 2.65, 1.030, 0.983, 3.59, 1.141, 1.027}, @@ -177,8 +161,7 @@ struct snyder_constants constants[] = { #define RAD2DEG (180.0/M_PI) #define DEG2RAD (M_PI/180.0) -ISEA_STATIC -struct isea_geo vertex[] = { +static struct isea_geo vertex[] = { {0.0, DEG90}, {DEG180, V_LAT}, {-DEG108, V_LAT}, @@ -253,8 +236,7 @@ az_adjustment(int triangle) /* H = 0.25 R tan g = */ #define TABLE_H 0.1909830056 -ISEA_STATIC -struct isea_pt +static struct isea_pt isea_triangle_xy(int triangle) { struct isea_pt c; @@ -309,8 +291,7 @@ sph_azimuth(double f_lon, double f_lat, double t_lon, double t_lat) #endif /* coord needs to be in radians */ -ISEA_STATIC -int +static int isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) { int i; @@ -501,8 +482,7 @@ isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) * * TODO take a result pointer */ -ISEA_STATIC -struct isea_geo +static struct isea_geo snyder_ctran(struct isea_geo * np, struct isea_geo * pt) { struct isea_geo npt; @@ -547,8 +527,7 @@ snyder_ctran(struct isea_geo * np, struct isea_geo * pt) return npt; } -ISEA_STATIC -struct isea_geo +static struct isea_geo isea_ctran(struct isea_geo * np, struct isea_geo * pt, double lon0) { struct isea_geo npt; @@ -580,8 +559,7 @@ isea_ctran(struct isea_geo * np, struct isea_geo * pt, double lon0) /* fuller's at 5.2454 west, 2.3009 N, adjacent at 7.46658 deg */ -ISEA_STATIC -int +static int isea_grid_init(struct isea_dgg * g) { if (!g) @@ -599,8 +577,7 @@ isea_grid_init(struct isea_dgg * g) return 1; } -ISEA_STATIC -void +static void isea_orient_isea(struct isea_dgg * g) { if (!g) @@ -610,8 +587,7 @@ isea_orient_isea(struct isea_dgg * g) g->o_az = 0.0; } -ISEA_STATIC -void +static void isea_orient_pole(struct isea_dgg * g) { if (!g) @@ -621,8 +597,7 @@ isea_orient_pole(struct isea_dgg * g) g->o_az = 0; } -ISEA_STATIC -int +static int isea_transform(struct isea_dgg * g, struct isea_geo * in, struct isea_pt * out) { @@ -644,8 +619,7 @@ isea_transform(struct isea_dgg * g, struct isea_geo * in, #define DOWNTRI(tri) (((tri - 1) / 5) % 2 == 1) -ISEA_STATIC -void +static void isea_rotate(struct isea_pt * pt, double degrees) { double rad; @@ -663,8 +637,7 @@ isea_rotate(struct isea_pt * pt, double degrees) pt->y = y; } -ISEA_STATIC -int isea_tri_plane(int tri, struct isea_pt *pt, double radius) { +static int isea_tri_plane(int tri, struct isea_pt *pt, double radius) { struct isea_pt tc; /* center of triangle */ if (DOWNTRI(tri)) { @@ -680,8 +653,7 @@ int isea_tri_plane(int tri, struct isea_pt *pt, double radius) { } /* convert projected triangle coords to quad xy coords, return quad number */ -ISEA_STATIC -int +static int isea_ptdd(int tri, struct isea_pt *pt) { int downtri, quad; @@ -697,8 +669,7 @@ isea_ptdd(int tri, struct isea_pt *pt) { return quad; } -ISEA_STATIC -int +static int isea_dddi_ap3odd(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_pt *di) { struct isea_pt v; @@ -776,8 +747,7 @@ isea_dddi_ap3odd(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_p return quad; } -ISEA_STATIC -int +static int isea_dddi(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_pt *di) { struct isea_pt v; double hexwidth; @@ -849,9 +819,8 @@ isea_dddi(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_pt *di) return quad; } -ISEA_STATIC -int isea_ptdi(struct isea_dgg *g, int tri, struct isea_pt *pt, - struct isea_pt *di) { +static int isea_ptdi(struct isea_dgg *g, int tri, struct isea_pt *pt, + struct isea_pt *di) { struct isea_pt v; int quad; @@ -862,8 +831,7 @@ int isea_ptdi(struct isea_dgg *g, int tri, struct isea_pt *pt, } /* q2di to seqnum */ -ISEA_STATIC -int isea_disn(struct isea_dgg *g, int quad, struct isea_pt *di) { +static int isea_disn(struct isea_dgg *g, int quad, struct isea_pt *di) { int sidelength; int sn, height; int hexes; @@ -898,9 +866,8 @@ int isea_disn(struct isea_dgg *g, int quad, struct isea_pt *di) { * d' = d << 4 + q, d = d' >> 4, q = d' & 0xf */ /* convert a q2di to global hex coord */ -ISEA_STATIC -int isea_hex(struct isea_dgg *g, int tri, - struct isea_pt *pt, struct isea_pt *hex) { +static int isea_hex(struct isea_dgg *g, int tri, + struct isea_pt *pt, struct isea_pt *hex) { struct isea_pt v; #ifdef FIXME int sidelength; @@ -961,8 +928,7 @@ int isea_hex(struct isea_dgg *g, int tri, #endif } -ISEA_STATIC -struct isea_pt +static struct isea_pt isea_forward(struct isea_dgg *g, struct isea_geo *in) { int tri; -- cgit v1.2.3 From f3c3d15e59ca13e65e701a621c0b67bd2498d06c Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Sun, 13 May 2018 06:14:38 -0700 Subject: Keep static on the same line as the function --- src/PJ_isea.c | 56 ++++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/src/PJ_isea.c b/src/PJ_isea.c index 6751a716..53302a5c 100644 --- a/src/PJ_isea.c +++ b/src/PJ_isea.c @@ -134,8 +134,7 @@ struct snyder_constants { }; /* TODO put these in radians to avoid a later conversion */ -static const -struct snyder_constants constants[] = { +static const struct snyder_constants constants[] = { {23.80018260, 62.15458023, 60.0, 3.75, 1.033, 0.968, 5.09, 1.195, 1.0}, {20.07675127, 55.69063953, 54.0, 2.65, 1.030, 0.983, 3.59, 1.141, 1.027}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, @@ -178,7 +177,7 @@ static struct isea_geo vertex[] = { /* TODO make an isea_pt array of the vertices as well */ -static int tri_v1[] = {0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10, 2, 3, 4, 5, 1, 11, 11, 11, 11, 11}; +static int tri_v1[] = {0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10, 2, 3, 4, 5, 1, 11, 11, 11, 11, 11}; /* 52.62263186 */ #define E_RAD 0.91843818702186776133 @@ -211,8 +210,7 @@ static const struct isea_geo icostriangles[] = { {DEG180, -E_RAD}, }; -static double -az_adjustment(int triangle) +static double az_adjustment(int triangle) { double adj; @@ -236,8 +234,7 @@ az_adjustment(int triangle) /* H = 0.25 R tan g = */ #define TABLE_H 0.1909830056 -static struct isea_pt -isea_triangle_xy(int triangle) +static struct isea_pt isea_triangle_xy(int triangle) { struct isea_pt c; const double Rprime = 0.91038328153090290025; @@ -272,8 +269,8 @@ isea_triangle_xy(int triangle) } /* snyder eq 14 */ -static double -sph_azimuth(double f_lon, double f_lat, double t_lon, double t_lat) +static double sph_azimuth(double f_lon, double f_lat, + double t_lon, double t_lat) { double az; @@ -291,8 +288,7 @@ sph_azimuth(double f_lon, double f_lat, double t_lon, double t_lat) #endif /* coord needs to be in radians */ -static int -isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) +static int isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) { int i; @@ -482,8 +478,7 @@ isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) * * TODO take a result pointer */ -static struct isea_geo -snyder_ctran(struct isea_geo * np, struct isea_geo * pt) +static struct isea_geo snyder_ctran(struct isea_geo * np, struct isea_geo * pt) { struct isea_geo npt; double alpha, phi, lambda, lambda0, beta, lambdap, phip; @@ -527,8 +522,8 @@ snyder_ctran(struct isea_geo * np, struct isea_geo * pt) return npt; } -static struct isea_geo -isea_ctran(struct isea_geo * np, struct isea_geo * pt, double lon0) +static struct isea_geo isea_ctran(struct isea_geo * np, struct isea_geo * pt, + double lon0) { struct isea_geo npt; @@ -559,8 +554,7 @@ isea_ctran(struct isea_geo * np, struct isea_geo * pt, double lon0) /* fuller's at 5.2454 west, 2.3009 N, adjacent at 7.46658 deg */ -static int -isea_grid_init(struct isea_dgg * g) +static int isea_grid_init(struct isea_dgg * g) { if (!g) return 0; @@ -577,8 +571,7 @@ isea_grid_init(struct isea_dgg * g) return 1; } -static void -isea_orient_isea(struct isea_dgg * g) +static void isea_orient_isea(struct isea_dgg * g) { if (!g) return; @@ -587,8 +580,7 @@ isea_orient_isea(struct isea_dgg * g) g->o_az = 0.0; } -static void -isea_orient_pole(struct isea_dgg * g) +static void isea_orient_pole(struct isea_dgg * g) { if (!g) return; @@ -597,9 +589,8 @@ isea_orient_pole(struct isea_dgg * g) g->o_az = 0; } -static int -isea_transform(struct isea_dgg * g, struct isea_geo * in, - struct isea_pt * out) +static int isea_transform(struct isea_dgg * g, struct isea_geo * in, + struct isea_pt * out) { struct isea_geo i, pole; int tri; @@ -619,8 +610,7 @@ isea_transform(struct isea_dgg * g, struct isea_geo * in, #define DOWNTRI(tri) (((tri - 1) / 5) % 2 == 1) -static void -isea_rotate(struct isea_pt * pt, double degrees) +static void isea_rotate(struct isea_pt * pt, double degrees) { double rad; @@ -653,8 +643,7 @@ static int isea_tri_plane(int tri, struct isea_pt *pt, double radius) { } /* convert projected triangle coords to quad xy coords, return quad number */ -static int -isea_ptdd(int tri, struct isea_pt *pt) { +static int isea_ptdd(int tri, struct isea_pt *pt) { int downtri, quad; downtri = (((tri - 1) / 5) % 2 == 1); @@ -669,8 +658,8 @@ isea_ptdd(int tri, struct isea_pt *pt) { return quad; } -static int -isea_dddi_ap3odd(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_pt *di) +static int isea_dddi_ap3odd(struct isea_dgg *g, int quad, struct isea_pt *pt, + struct isea_pt *di) { struct isea_pt v; double hexwidth; @@ -747,8 +736,8 @@ isea_dddi_ap3odd(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_p return quad; } -static int -isea_dddi(struct isea_dgg *g, int quad, struct isea_pt *pt, struct isea_pt *di) { +static int isea_dddi(struct isea_dgg *g, int quad, struct isea_pt *pt, + struct isea_pt *di) { struct isea_pt v; double hexwidth; int sidelength; /* in hexes */ @@ -928,8 +917,7 @@ static int isea_hex(struct isea_dgg *g, int tri, #endif } -static struct isea_pt -isea_forward(struct isea_dgg *g, struct isea_geo *in) +static struct isea_pt isea_forward(struct isea_dgg *g, struct isea_geo *in) { int tri; struct isea_pt out, coord; -- cgit v1.2.3 From 9f9b4505be5cb2006f363e1c0616e586b9d66a3d Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Sat, 19 May 2018 11:40:59 -0700 Subject: Partial clean isea defines and includes - Move includes to the top - Move #defines to the top after includes - Get M_PI and DEG90 from projects.h --- src/PJ_isea.c | 78 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/PJ_isea.c b/src/PJ_isea.c index b982d11e..769b1837 100644 --- a/src/PJ_isea.c +++ b/src/PJ_isea.c @@ -3,15 +3,49 @@ * and is in the public domain. */ +#include #include #include #include #include #include -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif +#define PJ_LIB__ +#include "proj.h" +#include "projects.h" + +#define DEG36 0.62831853071795864768 +#define DEG72 1.25663706143591729537 +#define DEG90 M_PI_2 +#define DEG108 1.88495559215387594306 +#define DEG120 2.09439510239319549229 +#define DEG144 2.51327412287183459075 +#define DEG180 M_PI + +/* sqrt(5)/M_PI */ +#define ISEA_SCALE 0.8301572857837594396028083 + +/* 26.565051177 degrees */ +#define V_LAT 0.46364760899944494524 + +/* 52.62263186 */ +#define E_RAD 0.91843818702186776133 + +/* 10.81231696 */ +#define F_RAD 0.18871053072122403508 + +/* R tan(g) sin(60) */ +#define TABLE_G 0.6615845383 + +/* H = 0.25 R tan g = */ +#define TABLE_H 0.1909830056 + +/* in radians */ +#define ISEA_STD_LAT 1.01722196792335072101 +#define ISEA_STD_LON .19634954084936207740 + +#define RAD2DEG (180.0/M_PI) +#define DEG2RAD (M_PI/180.0) struct hex { int iso; @@ -145,22 +179,6 @@ static const struct snyder_constants constants[] = { {37.37736814, 36.0, 30.0, 17.27, 1.163, 0.860, 13.14, 1.584, 1.0}, }; -#define DEG120 2.09439510239319549229 -#define DEG72 1.25663706143591729537 -#define DEG90 1.57079632679489661922 -#define DEG144 2.51327412287183459075 -#define DEG36 0.62831853071795864768 -#define DEG108 1.88495559215387594306 -#define DEG180 M_PI -/* sqrt(5)/M_PI */ -#define ISEA_SCALE 0.8301572857837594396028083 - -/* 26.565051177 degrees */ -#define V_LAT 0.46364760899944494524 - -#define RAD2DEG (180.0/M_PI) -#define DEG2RAD (M_PI/180.0) - static struct isea_geo vertex[] = { {0.0, DEG90}, {DEG180, V_LAT}, @@ -180,12 +198,6 @@ static struct isea_geo vertex[] = { static int tri_v1[] = {0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10, 2, 3, 4, 5, 1, 11, 11, 11, 11, 11}; -/* 52.62263186 */ -#define E_RAD 0.91843818702186776133 - -/* 10.81231696 */ -#define F_RAD 0.18871053072122403508 - /* triangle Centers */ static const struct isea_geo icostriangles[] = { {0.0, 0.0}, @@ -229,12 +241,6 @@ static double az_adjustment(int triangle) return adj; } -/* R tan(g) sin(60) */ -#define TABLE_G 0.6615845383 - -/* H = 0.25 R tan g = */ -#define TABLE_H 0.1909830056 - static struct isea_pt isea_triangle_xy(int triangle) { struct isea_pt c; @@ -549,10 +555,6 @@ static struct isea_geo isea_ctran(struct isea_geo * np, struct isea_geo * pt, return npt; } -/* in radians */ -#define ISEA_STD_LAT 1.01722196792335072101 -#define ISEA_STD_LON .19634954084936207740 - /* fuller's at 5.2454 west, 2.3009 N, adjacent at 7.46658 deg */ static int isea_grid_init(struct isea_dgg * g) @@ -965,15 +967,11 @@ static struct isea_pt isea_forward(struct isea_dgg *g, struct isea_geo *in) return out; } + /* * Proj 4 integration code follows */ -#define PJ_LIB__ -#include -#include "proj.h" -#include "projects.h" - PROJ_HEAD(isea, "Icosahedral Snyder Equal Area") "\n\tSph"; struct pj_opaque { -- cgit v1.2.3 From 8d42763d3536eb67085b0968790da1fea0012641 Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Sun, 20 May 2018 07:47:50 -0700 Subject: isea: Use PJ_TODEG and PJ_TORAD (#991) --- src/PJ_isea.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/PJ_isea.c b/src/PJ_isea.c index 769b1837..4e0eda32 100644 --- a/src/PJ_isea.c +++ b/src/PJ_isea.c @@ -11,6 +11,7 @@ #include #define PJ_LIB__ +#include "proj_internal.h" #include "proj.h" #include "projects.h" @@ -44,9 +45,6 @@ #define ISEA_STD_LAT 1.01722196792335072101 #define ISEA_STD_LON .19634954084936207740 -#define RAD2DEG (180.0/M_PI) -#define DEG2RAD (M_PI/180.0) - struct hex { int iso; int x, y, z; @@ -336,9 +334,9 @@ static int isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) /* TODO put these constants in as radians to begin with */ c = constants[SNYDER_POLY_ICOSAHEDRON]; - theta = c.theta * DEG2RAD; - g = c.g * DEG2RAD; - G = c.G * DEG2RAD; + theta = PJ_TORAD(c.theta); + g = PJ_TORAD(c.g); + G = PJ_TORAD(c.G); for (i = 1; i <= 20; i++) { double z; @@ -458,7 +456,7 @@ static int isea_snyder_forward(struct isea_geo * ll, struct isea_pt * out) */ fprintf(stderr, "impossible transform: %f %f is not on any triangle\n", - ll->lon * RAD2DEG, ll->lat * RAD2DEG); + PJ_TODEG(ll->lon), PJ_TODEG(ll->lat)); exit(EXIT_FAILURE); -- cgit v1.2.3