diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-10-28 10:41:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-28 10:41:39 +0100 |
| commit | d9b9afe2b9921b0b3624095b60cca7d630cae67a (patch) | |
| tree | 7865bf5e9b3d7b293f207c10a24fe965a114cfce /src/projections | |
| parent | e2d5b13f3442a8e88093a9d68e1be550194a4d77 (diff) | |
| parent | 7026fa2241d4e42ac35688487b7c7dd4d7f8bad1 (diff) | |
| download | PROJ-d9b9afe2b9921b0b3624095b60cca7d630cae67a.tar.gz PROJ-d9b9afe2b9921b0b3624095b60cca7d630cae67a.zip | |
Merge pull request #1697 from rouault/cppcheck_fixes
Fixes/workaround to be able to use cppcheck from Ubuntu 16.04 (fixes #1648)
Diffstat (limited to 'src/projections')
| -rw-r--r-- | src/projections/healpix.cpp | 58 | ||||
| -rw-r--r-- | src/projections/sch.cpp | 20 | ||||
| -rw-r--r-- | src/projections/stere.cpp | 3 |
3 files changed, 31 insertions, 50 deletions
diff --git a/src/projections/healpix.cpp b/src/projections/healpix.cpp index 4acb4f69..b065a310 100644 --- a/src/projections/healpix.cpp +++ b/src/projections/healpix.cpp @@ -192,39 +192,24 @@ static int in_image(double x, double y, int proj, int north_square, sizeof(healpixVertsJit[0]), healpixVertsJit, x, y); } else { /** - * Assigning each element by index to avoid warnings such as - * 'initializer element is not computable at load time'. - * Before C99 this was not allowed and to keep as portable as - * possible we do it the C89 way here. * We need to assign the array this way because the input is * dynamic (north_square and south_square vars are unknown at * compile time). **/ - double rhealpixVertsJit[12][2]; - rhealpixVertsJit[0][0] = -M_PI - EPS; - rhealpixVertsJit[0][1] = M_FORTPI + EPS; - rhealpixVertsJit[1][0] = -M_PI + north_square*M_HALFPI- EPS; - rhealpixVertsJit[1][1] = M_FORTPI + EPS; - rhealpixVertsJit[2][0] = -M_PI + north_square*M_HALFPI- EPS; - rhealpixVertsJit[2][1] = 3*M_FORTPI + EPS; - rhealpixVertsJit[3][0] = -M_PI + (north_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[3][1] = 3*M_FORTPI + EPS; - rhealpixVertsJit[4][0] = -M_PI + (north_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[4][1] = M_FORTPI + EPS; - rhealpixVertsJit[5][0] = M_PI + EPS; - rhealpixVertsJit[5][1] = M_FORTPI + EPS; - rhealpixVertsJit[6][0] = M_PI + EPS; - rhealpixVertsJit[6][1] = -M_FORTPI - EPS; - rhealpixVertsJit[7][0] = -M_PI + (south_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[7][1] = -M_FORTPI - EPS; - rhealpixVertsJit[8][0] = -M_PI + (south_square + 1.0)*M_HALFPI + EPS; - rhealpixVertsJit[8][1] = -3*M_FORTPI - EPS; - rhealpixVertsJit[9][0] = -M_PI + south_square*M_HALFPI - EPS; - rhealpixVertsJit[9][1] = -3*M_FORTPI - EPS; - rhealpixVertsJit[10][0] = -M_PI + south_square*M_HALFPI - EPS; - rhealpixVertsJit[10][1] = -M_FORTPI - EPS; - rhealpixVertsJit[11][0] = -M_PI - EPS; - rhealpixVertsJit[11][1] = -M_FORTPI - EPS; + double rhealpixVertsJit[][2] = { + { -M_PI - EPS, M_FORTPI + EPS }, + { -M_PI + north_square*M_HALFPI- EPS, M_FORTPI + EPS }, + { -M_PI + north_square*M_HALFPI- EPS, 3*M_FORTPI + EPS }, + { -M_PI + (north_square + 1.0)*M_HALFPI + EPS, 3*M_FORTPI + EPS }, + { -M_PI + (north_square + 1.0)*M_HALFPI + EPS, M_FORTPI + EPS}, + { M_PI + EPS, M_FORTPI + EPS }, + { M_PI + EPS, -M_FORTPI - EPS }, + { -M_PI + (south_square + 1.0)*M_HALFPI + EPS, -M_FORTPI - EPS }, + { -M_PI + (south_square + 1.0)*M_HALFPI + EPS, -3*M_FORTPI - EPS }, + { -M_PI + south_square*M_HALFPI - EPS, -3*M_FORTPI - EPS }, + { -M_PI + south_square*M_HALFPI - EPS, -M_FORTPI - EPS }, + { -M_PI - EPS, -M_FORTPI - EPS } + }; return pnpoly((int)sizeof(rhealpixVertsJit)/ sizeof(rhealpixVertsJit[0]), rhealpixVertsJit, x, y); @@ -459,8 +444,6 @@ static CapMap get_cap(double x, double y, int north_square, int south_square, static PJ_XY combine_caps(double x, double y, int north_square, int south_square, int inverse) { PJ_XY xy; - double v[2]; - double c[2]; double vector[2]; double v_min_c[2]; double ret_dot[2]; @@ -474,8 +457,8 @@ static PJ_XY combine_caps(double x, double y, int north_square, int south_square return xy; } - v[0] = x; v[1] = y; - c[0] = capmap.x; c[1] = capmap.y; + double v[] = {x, y}; + double c[] = {capmap.x, capmap.y}; if (inverse == 0) { /* Rotate (x, y) about its polar cap tip and then translate it to @@ -505,11 +488,10 @@ static PJ_XY combine_caps(double x, double y, int north_square, int south_square vector_sub(v, c, v_min_c); dot_product(tmpRot, v_min_c, ret_dot); { - double a[2]; - /* Workaround cppcheck git issue */ - double* pa = a; - pa[0] = -3*M_FORTPI + ((inverse == 0) ? pole : capmap.cn) *M_HALFPI; - pa[1] = ((capmap.region == CapMap::north) ? 1 : -1) *M_HALFPI; + double a[] = { + -3*M_FORTPI + ((inverse == 0) ? pole : capmap.cn) *M_HALFPI, + ((capmap.region == CapMap::north) ? 1 : -1) *M_HALFPI + }; vector_add(ret_dot, a, vector); } diff --git a/src/projections/sch.cpp b/src/projections/sch.cpp index e302c1da..261555a7 100644 --- a/src/projections/sch.cpp +++ b/src/projections/sch.cpp @@ -59,12 +59,12 @@ static PJ_LPZ sch_inverse3d(PJ_XYZ xyz, PJ *P) { PJ_LPZ lpz = {0.0, 0.0, 0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double temp[3]; - double pxyz[3]; - /* Local lat,lon using radius */ - pxyz[0] = xyz.y * P->a / Q->rcurv; - pxyz[1] = xyz.x * P->a / Q->rcurv; - pxyz[2] = xyz.z; + double pxyz[] = { + xyz.y * P->a / Q->rcurv, + xyz.x * P->a / Q->rcurv, + xyz.z + }; if( pj_Convert_Geodetic_To_Geocentric( &(Q->sph), pxyz[0], pxyz[1], pxyz[2], temp, temp+1, temp+2) != 0) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); @@ -97,8 +97,6 @@ static PJ_XYZ sch_forward3d(PJ_LPZ lpz, PJ *P) { PJ_XYZ xyz = {0.0, 0.0, 0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double temp[3]; - double pxyz[3]; - /* Convert lat lon to geocentric coordinates */ if( pj_Convert_Geodetic_To_Geocentric( &(Q->elp_0), lpz.phi, lpz.lam, lpz.z, temp, temp+1, temp+2 ) != 0 ) { @@ -114,9 +112,11 @@ static PJ_XYZ sch_forward3d(PJ_LPZ lpz, PJ *P) { /* Apply rotation */ - pxyz[0] = Q->transMat[0] * temp[0] + Q->transMat[3] * temp[1] + Q->transMat[6] * temp[2]; - pxyz[1] = Q->transMat[1] * temp[0] + Q->transMat[4] * temp[1] + Q->transMat[7] * temp[2]; - pxyz[2] = Q->transMat[2] * temp[0] + Q->transMat[5] * temp[1] + Q->transMat[8] * temp[2]; + double pxyz[] = { + Q->transMat[0] * temp[0] + Q->transMat[3] * temp[1] + Q->transMat[6] * temp[2], + Q->transMat[1] * temp[0] + Q->transMat[4] * temp[1] + Q->transMat[7] * temp[2], + Q->transMat[2] * temp[0] + Q->transMat[5] * temp[1] + Q->transMat[8] * temp[2] + }; /* Convert to local lat,lon */ pj_Convert_Geocentric_To_Geodetic( &(Q->sph), pxyz[0], pxyz[1], pxyz[2], diff --git a/src/projections/stere.cpp b/src/projections/stere.cpp index afcf5f02..a1bd41e7 100644 --- a/src/projections/stere.cpp +++ b/src/projections/stere.cpp @@ -141,7 +141,6 @@ static PJ_LP stere_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers PJ_LP lp = {0.0,0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, halfpi=0.0; - int i; rho = hypot (xy.x, xy.y); @@ -171,7 +170,7 @@ static PJ_LP stere_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers break; } - for (i = NITER; i--; ) { + for (int i = NITER; i > 0; --i) { sinphi = P->e * sin(phi_l); lp.phi = 2. * atan (tp * pow ((1.+sinphi)/(1.-sinphi), halfe)) - halfpi; if (fabs (phi_l - lp.phi) < CONV) { |
