aboutsummaryrefslogtreecommitdiff
path: root/src/projections
diff options
context:
space:
mode:
authorAndrew Bell <andrew.bell.ia@gmail.com>2019-05-15 10:47:03 -0400
committerAndrew Bell <andrew.bell.ia@gmail.com>2019-05-15 10:47:03 -0400
commit8f268409d37cea329d263e177b83e42f8384d3c7 (patch)
treec4d0f3dd19456600f718a6e0c8573577f433549b /src/projections
parent886ced02f0aaab5d66d16459435f7447cf976650 (diff)
parentd67203a6f76a74f5ac029ff052dbcc72e3b59624 (diff)
downloadPROJ-8f268409d37cea329d263e177b83e42f8384d3c7.tar.gz
PROJ-8f268409d37cea329d263e177b83e42f8384d3c7.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/projections')
-rw-r--r--src/projections/aea.cpp14
-rw-r--r--src/projections/aeqd.cpp17
-rw-r--r--src/projections/airy.cpp8
-rw-r--r--src/projections/aitoff.cpp41
-rw-r--r--src/projections/august.cpp4
-rw-r--r--src/projections/bacon.cpp8
-rw-r--r--src/projections/bertin1953.cpp5
-rw-r--r--src/projections/bipc.cpp8
-rw-r--r--src/projections/boggs.cpp4
-rw-r--r--src/projections/bonne.cpp27
-rw-r--r--src/projections/calcofi.cpp16
-rw-r--r--src/projections/cass.cpp16
-rw-r--r--src/projections/cc.cpp8
-rw-r--r--src/projections/ccon.cpp8
-rw-r--r--src/projections/cea.cpp16
-rw-r--r--src/projections/chamb.cpp4
-rw-r--r--src/projections/collg.cpp8
-rw-r--r--src/projections/comill.cpp8
-rw-r--r--src/projections/crast.cpp8
-rw-r--r--src/projections/denoy.cpp4
-rw-r--r--src/projections/eck1.cpp8
-rw-r--r--src/projections/eck2.cpp8
-rw-r--r--src/projections/eck3.cpp8
-rw-r--r--src/projections/eck4.cpp8
-rw-r--r--src/projections/eck5.cpp8
-rw-r--r--src/projections/eqc.cpp8
-rw-r--r--src/projections/eqdc.cpp18
-rw-r--r--src/projections/eqearth.cpp10
-rw-r--r--src/projections/fahey.cpp8
-rw-r--r--src/projections/fouc_s.cpp8
-rw-r--r--src/projections/gall.cpp8
-rw-r--r--src/projections/geos.cpp21
-rw-r--r--src/projections/gins8.cpp4
-rw-r--r--src/projections/gn_sinu.cpp16
-rw-r--r--src/projections/gnom.cpp8
-rw-r--r--src/projections/goode.cpp8
-rw-r--r--src/projections/gstmerc.cpp8
-rw-r--r--src/projections/hammer.cpp17
-rw-r--r--src/projections/hatano.cpp8
-rw-r--r--src/projections/healpix.cpp11
-rw-r--r--src/projections/igh.cpp10
-rw-r--r--src/projections/imw_p.cpp24
-rw-r--r--src/projections/isea.cpp46
-rw-r--r--src/projections/krovak.cpp30
-rw-r--r--src/projections/labrd.cpp8
-rw-r--r--src/projections/laea.cpp19
-rw-r--r--src/projections/lagrng.cpp22
-rw-r--r--src/projections/larr.cpp4
-rw-r--r--src/projections/lask.cpp4
-rw-r--r--src/projections/latlong.cpp1
-rw-r--r--src/projections/lcc.cpp31
-rw-r--r--src/projections/lcca.cpp8
-rw-r--r--src/projections/loxim.cpp8
-rw-r--r--src/projections/lsat.cpp17
-rw-r--r--src/projections/mbt_fps.cpp8
-rw-r--r--src/projections/mbtfpp.cpp8
-rw-r--r--src/projections/mbtfpq.cpp8
-rw-r--r--src/projections/merc.cpp23
-rw-r--r--src/projections/mill.cpp8
-rw-r--r--src/projections/misrsom.cpp16
-rw-r--r--src/projections/mod_ster.cpp16
-rw-r--r--src/projections/moll.cpp12
-rw-r--r--src/projections/natearth.cpp8
-rw-r--r--src/projections/natearth2.cpp8
-rw-r--r--src/projections/nell.cpp8
-rw-r--r--src/projections/nell_h.cpp8
-rw-r--r--src/projections/nicol.cpp4
-rw-r--r--src/projections/nsper.cpp29
-rw-r--r--src/projections/nzmg.cpp8
-rw-r--r--src/projections/ob_tran.cpp16
-rw-r--r--src/projections/ocea.cpp47
-rw-r--r--src/projections/oea.cpp8
-rw-r--r--src/projections/omerc.cpp28
-rw-r--r--src/projections/ortho.cpp9
-rw-r--r--src/projections/patterson.cpp8
-rw-r--r--src/projections/poly.cpp16
-rw-r--r--src/projections/putp2.cpp8
-rw-r--r--src/projections/putp3.cpp12
-rw-r--r--src/projections/putp4p.cpp12
-rw-r--r--src/projections/putp5.cpp12
-rw-r--r--src/projections/putp6.cpp12
-rw-r--r--src/projections/qsc.cpp8
-rw-r--r--src/projections/robin.cpp21
-rw-r--r--src/projections/rouss.cpp8
-rw-r--r--src/projections/rpoly.cpp4
-rw-r--r--src/projections/sch.cpp10
-rw-r--r--src/projections/sconics.cpp8
-rw-r--r--src/projections/somerc.cpp8
-rw-r--r--src/projections/stere.cpp35
-rw-r--r--src/projections/sterea.cpp15
-rw-r--r--src/projections/sts.cpp8
-rw-r--r--src/projections/tcc.cpp4
-rw-r--r--src/projections/tcea.cpp8
-rw-r--r--src/projections/times.cpp8
-rw-r--r--src/projections/tmerc.cpp4
-rw-r--r--src/projections/tobmerc.cpp11
-rw-r--r--src/projections/tpeqd.cpp12
-rw-r--r--src/projections/urm5.cpp10
-rw-r--r--src/projections/urmfps.cpp8
-rw-r--r--src/projections/vandg.cpp17
-rw-r--r--src/projections/vandg2.cpp6
-rw-r--r--src/projections/vandg4.cpp4
-rw-r--r--src/projections/wag2.cpp8
-rw-r--r--src/projections/wag3.cpp8
-rw-r--r--src/projections/wag7.cpp4
-rw-r--r--src/projections/wink1.cpp8
-rw-r--r--src/projections/wink2.cpp4
107 files changed, 720 insertions, 554 deletions
diff --git a/src/projections/aea.cpp b/src/projections/aea.cpp
index 9a0c4656..721ea3c9 100644
--- a/src/projections/aea.cpp
+++ b/src/projections/aea.cpp
@@ -99,7 +99,7 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */
+static PJ_XY aea_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
Q->rho = Q->c - (Q->ellips ? Q->n * pj_qsfn(sin(lp.phi), P->e, P->one_es) : Q->n2 * sin(lp.phi));;
@@ -114,7 +114,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse */
+static PJ_LP aea_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if( (Q->rho = hypot(xy.x, xy.y = Q->rho0 - xy.y)) != 0.0 ) {
@@ -152,9 +152,11 @@ static PJ *setup(PJ *P) {
int secant;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = aea_e_inverse;
+ P->fwd = aea_e_forward;
+ if (fabs(Q->phi1) > M_HALFPI || fabs(Q->phi2) > M_HALFPI)
+ return destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
if (fabs(Q->phi1 + Q->phi2) < EPS10)
return destructor(P, PJD_ERR_CONIC_LAT_EQUAL);
Q->n = sinphi = sin(Q->phi1);
@@ -178,6 +180,10 @@ static PJ *setup(PJ *P) {
return destructor(P, 0);
Q->n = (m1 * m1 - m2 * m2) / (ml2 - ml1);
+ if (Q->n == 0) {
+ // Not quite, but es is very close to 1...
+ return destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
+ }
}
Q->ec = 1. - .5 * P->one_es * log((1. - P->e) /
(1. + P->e)) / P->e;
diff --git a/src/projections/aeqd.cpp b/src/projections/aeqd.cpp
index 8566062d..04c3662e 100644
--- a/src/projections/aeqd.cpp
+++ b/src/projections/aeqd.cpp
@@ -91,7 +91,7 @@ static PJ_XY e_guam_fwd(PJ_LP lp, PJ *P) { /* Guam elliptical */
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY aeqd_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi, rho;
@@ -130,7 +130,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY aeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
@@ -195,7 +195,7 @@ static PJ_LP e_guam_inv(PJ_XY xy, PJ *P) { /* Guam elliptical */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP aeqd_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c;
@@ -227,7 +227,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP aeqd_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosc, c_rh, sinc;
@@ -291,8 +291,8 @@ PJ *PROJECTION(aeqd) {
Q->cosph0 = cos(P->phi0);
}
if (P->es == 0.0) {
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = aeqd_s_inverse;
+ P->fwd = aeqd_s_forward;
} else {
if (!(Q->en = pj_enfn(P->es)))
return pj_default_destructor (P, 0);
@@ -310,14 +310,13 @@ PJ *PROJECTION(aeqd) {
break;
case EQUIT:
case OBLIQ:
- P->inv = e_inverse; P->fwd = e_forward;
Q->N1 = 1. / sqrt(1. - P->es * Q->sinph0 * Q->sinph0);
Q->G = Q->sinph0 * (Q->He = P->e / sqrt(P->one_es));
Q->He *= Q->cosph0;
break;
}
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = aeqd_e_inverse;
+ P->fwd = aeqd_e_forward;
}
}
diff --git a/src/projections/airy.cpp b/src/projections/airy.cpp
index f7068061..91b4b7a2 100644
--- a/src/projections/airy.cpp
+++ b/src/projections/airy.cpp
@@ -58,7 +58,7 @@ struct pj_opaque {
# define EPS 1.e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY airy_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz;
@@ -79,6 +79,10 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
if (fabs(s = 1. - cosz) > EPS) {
t = 0.5 * (1. + cosz);
+ if(t == 0) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return xy;
+ }
Krho = -log(t)/s - Q->Cb / t;
} else
Krho = 0.5 - Q->Cb;
@@ -147,7 +151,7 @@ PJ *PROJECTION(airy) {
Q->cosph0 = cos(P->phi0);
}
}
- P->fwd = s_forward;
+ P->fwd = airy_s_forward;
P->es = 0.;
return P;
}
diff --git a/src/projections/aitoff.cpp b/src/projections/aitoff.cpp
index 127841ff..dadae12d 100644
--- a/src/projections/aitoff.cpp
+++ b/src/projections/aitoff.cpp
@@ -58,11 +58,11 @@ PROJ_HEAD(wintri, "Winkel Tripel") "\n\tMisc Sph\n\tlat_1";
#if 0
-FORWARD(s_forward); /* spheroid */
+FORWARD(aitoff_s_forward); /* spheroid */
#endif
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY aitoff_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c, d;
@@ -100,7 +100,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
*
************************************************************************************/
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP aitoff_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int iter, MAXITER = 10, round = 0, MAXROUND = 20;
@@ -116,15 +116,20 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
sl = sin(lp.lam * 0.5); cl = cos(lp.lam * 0.5);
sp = sin(lp.phi); cp = cos(lp.phi);
D = cp * cl;
- C = 1. - D * D;
- D = acos(D) / pow(C, 1.5);
- f1 = 2. * D * C * cp * sl;
- f2 = D * C * sp;
- f1p = 2.* (sl * cl * sp * cp / C - D * sp * sl);
- 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) {
+ C = 1. - D * D;
+ const double denom = pow(C, 1.5);
+ if( denom == 0 ) {
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return lp;
+ }
+ D = acos(D) / denom;
+ f1 = 2. * D * C * cp * sl;
+ f2 = D * C * sp;
+ f1p = 2.* (sl * cl * sp * cp / C - D * sp * sl);
+ 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) {
f1 = 0.5 * (f1 + lp.lam * Q->cosphi1);
f2 = 0.5 * (f2 + lp.phi);
f1p *= 0.5;
@@ -156,18 +161,18 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
} while (((fabs(xy.x-x) > EPSILON) || (fabs(xy.y-y) > EPSILON)) && (round++ < MAXROUND));
if (iter == MAXITER && round == MAXROUND)
- {
- pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
- /* fprintf(stderr, "Warning: Accuracy of 1e-12 not reached. Last increments: dlat=%e and dlon=%e\n", dp, dl); */
- }
+ {
+ pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
+ /* fprintf(stderr, "Warning: Accuracy of 1e-12 not reached. Last increments: dlat=%e and dlon=%e\n", dp, dl); */
+ }
return lp;
}
static PJ *setup(PJ *P) {
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = aitoff_s_inverse;
+ P->fwd = aitoff_s_forward;
P->es = 0.;
return P;
}
diff --git a/src/projections/august.cpp b/src/projections/august.cpp
index 3523034e..2104c3cc 100644
--- a/src/projections/august.cpp
+++ b/src/projections/august.cpp
@@ -9,7 +9,7 @@ PROJ_HEAD(august, "August Epicycloidal") "\n\tMisc Sph, no inv";
#define M 1.333333333333333
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY august_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double t, c1, c, x1, x12, y1, y12;
(void) P;
@@ -29,7 +29,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(august) {
P->inv = nullptr;
- P->fwd = s_forward;
+ P->fwd = august_s_forward;
P->es = 0.;
return P;
}
diff --git a/src/projections/bacon.cpp b/src/projections/bacon.cpp
index c713a989..5db2d854 100644
--- a/src/projections/bacon.cpp
+++ b/src/projections/bacon.cpp
@@ -20,7 +20,7 @@ PROJ_HEAD(ortel, "Ortelius Oval") "\n\tMisc Sph, no inv";
PROJ_HEAD(bacon, "Bacon Globular") "\n\tMisc Sph, no inv";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY bacon_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double ax, f;
@@ -50,7 +50,7 @@ PJ *PROJECTION(bacon) {
Q->bacn = 1;
Q->ortl = 0;
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = bacon_s_forward;
return P;
}
@@ -63,7 +63,7 @@ PJ *PROJECTION(apian) {
Q->bacn = Q->ortl = 0;
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = bacon_s_forward;
return P;
}
@@ -77,6 +77,6 @@ PJ *PROJECTION(ortel) {
Q->bacn = 0;
Q->ortl = 1;
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = bacon_s_forward;
return P;
}
diff --git a/src/projections/bertin1953.cpp b/src/projections/bertin1953.cpp
index 96de6d4b..63154084 100644
--- a/src/projections/bertin1953.cpp
+++ b/src/projections/bertin1953.cpp
@@ -14,7 +14,6 @@
#include <errno.h>
#include <math.h>
-#include "proj_internal.h"
#include "proj.h"
#include "proj_internal.h"
@@ -28,7 +27,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) {
+static PJ_XY bertin1953_s_forward (PJ_LP lp, PJ *P) {
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -90,7 +89,7 @@ PJ *PROJECTION(bertin1953) {
Q->sin_delta_gamma = 0.;
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = bertin1953_s_forward;
return P;
}
diff --git a/src/projections/bipc.cpp b/src/projections/bipc.cpp
index 5cfef11f..9fd2fc6f 100644
--- a/src/projections/bipc.cpp
+++ b/src/projections/bipc.cpp
@@ -36,7 +36,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY bipc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cphi, sphi, tphi, t, al, Az, z, Av, cdlam, sdlam, r;
@@ -113,7 +113,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP bipc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t, r, rp, rl, al, z = 0.0, fAz, Az, s, c, Av;
@@ -169,8 +169,8 @@ PJ *PROJECTION(bipc) {
P->opaque = Q;
Q->noskew = pj_param(P->ctx, P->params, "bns").i;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = bipc_s_inverse;
+ P->fwd = bipc_s_forward;
P->es = 0.;
return P;
}
diff --git a/src/projections/boggs.cpp b/src/projections/boggs.cpp
index 5502d493..e7278904 100644
--- a/src/projections/boggs.cpp
+++ b/src/projections/boggs.cpp
@@ -12,7 +12,7 @@ PROJ_HEAD(boggs, "Boggs Eumorphic") "\n\tPCyl, no inv, Sph";
# define FYC 0.49931
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY boggs_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double theta, th1, c;
int i;
@@ -39,6 +39,6 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(boggs) {
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = boggs_s_forward;
return P;
}
diff --git a/src/projections/bonne.cpp b/src/projections/bonne.cpp
index 0e9bae79..31f90907 100644
--- a/src/projections/bonne.cpp
+++ b/src/projections/bonne.cpp
@@ -20,20 +20,25 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY bonne_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, E, c;
rh = Q->am1 + Q->m1 - pj_mlfn(lp.phi, E = sin(lp.phi), c = cos(lp.phi), Q->en);
- E = c * lp.lam / (rh * sqrt(1. - P->es * E * E));
- xy.x = rh * sin(E);
- xy.y = Q->am1 - rh * cos(E);
+ if (fabs(rh) > EPS10) {
+ E = c * lp.lam / (rh * sqrt(1. - P->es * E * E));
+ xy.x = rh * sin(E);
+ xy.y = Q->am1 - rh * cos(E);
+ } else {
+ xy.x = 0.;
+ xy.y = 0.;
+ }
return xy;
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY bonne_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double E, rh;
@@ -48,7 +53,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP bonne_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh;
@@ -67,7 +72,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP bonne_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double s, rh;
@@ -120,15 +125,15 @@ PJ *PROJECTION(bonne) {
Q->m1 = pj_mlfn(Q->phi1, Q->am1 = sin(Q->phi1),
c = cos(Q->phi1), Q->en);
Q->am1 = c / (sqrt(1. - P->es * Q->am1 * Q->am1) * Q->am1);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = bonne_e_inverse;
+ P->fwd = bonne_e_forward;
} else {
if (fabs(Q->phi1) + EPS10 >= M_HALFPI)
Q->cphi1 = 0.;
else
Q->cphi1 = 1. / tan(Q->phi1);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = bonne_s_inverse;
+ P->fwd = bonne_s_forward;
}
return P;
}
diff --git a/src/projections/calcofi.cpp b/src/projections/calcofi.cpp
index e81843b4..57c12dde 100644
--- a/src/projections/calcofi.cpp
+++ b/src/projections/calcofi.cpp
@@ -35,7 +35,7 @@ whatever ellipsoid is provided. */
#define ROTATION_ANGLE 0.52359877559829882 /*CalCOFI angle of 30 deg in rad */
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY calcofi_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
double oy; /* pt O y value in Mercator */
double l1; /* l1 and l2 are distances calculated using trig that sum
@@ -67,7 +67,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY calcofi_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double oy;
double l1;
@@ -93,7 +93,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP calcofi_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
double ry; /* y value of point r */
double oymctr; /* Mercator-transformed y value of point O */
@@ -116,7 +116,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP calcofi_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double ry;
double oymctr;
@@ -153,11 +153,11 @@ PJ *PROJECTION(calcofi) {
P->over = 1;
if (P->es != 0.0) { /* ellipsoid */
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = calcofi_e_inverse;
+ P->fwd = calcofi_e_forward;
} else { /* sphere */
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = calcofi_s_inverse;
+ P->fwd = calcofi_s_forward;
}
return P;
}
diff --git a/src/projections/cass.cpp b/src/projections/cass.cpp
index ee050548..9eea10c5 100644
--- a/src/projections/cass.cpp
+++ b/src/projections/cass.cpp
@@ -25,7 +25,7 @@ struct pj_opaque {
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY cass_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
double n, t, a1, c, a2, tn;
PJ_XY xy = {0.0, 0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -47,7 +47,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY cass_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
xy.x = asin (cos (lp.phi) * sin (lp.lam));
xy.y = atan2 (tan (lp.phi), cos (lp.lam)) - P->phi0;
@@ -55,7 +55,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP cass_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
double n, t, r, dd, d2, tn, ph1;
PJ_LP lp = {0.0, 0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -76,7 +76,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP cass_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double dd;
lp.phi = asin(sin(dd = xy.y + P->phi0) * cos(xy.x));
@@ -101,8 +101,8 @@ PJ *PROJECTION(cass) {
/* Spheroidal? */
if (0==P->es) {
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = cass_s_inverse;
+ P->fwd = cass_s_forward;
return P;
}
@@ -117,8 +117,8 @@ PJ *PROJECTION(cass) {
return pj_default_destructor (P, ENOMEM);
static_cast<struct pj_opaque*>(P->opaque)->m0 = pj_mlfn (P->phi0, sin (P->phi0), cos (P->phi0), static_cast<struct pj_opaque*>(P->opaque)->en);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = cass_e_inverse;
+ P->fwd = cass_e_forward;
return P;
}
diff --git a/src/projections/cc.cpp b/src/projections/cc.cpp
index 559a4f1a..244e185d 100644
--- a/src/projections/cc.cpp
+++ b/src/projections/cc.cpp
@@ -9,7 +9,7 @@ PROJ_HEAD(cc, "Central Cylindrical") "\n\tCyl, Sph";
#define EPS10 1.e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY cc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
if (fabs (fabs(lp.phi) - M_HALFPI) <= EPS10) {
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
@@ -21,7 +21,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP cc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
lp.phi = atan(xy.y);
@@ -34,8 +34,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(cc) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = cc_s_inverse;
+ P->fwd = cc_s_forward;
return P;
}
diff --git a/src/projections/ccon.cpp b/src/projections/ccon.cpp
index 5f5128cf..e2312c0d 100644
--- a/src/projections/ccon.cpp
+++ b/src/projections/ccon.cpp
@@ -43,7 +43,7 @@ PROJ_HEAD(ccon, "Central Conic")
-static PJ_XY forward (PJ_LP lp, PJ *P) {
+static PJ_XY ccon_forward (PJ_LP lp, PJ *P) {
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r;
@@ -56,7 +56,7 @@ static PJ_XY forward (PJ_LP lp, PJ *P) {
}
-static PJ_LP inverse (PJ_XY xy, PJ *P) {
+static PJ_LP ccon_inverse (PJ_XY xy, PJ *P) {
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -100,8 +100,8 @@ PJ *PROJECTION(ccon) {
Q->ctgphi1 = Q->cosphi1/Q->sinphi1;
- P->inv = inverse;
- P->fwd = forward;
+ P->inv = ccon_inverse;
+ P->fwd = ccon_forward;
return P;
}
diff --git a/src/projections/cea.cpp b/src/projections/cea.cpp
index a1c9c8b5..a7e5fd04 100644
--- a/src/projections/cea.cpp
+++ b/src/projections/cea.cpp
@@ -17,7 +17,7 @@ PROJ_HEAD(cea, "Equal Area Cylindrical") "\n\tCyl, Sph&Ell\n\tlat_ts=";
# define EPS 1e-10
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY cea_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
xy.x = P->k0 * lp.lam;
xy.y = 0.5 * pj_qsfn (sin (lp.phi), P->e, P->one_es) / P->k0;
@@ -25,7 +25,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY cea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
xy.x = P->k0 * lp.lam;
xy.y = sin(lp.phi) / P->k0;
@@ -33,7 +33,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP cea_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = pj_authlat(asin( 2. * xy.y * P->k0 / static_cast<struct pj_opaque*>(P->opaque)->qp), static_cast<struct pj_opaque*>(P->opaque)->apa);
lp.lam = xy.x / P->k0;
@@ -41,7 +41,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP cea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double t;
@@ -92,11 +92,11 @@ PJ *PROJECTION(cea) {
return pj_default_destructor(P, ENOMEM);
Q->qp = pj_qsfn(1., P->e, P->one_es);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = cea_e_inverse;
+ P->fwd = cea_e_forward;
} else {
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = cea_s_inverse;
+ P->fwd = cea_s_forward;
}
return P;
diff --git a/src/projections/chamb.cpp b/src/projections/chamb.cpp
index 33a38781..e6bac22c 100644
--- a/src/projections/chamb.cpp
+++ b/src/projections/chamb.cpp
@@ -54,7 +54,7 @@ static double lc(projCtx ctx, double b,double c,double a) {
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY chamb_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinphi, cosphi, a;
@@ -135,7 +135,7 @@ PJ *PROJECTION(chamb) {
Q->p.x = Q->c[2].p.x = Q->c[0].p.x + Q->c[2].v.r * cos(Q->beta_0);
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = chamb_s_forward;
return P;
}
diff --git a/src/projections/collg.cpp b/src/projections/collg.cpp
index b22e1bf2..40319a51 100644
--- a/src/projections/collg.cpp
+++ b/src/projections/collg.cpp
@@ -11,7 +11,7 @@ PROJ_HEAD(collg, "Collignon") "\n\tPCyl, Sph";
#define ONEEPS 1.0000001
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY collg_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
if ((xy.y = 1. - sin(lp.phi)) <= 0.)
@@ -24,7 +24,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP collg_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = xy.y / FYC - 1.;
if (fabs(lp.phi = 1. - lp.phi * lp.phi) < 1.)
@@ -46,8 +46,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(collg) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = collg_s_inverse;
+ P->fwd = collg_s_forward;
return P;
}
diff --git a/src/projections/comill.cpp b/src/projections/comill.cpp
index 3af19b42..afcfbf7f 100644
--- a/src/projections/comill.cpp
+++ b/src/projections/comill.cpp
@@ -26,7 +26,7 @@ PROJ_HEAD(comill, "Compact Miller") "\n\tCyl, Sph";
/* Not sure at all of the appropriate number for MAX_ITER... */
#define MAX_ITER 100
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY comill_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double lat_sq;
@@ -39,7 +39,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP comill_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double yc, tol, y2, f, fder;
int i;
@@ -78,8 +78,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(comill) {
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = comill_s_inverse;
+ P->fwd = comill_s_forward;
return P;
}
diff --git a/src/projections/crast.cpp b/src/projections/crast.cpp
index 35272058..cff35472 100644
--- a/src/projections/crast.cpp
+++ b/src/projections/crast.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(crast, "Craster Parabolic (Putnins P4)") "\n\tPCyl, Sph";
#define THIRD 0.333333333333333333
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY crast_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
lp.phi *= THIRD;
@@ -23,7 +23,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP crast_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
lp.phi = 3. * asin(xy.y * RYM);
@@ -34,8 +34,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(crast) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = crast_s_inverse;
+ P->fwd = crast_s_forward;
return P;
}
diff --git a/src/projections/denoy.cpp b/src/projections/denoy.cpp
index 1560ad6b..5f736a40 100644
--- a/src/projections/denoy.cpp
+++ b/src/projections/denoy.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(denoy, "Denoyer Semi-Elliptical") "\n\tPCyl, no inv, Sph";
#define D5 0.03
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY denoy_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
(void) P;
xy.y = lp.phi;
@@ -27,7 +27,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(denoy) {
P->es = 0.0;
- P->fwd = s_forward;
+ P->fwd = denoy_s_forward;
return P;
}
diff --git a/src/projections/eck1.cpp b/src/projections/eck1.cpp
index 3a19796e..55944952 100644
--- a/src/projections/eck1.cpp
+++ b/src/projections/eck1.cpp
@@ -9,7 +9,7 @@ PROJ_HEAD(eck1, "Eckert I") "\n\tPCyl, Sph";
#define RP 0.31830988618379067154
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY eck1_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -20,7 +20,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP eck1_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
@@ -34,8 +34,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(eck1) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = eck1_s_inverse;
+ P->fwd = eck1_s_forward;
return P
;
diff --git a/src/projections/eck2.cpp b/src/projections/eck2.cpp
index f019fdab..27b94aed 100644
--- a/src/projections/eck2.cpp
+++ b/src/projections/eck2.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(eck2, "Eckert II") "\n\tPCyl, Sph";
#define ONEEPS 1.0000001
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY eck2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -25,7 +25,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP eck2_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
@@ -49,8 +49,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(eck2) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = eck2_s_inverse;
+ P->fwd = eck2_s_forward;
return P;
}
diff --git a/src/projections/eck3.cpp b/src/projections/eck3.cpp
index 6777c765..dd04fb39 100644
--- a/src/projections/eck3.cpp
+++ b/src/projections/eck3.cpp
@@ -18,7 +18,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY eck3_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -28,7 +28,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP eck3_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double denominator;
@@ -45,8 +45,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ *setup(PJ *P) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = eck3_s_inverse;
+ P->fwd = eck3_s_forward;
return P;
}
diff --git a/src/projections/eck4.cpp b/src/projections/eck4.cpp
index 7f8203b2..df2caf42 100644
--- a/src/projections/eck4.cpp
+++ b/src/projections/eck4.cpp
@@ -16,7 +16,7 @@ PROJ_HEAD(eck4, "Eckert IV") "\n\tPCyl, Sph";
#define NITER 6
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY eck4_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double p, V, s, c;
int i;
@@ -44,7 +44,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP eck4_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double c;
@@ -57,8 +57,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(eck4) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = eck4_s_inverse;
+ P->fwd = eck4_s_forward;
return P;
}
diff --git a/src/projections/eck5.cpp b/src/projections/eck5.cpp
index 40e9d3bb..bf0e6a42 100644
--- a/src/projections/eck5.cpp
+++ b/src/projections/eck5.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(eck5, "Eckert V") "\n\tPCyl, Sph";
#define RYF 1.13375401361911319568
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY eck5_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
xy.x = XF * (1. + cos(lp.phi)) * lp.lam;
@@ -23,7 +23,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP eck5_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
lp.lam = RXF * xy.x / (1. + cos( lp.phi = RYF * xy.y));
@@ -34,8 +34,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(eck5) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = eck5_s_inverse;
+ P->fwd = eck5_s_forward;
return P;
}
diff --git a/src/projections/eqc.cpp b/src/projections/eqc.cpp
index eb021eac..194625ef 100644
--- a/src/projections/eqc.cpp
+++ b/src/projections/eqc.cpp
@@ -16,7 +16,7 @@ PROJ_HEAD(eqc, "Equidistant Cylindrical (Plate Carree)")
"\n\tCyl, Sph\n\tlat_ts=[, lat_0=0]";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY eqc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -27,7 +27,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP eqc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -46,8 +46,8 @@ PJ *PROJECTION(eqc) {
if ((Q->rc = cos(pj_param(P->ctx, P->params, "rlat_ts").f)) <= 0.)
return pj_default_destructor (P, PJD_ERR_LAT_TS_LARGER_THAN_90);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = eqc_s_inverse;
+ P->fwd = eqc_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/eqdc.cpp b/src/projections/eqdc.cpp
index d175d4a1..e050a593 100644
--- a/src/projections/eqdc.cpp
+++ b/src/projections/eqdc.cpp
@@ -25,7 +25,7 @@ PROJ_HEAD(eqdc, "Equidistant Conic")
# define EPS10 1.e-10
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY eqdc_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -38,7 +38,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP eqdc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -84,12 +84,14 @@ PJ *PROJECTION(eqdc) {
Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f;
Q->phi2 = pj_param(P->ctx, P->params, "rlat_2").f;
+ if (fabs(Q->phi1) > M_HALFPI || fabs(Q->phi2) > M_HALFPI)
+ return destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
if (fabs(Q->phi1 + Q->phi2) < EPS10)
- return pj_default_destructor (P, PJD_ERR_CONIC_LAT_EQUAL);
+ return destructor (P, PJD_ERR_CONIC_LAT_EQUAL);
if (!(Q->en = pj_enfn(P->es)))
- return pj_default_destructor(P, ENOMEM);
+ return destructor(P, ENOMEM);
Q->n = sinphi = sin(Q->phi1);
cosphi = cos(Q->phi1);
@@ -104,6 +106,10 @@ PJ *PROJECTION(eqdc) {
cosphi = cos(Q->phi2);
Q->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) /
(pj_mlfn(Q->phi2, sinphi, cosphi, Q->en) - ml1);
+ if (Q->n == 0) {
+ // Not quite, but es is very close to 1...
+ return destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
+ }
}
Q->c = ml1 + m1 / Q->n;
Q->rho0 = Q->c - pj_mlfn(P->phi0, sin(P->phi0),
@@ -115,8 +121,8 @@ PJ *PROJECTION(eqdc) {
Q->rho0 = Q->c - P->phi0;
}
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = eqdc_e_inverse;
+ P->fwd = eqdc_e_forward;
return P;
}
diff --git a/src/projections/eqearth.cpp b/src/projections/eqearth.cpp
index dc58eed9..832c9444 100644
--- a/src/projections/eqearth.cpp
+++ b/src/projections/eqearth.cpp
@@ -26,7 +26,7 @@ PROJ_HEAD(eqearth, "Equal Earth") "\n\tPCyl, Sph&Ell";
#define A2 -0.081106
#define A3 0.000893
#define A4 0.003796
-#define M (sqrt(3) / 2.0)
+#define M (sqrt(3.0) / 2.0)
#define MAX_Y 1.3173627591574 /* 90° latitude on a sphere with radius 1 */
#define EPS 1e-11
@@ -40,7 +40,7 @@ struct pj_opaque {
};
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal/spheroidal, forward */
+static PJ_XY eqearth_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal/spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sbeta;
@@ -74,7 +74,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal/spheroidal,
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal/spheroidal, inverse */
+static PJ_LP eqearth_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal/spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double yc, y2, y6;
@@ -148,8 +148,8 @@ PJ *PROJECTION(eqearth) {
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
- P->fwd = e_forward;
- P->inv = e_inverse;
+ P->fwd = eqearth_e_forward;
+ P->inv = eqearth_e_inverse;
Q->rqda = 1.0;
/* Ellipsoidal case */
diff --git a/src/projections/fahey.cpp b/src/projections/fahey.cpp
index ba8cb8f9..9561217a 100644
--- a/src/projections/fahey.cpp
+++ b/src/projections/fahey.cpp
@@ -10,7 +10,7 @@ PROJ_HEAD(fahey, "Fahey") "\n\tPcyl, Sph";
#define TOL 1e-6
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY fahey_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -21,7 +21,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP fahey_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
@@ -35,8 +35,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(fahey) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = fahey_s_inverse;
+ P->fwd = fahey_s_forward;
return P;
}
diff --git a/src/projections/fouc_s.cpp b/src/projections/fouc_s.cpp
index e91f41c3..29d6437d 100644
--- a/src/projections/fouc_s.cpp
+++ b/src/projections/fouc_s.cpp
@@ -18,7 +18,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY fouc_s_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t;
@@ -30,7 +30,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP fouc_s_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double V;
@@ -66,7 +66,7 @@ PJ *PROJECTION(fouc_s) {
Q->n1 = 1. - Q->n;
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = fouc_s_s_inverse;
+ P->fwd = fouc_s_s_forward;
return P;
}
diff --git a/src/projections/gall.cpp b/src/projections/gall.cpp
index 8f1ca1f8..091c75d7 100644
--- a/src/projections/gall.cpp
+++ b/src/projections/gall.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(gall, "Gall (Gall Stereographic)") "\n\tCyl, Sph";
#define RXF 1.41421356237309504880
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY gall_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -24,7 +24,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP gall_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
@@ -38,8 +38,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(gall) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = gall_s_inverse;
+ P->fwd = gall_s_forward;
return P;
}
diff --git a/src/projections/geos.cpp b/src/projections/geos.cpp
index cdb0244a..5b3e594c 100644
--- a/src/projections/geos.cpp
+++ b/src/projections/geos.cpp
@@ -52,7 +52,7 @@ struct pj_opaque {
PROJ_HEAD(geos, "Geostationary Satellite View") "\n\tAzi, Sph&Ell\n\th=";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY geos_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Vx, Vy, Vz, tmp;
@@ -82,7 +82,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY geos_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r, Vx, Vy, Vz, tmp;
@@ -118,7 +118,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP geos_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Vx, Vy, Vz, a, b, det, k;
@@ -155,7 +155,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP geos_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Vx, Vy, Vz, a, b, det, k;
@@ -202,8 +202,7 @@ PJ *PROJECTION(geos) {
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
- if ((Q->h = pj_param(P->ctx, P->params, "dh").f) <= 0.)
- return pj_default_destructor (P, PJD_ERR_H_LESS_THAN_ZERO);
+ Q->h = pj_param(P->ctx, P->params, "dh").f;
sweep_axis = pj_param(P->ctx, P->params, "ssweep").s;
if (sweep_axis == nullptr)
@@ -220,18 +219,20 @@ PJ *PROJECTION(geos) {
}
Q->radius_g_1 = Q->h / P->a;
+ if ( Q->radius_g_1 <= 0 || Q->radius_g_1 > 1e10 )
+ return pj_default_destructor (P, PJD_ERR_INVALID_H);
Q->radius_g = 1. + Q->radius_g_1;
Q->C = Q->radius_g * Q->radius_g - 1.0;
if (P->es != 0.0) {
Q->radius_p = sqrt (P->one_es);
Q->radius_p2 = P->one_es;
Q->radius_p_inv2 = P->rone_es;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = geos_e_inverse;
+ P->fwd = geos_e_forward;
} else {
Q->radius_p = Q->radius_p2 = Q->radius_p_inv2 = 1.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = geos_s_inverse;
+ P->fwd = geos_s_forward;
}
return P;
diff --git a/src/projections/gins8.cpp b/src/projections/gins8.cpp
index 6f499889..73f00d6f 100644
--- a/src/projections/gins8.cpp
+++ b/src/projections/gins8.cpp
@@ -10,7 +10,7 @@ PROJ_HEAD(gins8, "Ginsburg VIII (TsNIIGAiK)") "\n\tPCyl, Sph, no inv";
#define C12 0.08333333333333333
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY gins8_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double t = lp.phi * lp.phi;
(void) P;
@@ -27,7 +27,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(gins8) {
P->es = 0.0;
P->inv = nullptr;
- P->fwd = s_forward;
+ P->fwd = gins8_s_forward;
return P;
}
diff --git a/src/projections/gn_sinu.cpp b/src/projections/gn_sinu.cpp
index 3a591669..84883cbc 100644
--- a/src/projections/gn_sinu.cpp
+++ b/src/projections/gn_sinu.cpp
@@ -23,7 +23,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY gn_sinu_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
double s, c;
@@ -33,7 +33,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP gn_sinu_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
double s;
@@ -50,7 +50,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY gn_sinu_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -80,7 +80,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP gn_sinu_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -109,8 +109,8 @@ static PJ *destructor (PJ *P, int errlev) { /* Destructor
static void setup(PJ *P) {
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = gn_sinu_s_inverse;
+ P->fwd = gn_sinu_s_forward;
Q->C_x = (Q->C_y = sqrt((Q->m + 1.) / Q->n))/(Q->m + 1.);
}
@@ -127,8 +127,8 @@ PJ *PROJECTION(sinu) {
return pj_default_destructor (P, ENOMEM);
if (P->es != 0.0) {
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = gn_sinu_e_inverse;
+ P->fwd = gn_sinu_e_forward;
} else {
Q->n = 1.;
Q->m = 0.;
diff --git a/src/projections/gnom.cpp b/src/projections/gnom.cpp
index bf454ba9..f7cb2635 100644
--- a/src/projections/gnom.cpp
+++ b/src/projections/gnom.cpp
@@ -29,7 +29,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY gnom_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
@@ -77,7 +77,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP gnom_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, cosz, sinz;
@@ -139,8 +139,8 @@ PJ *PROJECTION(gnom) {
Q->cosph0 = cos(P->phi0);
}
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = gnom_s_inverse;
+ P->fwd = gnom_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/goode.cpp b/src/projections/goode.cpp
index 802df90c..c716649d 100644
--- a/src/projections/goode.cpp
+++ b/src/projections/goode.cpp
@@ -21,7 +21,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY goode_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -35,7 +35,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP goode_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -77,8 +77,8 @@ PJ *PROJECTION(goode) {
if (!(Q->sinu = pj_sinu(Q->sinu)) || !(Q->moll = pj_moll(Q->moll)))
return destructor (P, ENOMEM);
- P->fwd = s_forward;
- P->inv = s_inverse;
+ P->fwd = goode_s_forward;
+ P->inv = goode_s_inverse;
return P;
}
diff --git a/src/projections/gstmerc.cpp b/src/projections/gstmerc.cpp
index 735d39e5..808d9ef7 100644
--- a/src/projections/gstmerc.cpp
+++ b/src/projections/gstmerc.cpp
@@ -22,7 +22,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY gstmerc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double L, Ls, sinLs1, Ls1;
@@ -38,7 +38,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP gstmerc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double L, LC, sinC;
@@ -68,8 +68,8 @@ PJ *PROJECTION(gstmerc) {
Q->XS = 0;
Q->YS = -1.0 * Q->n2 * Q->phic;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = gstmerc_s_inverse;
+ P->fwd = gstmerc_s_forward;
return P;
}
diff --git a/src/projections/hammer.cpp b/src/projections/hammer.cpp
index aa7d1ba9..56bdf74e 100644
--- a/src/projections/hammer.cpp
+++ b/src/projections/hammer.cpp
@@ -19,19 +19,26 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY hammer_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosphi, d;
- d = sqrt(2./(1. + (cosphi = cos(lp.phi)) * cos(lp.lam *= Q->w)));
+ cosphi = cos(lp.phi);
+ lp.lam *= Q->w;
+ double denom = 1. + cosphi * cos(lp.lam);
+ if( denom == 0.0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return proj_coord_error().xy;
+ }
+ d = sqrt(2./denom);
xy.x = Q->m * d * cosphi * sin(lp.lam);
xy.y = Q->rm * d * sin(lp.phi);
return xy;
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP hammer_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double z;
@@ -70,8 +77,8 @@ PJ *PROJECTION(hammer) {
Q->m /= Q->w;
P->es = 0.;
- P->fwd = s_forward;
- P->inv = s_inverse;
+ P->fwd = hammer_s_forward;
+ P->inv = hammer_s_inverse;
return P;
}
diff --git a/src/projections/hatano.cpp b/src/projections/hatano.cpp
index b2ef6c6f..6c125d2e 100644
--- a/src/projections/hatano.cpp
+++ b/src/projections/hatano.cpp
@@ -22,7 +22,7 @@ PROJ_HEAD(hatano, "Hatano Asymmetrical Equal Area") "\n\tPCyl, Sph";
#define RXC 1.17647058823529411764
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY hatano_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double th1, c;
int i;
@@ -40,7 +40,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP hatano_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double th;
@@ -76,8 +76,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(hatano) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = hatano_s_inverse;
+ P->fwd = hatano_s_forward;
return P;
}
diff --git a/src/projections/healpix.cpp b/src/projections/healpix.cpp
index 8e4846ed..515f4f6f 100644
--- a/src/projections/healpix.cpp
+++ b/src/projections/healpix.cpp
@@ -33,7 +33,6 @@
#include <errno.h>
#include <math.h>
-#include "proj_internal.h"
#include "proj.h"
#include "proj_internal.h"
@@ -282,7 +281,7 @@ static PJ_XY healpix_sphere(PJ_LP lp) {
/**
* Return the inverse of healpix_sphere().
**/
-static PJ_LP healpix_sphere_inverse(PJ_XY xy) {
+static PJ_LP healpix_spherhealpix_e_inverse(PJ_XY xy) {
PJ_LP lp;
double x = xy.x;
double y = xy.y;
@@ -533,7 +532,7 @@ static PJ_LP s_healpix_inverse(PJ_XY xy, PJ *P) { /* sphere */
pj_ctx_set_errno(P->ctx, PJD_ERR_INVALID_X_OR_Y);
return lp;
}
- return healpix_sphere_inverse(xy);
+ return healpix_spherhealpix_e_inverse(xy);
}
@@ -547,7 +546,7 @@ static PJ_LP e_healpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */
pj_ctx_set_errno(P->ctx, PJD_ERR_INVALID_X_OR_Y);
return lp;
}
- lp = healpix_sphere_inverse(xy);
+ lp = healpix_spherhealpix_e_inverse(xy);
lp.phi = auth_lat(P, lp.phi, 1);
return lp;
}
@@ -582,7 +581,7 @@ static PJ_LP s_rhealpix_inverse(PJ_XY xy, PJ *P) { /* sphere */
return lp;
}
xy = combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 1);
- return healpix_sphere_inverse(xy);
+ return healpix_spherhealpix_e_inverse(xy);
}
@@ -598,7 +597,7 @@ static PJ_LP e_rhealpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */
return lp;
}
xy = combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 1);
- lp = healpix_sphere_inverse(xy);
+ lp = healpix_spherhealpix_e_inverse(xy);
lp.phi = auth_lat(P, lp.phi, 1);
return lp;
}
diff --git a/src/projections/igh.cpp b/src/projections/igh.cpp
index a8efbb9d..8a41cea3 100644
--- a/src/projections/igh.cpp
+++ b/src/projections/igh.cpp
@@ -41,7 +41,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY igh_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int z;
@@ -74,10 +74,10 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP igh_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
- const double y90 = Q->dy0 + sqrt(2); /* lt=90 corresponds to y=y0+sqrt(2) */
+ const double y90 = Q->dy0 + sqrt(2.0); /* lt=90 corresponds to y=y0+sqrt(2) */
int z = 0;
if (xy.y > y90+EPSLN || xy.y < -y90+EPSLN) /* 0 */
@@ -219,8 +219,8 @@ PJ *PROJECTION(igh) {
SETUP(11, moll, d20, -Q->dy0, d20);
SETUP(12, moll, d140, -Q->dy0, d140);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = igh_s_inverse;
+ P->fwd = igh_s_forward;
P->destructor = destructor;
P->es = 0.;
diff --git a/src/projections/imw_p.cpp b/src/projections/imw_p.cpp
index 723fcc48..ee206091 100644
--- a/src/projections/imw_p.cpp
+++ b/src/projections/imw_p.cpp
@@ -97,14 +97,14 @@ static PJ_XY loc_for(PJ_LP lp, PJ *P, double *yc) {
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY imw_p_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
double yc;
PJ_XY xy = loc_for(lp, P, &yc);
return (xy);
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP imw_p_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
PJ_XY t;
@@ -116,15 +116,25 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
lp.lam = xy.x / cos(lp.phi);
do {
t = loc_for(lp, P, &yc);
- lp.phi = ((lp.phi - Q->phi_1) * (xy.y - yc) / (t.y - yc)) + Q->phi_1;
- lp.lam = lp.lam * xy.x / t.x;
+ const double denom = t.y - yc;
+ if( denom != 0 || fabs(t.y - xy.y) > TOL )
+ {
+ if( denom == 0 ) {
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().lp;
+ }
+ lp.phi = ((lp.phi - Q->phi_1) * (xy.y - yc) / denom) + Q->phi_1;
+ }
+ if( t.x != 0 && fabs(t.x - xy.x) > TOL )
+ lp.lam = lp.lam * xy.x / t.x;
i ++;
} while (i < N_MAX_ITER &&
(fabs(t.x - xy.x) > TOL || fabs(t.y - xy.y) > TOL));
if( i == N_MAX_ITER )
{
- lp.lam = lp.phi = HUGE_VAL;
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().lp;
}
return lp;
@@ -209,8 +219,8 @@ PJ *PROJECTION(imw_p) {
Q->Pp = (m2 * x1 - m1 * x2) * t;
Q->Qp = (x2 - x1) * t;
- P->fwd = e_forward;
- P->inv = e_inverse;
+ P->fwd = imw_p_e_forward;
+ P->inv = imw_p_e_inverse;
P->destructor = destructor;
return P;
diff --git a/src/projections/isea.cpp b/src/projections/isea.cpp
index 3a0a0a48..c22e143d 100644
--- a/src/projections/isea.cpp
+++ b/src/projections/isea.cpp
@@ -10,11 +10,12 @@
#include <stdlib.h>
#include <string.h>
+#include <limits>
+
#define PJ_LIB__
-#include "proj_internal.h"
-#include "proj_math.h"
#include "proj.h"
#include "proj_internal.h"
+#include "proj_math.h"
#define DEG36 0.62831853071795864768
#define DEG72 1.25663706143591729537
@@ -89,6 +90,9 @@ static void hexbin2(double width, double x, double y, long *i, long *j) {
y = y - x / 2.0; /* adjustment for rotated X */
/* adjust for actual hexwidth */
+ if( width == 0 ) {
+ throw "Division by zero";
+ }
x /= width;
y /= width;
@@ -100,6 +104,10 @@ static void hexbin2(double width, double x, double y, long *i, long *j) {
iy = lround(ry);
rz = floor(z + 0.5);
iz = lround(rz);
+ if( fabs((double)ix + iy) > std::numeric_limits<int>::max() ||
+ fabs((double)ix + iy + iz) > std::numeric_limits<int>::max() ) {
+ throw "Integer overflow";
+ }
s = ix + iy + iz;
@@ -764,11 +772,18 @@ static int isea_dddi(struct isea_dgg *g, int quad, struct isea_pt *pt,
}
/* todo might want to do this as an iterated loop */
if (g->aperture >0) {
- sidelength = lround(pow(g->aperture, g->resolution / 2.0));
+ double sidelengthDouble = pow(g->aperture, g->resolution / 2.0);
+ if( fabs(sidelengthDouble) > std::numeric_limits<int>::max() ) {
+ throw "Integer overflow";
+ }
+ sidelength = lround(sidelengthDouble);
} else {
sidelength = g->resolution;
}
+ if( sidelength == 0 ) {
+ throw "Division by zero";
+ }
hexwidth = 1.0 / sidelength;
v = *pt;
@@ -847,7 +862,7 @@ static long isea_disn(struct isea_dgg *g, int quad, struct isea_pt *di) {
return g->serial;
}
/* hexes in a quad */
- hexes = lround(pow(g->aperture, g->resolution));
+ hexes = lround(pow(static_cast<double>(g->aperture), static_cast<double>(g->resolution)));
if (quad == 11) {
g->serial = 1 + 10 * hexes + 1;
return g->serial;
@@ -883,6 +898,10 @@ static int isea_hex(struct isea_dgg *g, int tri,
quad = isea_ptdi(g, tri, pt, &v);
+ if( v.x < (INT_MIN >> 4) || v.x > (INT_MAX >> 4) )
+ {
+ throw "Invalid shift";
+ }
hex->x = ((int)v.x << 4) + quad;
hex->y = v.y;
@@ -995,7 +1014,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY isea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
struct isea_pt out;
@@ -1004,7 +1023,12 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
in.lon = lp.lam;
in.lat = lp.phi;
- out = isea_forward(&Q->dgg, &in);
+ try {
+ out = isea_forward(&Q->dgg, &in);
+ } catch( const char* ) {
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().xy;
+ }
xy.x = out.x;
xy.y = out.y;
@@ -1021,7 +1045,7 @@ PJ *PROJECTION(isea) {
P->opaque = Q;
- P->fwd = s_forward;
+ P->fwd = isea_s_forward;
isea_grid_init(&Q->dgg);
Q->dgg.output = ISEA_PLANE;
@@ -1051,14 +1075,6 @@ PJ *PROJECTION(isea) {
Q->dgg.o_lat = pj_param(P->ctx,P->params, "rlat_0").f;
}
- if (pj_param(P->ctx,P->params, "taperture").i) {
- Q->dgg.aperture = pj_param(P->ctx,P->params, "iaperture").i;
- }
-
- if (pj_param(P->ctx,P->params, "tresolution").i) {
- Q->dgg.resolution = pj_param(P->ctx,P->params, "iresolution").i;
- }
-
opt = pj_param(P->ctx,P->params, "smode").s;
if (opt) {
if (!strcmp(opt, "plane")) {
diff --git a/src/projections/krovak.cpp b/src/projections/krovak.cpp
index 591f8dcc..98f09199 100644
--- a/src/projections/krovak.cpp
+++ b/src/projections/krovak.cpp
@@ -103,7 +103,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY krovak_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
PJ_XY xy = {0.0,0.0};
@@ -115,7 +115,14 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forwar
deltav = -lp.lam * Q->alpha;
s = asin(cos(Q->ad) * sin(u) + sin(Q->ad) * cos(u) * cos(deltav));
- d = asin(cos(u) * sin(deltav) / cos(s));
+ const double cos_s = cos(s);
+ if( cos_s < 1e-12 )
+ {
+ xy.x = 0;
+ xy.y = 0;
+ return xy;
+ }
+ d = asin(cos(u) * sin(deltav) / cos_s);
eps = Q->n * d;
rho = Q->rho0 * pow(tan(S0 / 2. + M_PI_4) , Q->n) / pow(tan(s / 2. + M_PI_4) , Q->n);
@@ -130,7 +137,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forwar
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP krovak_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
PJ_LP lp = {0.0,0.0};
@@ -148,7 +155,12 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, invers
eps = atan2(xy.y, xy.x);
d = eps / sin(S0);
- s = 2. * (atan( pow(Q->rho0 / rho, 1. / Q->n) * tan(S0 / 2. + M_PI_4)) - M_PI_4);
+ if( rho == 0.0 ) {
+ s = M_PI_2;
+ }
+ else {
+ s = 2. * (atan( pow(Q->rho0 / rho, 1. / Q->n) * tan(S0 / 2. + M_PI_4)) - M_PI_4);
+ }
u = asin(cos(Q->ad) * sin(s) - sin(Q->ad) * cos(s) * cos(d));
deltav = asin(cos(s) * sin(d) / cos(u));
@@ -210,14 +222,18 @@ PJ *PROJECTION(krovak) {
Q->alpha = sqrt(1. + (P->es * pow(cos(P->phi0), 4)) / (1. - P->es));
u0 = asin(sin(P->phi0) / Q->alpha);
g = pow( (1. + P->e * sin(P->phi0)) / (1. - P->e * sin(P->phi0)) , Q->alpha * P->e / 2. );
- Q->k = tan( u0 / 2. + M_PI_4) / pow (tan(P->phi0 / 2. + M_PI_4) , Q->alpha) * g;
+ double tan_half_phi0_plus_pi_4 = tan(P->phi0 / 2. + M_PI_4);
+ if( tan_half_phi0_plus_pi_4 == 0.0 ) {
+ return pj_default_destructor(P, PJD_ERR_INVALID_ARG);
+ }
+ Q->k = tan( u0 / 2. + M_PI_4) / pow (tan_half_phi0_plus_pi_4 , Q->alpha) * g;
n0 = sqrt(1. - P->es) / (1. - P->es * pow(sin(P->phi0), 2));
Q->n = sin(S0);
Q->rho0 = P->k0 * n0 / tan(S0);
Q->ad = M_PI_2 - UQ;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = krovak_e_inverse;
+ P->fwd = krovak_e_forward;
return P;
}
diff --git a/src/projections/labrd.cpp b/src/projections/labrd.cpp
index 85ab3ddd..21d9099f 100644
--- a/src/projections/labrd.cpp
+++ b/src/projections/labrd.cpp
@@ -16,7 +16,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY labrd_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double V1, V2, ps, sinps, cosps, sinps2, cosps2;
@@ -49,7 +49,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP labrd_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
/* t = 0.0 optimization is to avoid a false positive cppcheck warning */
@@ -130,8 +130,8 @@ PJ *PROJECTION(labrd) {
Q->Cc = 3. * (Q->Ca * Q->Ca - Q->Cb * Q->Cb);
Q->Cd = 6. * Q->Ca * Q->Cb;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = labrd_e_inverse;
+ P->fwd = labrd_e_forward;
return P;
}
diff --git a/src/projections/laea.cpp b/src/projections/laea.cpp
index 22fb1691..8a23c504 100644
--- a/src/projections/laea.cpp
+++ b/src/projections/laea.cpp
@@ -32,7 +32,7 @@ struct pj_opaque {
#define EPS10 1.e-10
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY laea_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, sinlam, sinphi, q, sinb=0.0, cosb=0.0, b=0.0;
@@ -94,7 +94,7 @@ eqcon:
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY laea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
@@ -136,7 +136,7 @@ oblcon:
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP laea_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cCe, sCe, q, rho, ab=0.0;
@@ -185,7 +185,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP laea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosz=0.0, rh, sinz=0.0;
@@ -248,6 +248,9 @@ PJ *PROJECTION(laea) {
P->destructor = destructor;
t = fabs(P->phi0);
+ if (t > M_HALFPI + EPS10 ) {
+ return destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
+ }
if (fabs(t - M_HALFPI) < EPS10)
Q->mode = P->phi0 < 0. ? S_POLE : N_POLE;
else if (fabs(t) < EPS10)
@@ -284,15 +287,15 @@ PJ *PROJECTION(laea) {
Q->xmf *= Q->dd;
break;
}
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = laea_e_inverse;
+ P->fwd = laea_e_forward;
} else {
if (Q->mode == OBLIQ) {
Q->sinb1 = sin(P->phi0);
Q->cosb1 = cos(P->phi0);
}
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = laea_s_inverse;
+ P->fwd = laea_s_forward;
}
return P;
diff --git a/src/projections/lagrng.cpp b/src/projections/lagrng.cpp
index 65686584..d37a00e6 100644
--- a/src/projections/lagrng.cpp
+++ b/src/projections/lagrng.cpp
@@ -21,17 +21,17 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY lagrng_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double v, c;
- if (fabs(fabs(lp.phi) - M_HALFPI) < TOL) {
+ const double sin_phi = sin(lp.phi);
+ if (fabs(fabs(sin_phi) - 1) < TOL) {
xy.x = 0;
xy.y = lp.phi < 0 ? -2. : 2.;
} else {
- lp.phi = sin(lp.phi);
- v = Q->a1 * pow((1. + lp.phi)/(1. - lp.phi), Q->hrw);
+ v = Q->a1 * pow((1. + sin_phi)/(1. - sin_phi), Q->hrw);
lp.lam *= Q->rw;
c = 0.5 * (v + 1./v) + cos(lp.lam);
if (c < TOL) {
@@ -45,7 +45,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP lagrng_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c, x2, y2p, y2m;
@@ -70,7 +70,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(lagrng) {
- double phi1;
+ double sin_phi1;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
@@ -85,16 +85,16 @@ PJ *PROJECTION(lagrng) {
Q->hw = 0.5 * Q->w;
Q->rw = 1. / Q->w;
Q->hrw = 0.5 * Q->rw;
- phi1 = sin(pj_param(P->ctx, P->params, "rlat_1").f);
- if (fabs(fabs(phi1) - 1.) < TOL)
+ sin_phi1 = sin(pj_param(P->ctx, P->params, "rlat_1").f);
+ if (fabs(fabs(sin_phi1) - 1.) < TOL)
return pj_default_destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
- Q->a1 = pow((1. - phi1)/(1. + phi1), Q->hrw);
+ Q->a1 = pow((1. - sin_phi1)/(1. + sin_phi1), Q->hrw);
Q->a2 = Q->a1 * Q->a1;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = lagrng_s_inverse;
+ P->fwd = lagrng_s_forward;
return P;
}
diff --git a/src/projections/larr.cpp b/src/projections/larr.cpp
index bab1dbf4..33fbd94c 100644
--- a/src/projections/larr.cpp
+++ b/src/projections/larr.cpp
@@ -10,7 +10,7 @@ PROJ_HEAD(larr, "Larrivee") "\n\tMisc Sph, no inv";
#define SIXTH .16666666666666666
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY larr_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -23,7 +23,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(larr) {
P->es = 0;
- P->fwd = s_forward;
+ P->fwd = larr_s_forward;
return P;
}
diff --git a/src/projections/lask.cpp b/src/projections/lask.cpp
index c4c6734d..80e50522 100644
--- a/src/projections/lask.cpp
+++ b/src/projections/lask.cpp
@@ -17,7 +17,7 @@ PROJ_HEAD(lask, "Laskowski") "\n\tMisc Sph, no inv";
#define b05 -0.0491032
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY lask_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double l2, p2;
(void) P;
@@ -33,7 +33,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(lask) {
- P->fwd = s_forward;
+ P->fwd = lask_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/latlong.cpp b/src/projections/latlong.cpp
index 970c4893..2c98a4cd 100644
--- a/src/projections/latlong.cpp
+++ b/src/projections/latlong.cpp
@@ -30,7 +30,6 @@
/* very loosely based upon DMA code by Bradford W. Drew */
#define PJ_LIB__
#include "proj_internal.h"
-#include "proj_internal.h"
PROJ_HEAD(lonlat, "Lat/long (Geodetic)") "\n\t";
PROJ_HEAD(latlon, "Lat/long (Geodetic alias)") "\n\t";
diff --git a/src/projections/lcc.cpp b/src/projections/lcc.cpp
index a1fe79a9..beb2efd1 100644
--- a/src/projections/lcc.cpp
+++ b/src/projections/lcc.cpp
@@ -20,7 +20,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY lcc_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0., 0.};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
@@ -43,7 +43,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP lcc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0., 0.};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
@@ -94,6 +94,8 @@ PJ *PROJECTION(lcc) {
if (!pj_param(P->ctx, P->params, "tlat_0").i)
P->phi0 = Q->phi1;
}
+ if (fabs(Q->phi1) > M_HALFPI || fabs(Q->phi2) > M_HALFPI)
+ return pj_default_destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
if (fabs(Q->phi1 + Q->phi2) < EPS10)
return pj_default_destructor(P, PJD_ERR_CONIC_LAT_EQUAL);
@@ -105,15 +107,34 @@ PJ *PROJECTION(lcc) {
m1 = pj_msfn(sinphi, cosphi, P->es);
ml1 = pj_tsfn(Q->phi1, sinphi, P->e);
+ if( ml1 == 0 ) {
+ return pj_default_destructor(P, PJD_ERR_LAT_1_OR_2_ZERO_OR_90);
+ }
if (secant) { /* secant cone */
sinphi = sin(Q->phi2);
Q->n = log(m1 / pj_msfn(sinphi, cos(Q->phi2), P->es));
- Q->n /= log(ml1 / pj_tsfn(Q->phi2, sinphi, P->e));
+ if (Q->n == 0) {
+ // Not quite, but es is very close to 1...
+ return pj_default_destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
+ }
+ const double ml2 = pj_tsfn(Q->phi2, sinphi, P->e);
+ if( ml2 == 0 ) {
+ return pj_default_destructor(P, PJD_ERR_LAT_1_OR_2_ZERO_OR_90);
+ }
+ const double denom = log(ml1 / ml2);
+ if( denom == 0 ) {
+ // Not quite, but es is very close to 1...
+ return pj_default_destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
+ }
+ Q->n /= denom;
}
Q->c = (Q->rho0 = m1 * pow(ml1, -Q->n) / Q->n);
Q->rho0 *= (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) ? 0. :
pow(pj_tsfn(P->phi0, sin(P->phi0), P->e), Q->n);
} else {
+ if( fabs(cosphi) < EPS10 || fabs(cos(Q->phi2)) < EPS10 ) {
+ return pj_default_destructor(P, PJD_ERR_LAT_1_OR_2_ZERO_OR_90);
+ }
if (secant)
Q->n = log(cosphi / cos(Q->phi2)) /
log(tan(M_FORTPI + .5 * Q->phi2) /
@@ -123,8 +144,8 @@ PJ *PROJECTION(lcc) {
Q->c * pow(tan(M_FORTPI + .5 * P->phi0), -Q->n);
}
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = lcc_e_inverse;
+ P->fwd = lcc_e_forward;
return P;
}
diff --git a/src/projections/lcca.cpp b/src/projections/lcca.cpp
index d4dc8641..11ecb29c 100644
--- a/src/projections/lcca.cpp
+++ b/src/projections/lcca.cpp
@@ -80,7 +80,7 @@ static double fSp(double S, double C) { /* deriv of fs */
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY lcca_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double S, r, dr;
@@ -94,7 +94,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP lcca_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double theta, dr, S, dif;
@@ -156,8 +156,8 @@ PJ *PROJECTION(lcca) {
Q->r0 = N0 / tan0;
Q->C = 1. / (6. * R0 * N0);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = lcca_e_inverse;
+ P->fwd = lcca_e_forward;
P->destructor = destructor;
return P;
diff --git a/src/projections/loxim.cpp b/src/projections/loxim.cpp
index 2a780a9e..2ee88037 100644
--- a/src/projections/loxim.cpp
+++ b/src/projections/loxim.cpp
@@ -19,7 +19,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY loxim_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -37,7 +37,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP loxim_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -69,8 +69,8 @@ PJ *PROJECTION(loxim) {
Q->tanphi1 = tan(M_FORTPI + 0.5 * Q->phi1);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = loxim_s_inverse;
+ P->fwd = loxim_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/lsat.cpp b/src/projections/lsat.cpp
index 5b7520d3..f6114485 100644
--- a/src/projections/lsat.cpp
+++ b/src/projections/lsat.cpp
@@ -44,7 +44,7 @@ static void seraz0(double lam, double mult, PJ *P) {
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY lsat_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int l, nn;
@@ -107,12 +107,11 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP lsat_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
double lamt, sdsq, s, lamdp, phidp, sppsq, dd, sd, sl, fac, scl, sav, spp;
-
lamdp = xy.x / Q->b;
nn = 50;
do {
@@ -135,10 +134,14 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
lamdp -= TOL;
spp = sin(phidp);
sppsq = spp * spp;
+ const double denom = 1. - sppsq * (1. + Q->u);
+ if( denom == 0.0 ) {
+ proj_errno_set(P, PJD_ERR_INVALID_X_OR_Y);
+ return proj_coord_error().lp;
+ }
lamt = atan(((1. - sppsq * P->rone_es) * tan(lamdp) *
Q->ca - spp * Q->sa * sqrt((1. + Q->q * dd) * (
- 1. - sppsq) - sppsq * Q->u) / cos(lamdp)) / (1. - sppsq
- * (1. + Q->u)));
+ 1. - sppsq) - sppsq * Q->u) / cos(lamdp)) / denom);
sl = lamt >= 0. ? 1. : -1.;
scl = cos(lamdp) >= 0. ? 1. : -1;
lamt -= M_HALFPI * (1. - scl) * sl;
@@ -205,8 +208,8 @@ PJ *PROJECTION(lsat) {
Q->c1 /= 15.;
Q->c3 /= 45.;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = lsat_e_inverse;
+ P->fwd = lsat_e_forward;
return P;
}
diff --git a/src/projections/mbt_fps.cpp b/src/projections/mbt_fps.cpp
index beff3314..9ce2aa36 100644
--- a/src/projections/mbt_fps.cpp
+++ b/src/projections/mbt_fps.cpp
@@ -16,7 +16,7 @@ PROJ_HEAD(mbt_fps, "McBryde-Thomas Flat-Pole Sine (No. 2)") "\n\tCyl, Sph";
#define C_y 1.44492
#define C1_2 0.33333333333333333333333333
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY mbt_fps_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double k, V, t;
int i;
@@ -37,7 +37,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP mbt_fps_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double t;
@@ -51,8 +51,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(mbt_fps) {
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = mbt_fps_s_inverse;
+ P->fwd = mbt_fps_s_forward;
return P;
}
diff --git a/src/projections/mbtfpp.cpp b/src/projections/mbtfpp.cpp
index ebd860ee..a4ab60b9 100644
--- a/src/projections/mbtfpp.cpp
+++ b/src/projections/mbtfpp.cpp
@@ -15,7 +15,7 @@ PROJ_HEAD(mbtfpp, "McBride-Thomas Flat-Polar Parabolic") "\n\tCyl, Sph";
#define ONEEPS 1.0000001
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY mbtfpp_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -26,7 +26,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP mbtfpp_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = xy.y / FYC;
@@ -58,8 +58,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(mbtfpp) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = mbtfpp_s_inverse;
+ P->fwd = mbtfpp_s_forward;
return P;
}
diff --git a/src/projections/mbtfpq.cpp b/src/projections/mbtfpq.cpp
index ec49f9ce..9a419790 100644
--- a/src/projections/mbtfpq.cpp
+++ b/src/projections/mbtfpq.cpp
@@ -18,7 +18,7 @@ PROJ_HEAD(mbtfpq, "McBryde-Thomas Flat-Polar Quartic") "\n\tCyl, Sph";
#define RXC 3.20041258076506210122
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY mbtfpq_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double th1, c;
int i;
@@ -36,7 +36,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP mbtfpq_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double t;
@@ -67,8 +67,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(mbtfpq) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = mbtfpq_s_inverse;
+ P->fwd = mbtfpq_s_forward;
return P;
}
diff --git a/src/projections/merc.cpp b/src/projections/merc.cpp
index 5b65de90..10b8bb90 100644
--- a/src/projections/merc.cpp
+++ b/src/projections/merc.cpp
@@ -3,10 +3,9 @@
#include <float.h>
#include <math.h>
-#include "proj_internal.h"
#include "proj.h"
-#include "proj_math.h"
#include "proj_internal.h"
+#include "proj_math.h"
PROJ_HEAD(merc, "Mercator") "\n\tCyl, Sph&Ell\n\tlat_ts=";
PROJ_HEAD(webmerc, "Web Mercator / Pseudo Mercator") "\n\tCyl, Ell\n\t";
@@ -20,7 +19,7 @@ static double logtanpfpim1(double x) { /* log(tan(x/2 + M_FORTPI)) */
return log(tan(M_FORTPI + .5 * x));
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY merc_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
if (fabs(fabs(lp.phi) - M_HALFPI) <= EPS10) {
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
@@ -32,7 +31,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY merc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
if (fabs(fabs(lp.phi) - M_HALFPI) <= EPS10) {
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
@@ -44,7 +43,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP merc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
if ((lp.phi = pj_phi2(P->ctx, exp(- xy.y / P->k0), P->e)) == HUGE_VAL) {
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
@@ -55,7 +54,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP merc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = atan(sinh(xy.y / P->k0));
lp.lam = xy.x / P->k0;
@@ -76,15 +75,15 @@ PJ *PROJECTION(merc) {
if (P->es != 0.0) { /* ellipsoid */
if (is_phits)
P->k0 = pj_msfn(sin(phits), cos(phits), P->es);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = merc_e_inverse;
+ P->fwd = merc_e_forward;
}
else { /* sphere */
if (is_phits)
P->k0 = cos(phits);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = merc_s_inverse;
+ P->fwd = merc_s_forward;
}
return P;
@@ -95,7 +94,7 @@ PJ *PROJECTION(webmerc) {
/* Overriding k_0 with fixed parameter */
P->k0 = 1.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = merc_s_inverse;
+ P->fwd = merc_s_forward;
return P;
}
diff --git a/src/projections/mill.cpp b/src/projections/mill.cpp
index 5d4acd89..e6a97057 100644
--- a/src/projections/mill.cpp
+++ b/src/projections/mill.cpp
@@ -7,7 +7,7 @@
PROJ_HEAD(mill, "Miller Cylindrical") "\n\tCyl, Sph";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY mill_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -18,7 +18,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP mill_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
(void) P;
@@ -31,8 +31,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(mill) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = mill_s_inverse;
+ P->fwd = mill_s_forward;
return P;
}
diff --git a/src/projections/misrsom.cpp b/src/projections/misrsom.cpp
index c53f22a1..09e2d8f3 100644
--- a/src/projections/misrsom.cpp
+++ b/src/projections/misrsom.cpp
@@ -62,7 +62,7 @@ static void seraz0(double lam, double mult, PJ *P) {
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY misrsom_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int l, nn;
@@ -123,7 +123,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP misrsom_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
@@ -151,10 +151,14 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
lamdp -= TOL;
spp = sin(phidp);
sppsq = spp * spp;
+ const double denom = 1. - sppsq * (1. + Q->u);
+ if( denom == 0.0 ) {
+ proj_errno_set(P, PJD_ERR_NON_CONVERGENT);
+ return proj_coord_error().lp;
+ }
lamt = atan(((1. - sppsq * P->rone_es) * tan(lamdp) *
Q->ca - spp * Q->sa * sqrt((1. + Q->q * dd) * (
- 1. - sppsq) - sppsq * Q->u) / cos(lamdp)) / (1. - sppsq
- * (1. + Q->u)));
+ 1. - sppsq) - sppsq * Q->u) / cos(lamdp)) / denom);
sl = lamt >= 0. ? 1. : -1.;
scl = cos(lamdp) >= 0. ? 1. : -1;
lamt -= M_HALFPI * (1. - scl) * sl;
@@ -212,8 +216,8 @@ PJ *PROJECTION(misrsom) {
Q->c1 /= 15.;
Q->c3 /= 45.;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = misrsom_e_inverse;
+ P->fwd = misrsom_e_forward;
return P;
}
diff --git a/src/projections/mod_ster.cpp b/src/projections/mod_ster.cpp
index 83390178..8e02ea72 100644
--- a/src/projections/mod_ster.cpp
+++ b/src/projections/mod_ster.cpp
@@ -22,7 +22,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY mod_ster_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinlon, coslon, esphi, chi, schi, cchi, s;
@@ -35,7 +35,12 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
pow((1. - esphi) / (1. + esphi), P->e * .5)) - M_HALFPI;
schi = sin(chi);
cchi = cos(chi);
- s = 2. / (1. + Q->schio * schi + Q->cchio * cchi * coslon);
+ const double denom = 1. + Q->schio * schi + Q->cchio * cchi * coslon;
+ if( denom == 0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return xy;
+ }
+ s = 2. / denom;
p.r = s * cchi * sinlon;
p.i = s * (Q->cchio * schi - Q->schio * cchi * coslon);
p = pj_zpoly1(p, Q->zcoeff, Q->n);
@@ -46,7 +51,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP mod_ster_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
@@ -72,7 +77,6 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
z = 2. * atan(.5 * rh);
sinz = sin(z);
cosz = cos(z);
- lp.lam = P->lam0;
if (fabs(rh) <= EPSLN) {
/* if we end up here input coordinates were (0,0).
* pj_inv() adds P->lam0 to lp.lam, this way we are
@@ -115,8 +119,8 @@ static PJ *setup(PJ *P) { /* general initialization */
chio = P->phi0;
Q->schio = sin(chio);
Q->cchio = cos(chio);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = mod_ster_e_inverse;
+ P->fwd = mod_ster_e_forward;
return P;
}
diff --git a/src/projections/moll.cpp b/src/projections/moll.cpp
index 03393b01..d511c6e0 100644
--- a/src/projections/moll.cpp
+++ b/src/projections/moll.cpp
@@ -20,7 +20,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY moll_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double k, V;
@@ -43,7 +43,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP moll_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.phi = aasin(P->ctx, xy.y / Q->C_y);
@@ -70,8 +70,8 @@ static PJ * setup(PJ *P, double p) {
Q->C_y = r / sp;
Q->C_p = p2 + sin(p2);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = moll_s_inverse;
+ P->fwd = moll_s_forward;
return P;
}
@@ -106,8 +106,8 @@ PJ *PROJECTION(wag5) {
Q->C_y = 1.65014;
Q->C_p = 3.00896;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = moll_s_inverse;
+ P->fwd = moll_s_forward;
return P;
}
diff --git a/src/projections/natearth.cpp b/src/projections/natearth.cpp
index d8e52c37..ff8aef6a 100644
--- a/src/projections/natearth.cpp
+++ b/src/projections/natearth.cpp
@@ -42,7 +42,7 @@ PROJ_HEAD(natearth, "Natural Earth") "\n\tPCyl, Sph";
#define MAX_ITER 100
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY natearth_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double phi2, phi4;
(void) P;
@@ -55,7 +55,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP natearth_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double yc, tol, y2, y4, f, fder;
int i;
@@ -94,8 +94,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(natearth) {
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = natearth_s_inverse;
+ P->fwd = natearth_s_forward;
return P;
}
diff --git a/src/projections/natearth2.cpp b/src/projections/natearth2.cpp
index 9849a723..95d73c36 100644
--- a/src/projections/natearth2.cpp
+++ b/src/projections/natearth2.cpp
@@ -34,7 +34,7 @@ PROJ_HEAD(natearth2, "Natural Earth 2") "\n\tPCyl, Sph";
#define MAX_ITER 100
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY natearth2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double phi2, phi4, phi6;
(void) P;
@@ -49,7 +49,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP natearth2_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double yc, tol, y2, y4, y6, f, fder;
int i;
@@ -91,8 +91,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(natearth2) {
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = natearth2_s_inverse;
+ P->fwd = natearth2_s_forward;
return P;
}
diff --git a/src/projections/nell.cpp b/src/projections/nell.cpp
index b6e69dd6..63a0eec1 100644
--- a/src/projections/nell.cpp
+++ b/src/projections/nell.cpp
@@ -11,7 +11,7 @@ PROJ_HEAD(nell, "Nell") "\n\tPCyl, Sph";
#define LOOP_TOL 1e-7
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY nell_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double k, V;
int i;
@@ -33,7 +33,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP nell_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.lam = 2. * xy.x / (1. + cos(xy.y));
lp.phi = aasin(P->ctx,0.5 * (xy.y + sin(xy.y)));
@@ -45,8 +45,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(nell) {
P->es = 0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = nell_s_inverse;
+ P->fwd = nell_s_forward;
return P;
}
diff --git a/src/projections/nell_h.cpp b/src/projections/nell_h.cpp
index be28b917..63d12391 100644
--- a/src/projections/nell_h.cpp
+++ b/src/projections/nell_h.cpp
@@ -11,7 +11,7 @@ PROJ_HEAD(nell_h, "Nell-Hammer") "\n\tPCyl, Sph";
#define EPS 1e-7
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY nell_h_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -22,7 +22,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP nell_h_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double V, c, p;
int i;
@@ -47,8 +47,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(nell_h) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = nell_h_s_inverse;
+ P->fwd = nell_h_s_forward;
return P;
}
diff --git a/src/projections/nicol.cpp b/src/projections/nicol.cpp
index c4bee261..fb1b93ea 100644
--- a/src/projections/nicol.cpp
+++ b/src/projections/nicol.cpp
@@ -10,7 +10,7 @@ PROJ_HEAD(nicol, "Nicolosi Globular") "\n\tMisc Sph, no inv";
#define EPS 1e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY nicol_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -49,7 +49,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(nicol) {
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = nicol_s_forward;
return P;
}
diff --git a/src/projections/nsper.cpp b/src/projections/nsper.cpp
index a0bb5686..d641e1b6 100644
--- a/src/projections/nsper.cpp
+++ b/src/projections/nsper.cpp
@@ -38,7 +38,7 @@ PROJ_HEAD(tpers, "Tilted perspective") "\n\tAzi, Sph\n\ttilt= azi= h=";
# define EPS10 1.e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY nsper_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
@@ -93,10 +93,10 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP nsper_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
- double rh, cosz, sinz;
+ double rh;
if (Q->tilt) {
double bm, bq, yt;
@@ -108,16 +108,18 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
xy.y = bq * Q->cg - bm * Q->sg;
}
rh = hypot(xy.x, xy.y);
- if ((sinz = 1. - rh * rh * Q->pfact) < 0.) {
- proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
- return lp;
- }
- sinz = (Q->p - sqrt(sinz)) / (Q->pn1 / rh + rh / Q->pn1);
- cosz = sqrt(1. - sinz * sinz);
if (fabs(rh) <= EPS10) {
lp.lam = 0.;
lp.phi = P->phi0;
} else {
+ double cosz, sinz;
+ sinz = 1. - rh * rh * Q->pfact;
+ if (sinz < 0.) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return lp;
+ }
+ sinz = (Q->p - sqrt(sinz)) / (Q->pn1 / rh + rh / Q->pn1);
+ cosz = sqrt(1. - sinz * sinz);
switch (Q->mode) {
case OBLIQ:
lp.phi = asin(cosz * Q->sinph0 + xy.y * sinz * Q->cosph0 / rh);
@@ -146,8 +148,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ *setup(PJ *P) {
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
- if ((Q->height = pj_param(P->ctx, P->params, "dh").f) <= 0.)
- return pj_default_destructor(P, PJD_ERR_H_LESS_THAN_ZERO);
+ Q->height = pj_param(P->ctx, P->params, "dh").f;
if (fabs(fabs(P->phi0) - M_HALFPI) < EPS10)
Q->mode = P->phi0 < 0. ? S_POLE : N_POLE;
@@ -159,12 +160,14 @@ static PJ *setup(PJ *P) {
Q->cosph0 = cos(P->phi0);
}
Q->pn1 = Q->height / P->a; /* normalize by radius */
+ if ( Q->pn1 <= 0 || Q->pn1 > 1e10 )
+ return pj_default_destructor (P, PJD_ERR_INVALID_H);
Q->p = 1. + Q->pn1;
Q->rp = 1. / Q->p;
Q->h = 1. / Q->pn1;
Q->pfact = (Q->p + 1.) * Q->h;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = nsper_s_inverse;
+ P->fwd = nsper_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/nzmg.cpp b/src/projections/nzmg.cpp
index 1c2d9fb7..2f1a897e 100644
--- a/src/projections/nzmg.cpp
+++ b/src/projections/nzmg.cpp
@@ -58,7 +58,7 @@ static const double tpsi[] = { .6399175073, -.1358797613, .063294409, -.02526853
#define Ntphi 8
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY nzmg_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
COMPLEX p;
const double *C;
@@ -77,7 +77,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP nzmg_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
int nn, i;
COMPLEX p, f, fp, dp;
@@ -116,8 +116,8 @@ PJ *PROJECTION(nzmg) {
P->x0 = 2510000.;
P->y0 = 6023150.;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = nzmg_e_inverse;
+ P->fwd = nzmg_e_forward;
return P;
diff --git a/src/projections/ob_tran.cpp b/src/projections/ob_tran.cpp
index 6daae394..f9eaa6f0 100644
--- a/src/projections/ob_tran.cpp
+++ b/src/projections/ob_tran.cpp
@@ -154,6 +154,11 @@ static ARGS ob_tran_target_params (paralist *params) {
if (0!=strncmp (args.argv[i], "o_proj=", 7))
continue;
args.argv[i] += 2;
+ if (strcmp(args.argv[i], "proj=ob_tran") == 0 ) {
+ pj_dealloc (args.argv);
+ args.argc = 0;
+ args.argv = nullptr;
+ }
break;
}
@@ -164,7 +169,6 @@ static ARGS ob_tran_target_params (paralist *params) {
PJ *PROJECTION(ob_tran) {
double phip;
- char *name;
ARGS args;
PJ *R; /* projection to rotate */
@@ -176,15 +180,15 @@ PJ *PROJECTION(ob_tran) {
P->destructor = destructor;
/* get name of projection to be translated */
- if (!(name = pj_param(P->ctx, P->params, "so_proj").s))
+ if (pj_param(P->ctx, P->params, "so_proj").s == nullptr)
return destructor(P, PJD_ERR_NO_ROTATION_PROJ);
- /* avoid endless recursion */
- if( strcmp(name, "ob_tran") == 0 )
- return destructor(P, PJD_ERR_FAILED_TO_FIND_PROJ);
-
/* Create the target projection object to rotate */
args = ob_tran_target_params (P->params);
+ /* avoid endless recursion */
+ if (args.argv == nullptr ) {
+ return destructor(P, PJD_ERR_FAILED_TO_FIND_PROJ);
+ }
R = pj_init_ctx (pj_get_ctx(P), args.argc, args.argv);
pj_dealloc (args.argv);
diff --git a/src/projections/ocea.cpp b/src/projections/ocea.cpp
index 75aa6666..646b8638 100644
--- a/src/projections/ocea.cpp
+++ b/src/projections/ocea.cpp
@@ -15,13 +15,11 @@ struct pj_opaque {
double rtk;
double sinphi;
double cosphi;
- double singam;
- double cosgam;
};
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY ocea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t;
@@ -36,7 +34,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP ocea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t, s;
@@ -52,7 +50,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(ocea) {
- double phi_0=0.0, phi_1, phi_2, lam_1, lam_2, lonz, alpha;
+ double phi_1, phi_2, lam_1, lam_2, lonz, alpha;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
if (nullptr==Q)
@@ -61,15 +59,21 @@ PJ *PROJECTION(ocea) {
Q->rok = 1. / P->k0;
Q->rtk = P->k0;
+ double lam_p, phi_p;
/*If the keyword "alpha" is found in the sentence then use 1point+1azimuth*/
if ( pj_param(P->ctx, P->params, "talpha").i) {
/*Define Pole of oblique transformation from 1 point & 1 azimuth*/
- alpha = pj_param(P->ctx, P->params, "ralpha").f;
+ // ERO: I've added M_PI so that the alpha is the angle from point 1 to point 2
+ // from the North in a clockwise direction
+ // (to be consistent with omerc behaviour)
+ alpha = M_PI + pj_param(P->ctx, P->params, "ralpha").f;
lonz = pj_param(P->ctx, P->params, "rlonc").f;
/*Equation 9-8 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
- Q->singam = atan(-cos(alpha)/(-sin(phi_0) * sin(alpha))) + lonz;
+ // Actually slightliy modified to use atan2(), as it is suggested by
+ // Snyder for equation 9-1, but this is not mentionned here
+ lam_p = atan2(-cos(alpha) , -sin(P->phi0) * sin(alpha)) + lonz;
/*Equation 9-7 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
- Q->sinphi = asin(cos(phi_0) * sin(alpha));
+ phi_p = asin(cos(P->phi0) * sin(alpha));
/*If the keyword "alpha" is NOT found in the sentence then use 2points*/
} else {
/*Define Pole of oblique transformation from 2 points*/
@@ -78,25 +82,32 @@ PJ *PROJECTION(ocea) {
lam_1 = pj_param(P->ctx, P->params, "rlon_1").f;
lam_2 = pj_param(P->ctx, P->params, "rlon_2").f;
/*Equation 9-1 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
- Q->singam = atan2(cos(phi_1) * sin(phi_2) * cos(lam_1) -
+ lam_p = atan2(cos(phi_1) * sin(phi_2) * cos(lam_1) -
sin(phi_1) * cos(phi_2) * cos(lam_2),
sin(phi_1) * cos(phi_2) * sin(lam_2) -
cos(phi_1) * sin(phi_2) * sin(lam_1) );
/* take care of P->lam0 wrap-around when +lam_1=-90*/
if (lam_1 == -M_HALFPI)
- Q->singam = -Q->singam;
+ lam_p = -lam_p;
/*Equation 9-2 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
- Q->sinphi = atan(-cos(Q->singam - lam_1) / tan(phi_1));
+ double cos_lamp_m_minus_lam_1 = cos(lam_p - lam_1);
+ double tan_phi_1 = tan(phi_1);
+ if( tan_phi_1 == 0.0 ) {
+ // Not sure if we want to support this case, but at least this avoids
+ // a division by zero, and gives the same result as the below atan()
+ phi_p = (cos_lamp_m_minus_lam_1 >= 0.0 ) ? -M_HALFPI : M_HALFPI;
+ }
+ else {
+ phi_p = atan(- cos_lamp_m_minus_lam_1 / tan_phi_1);
+ }
}
- P->lam0 = Q->singam + M_HALFPI;
- Q->cosphi = cos(Q->sinphi);
- Q->sinphi = sin(Q->sinphi);
- Q->cosgam = cos(Q->singam);
- Q->singam = sin(Q->singam);
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->lam0 = lam_p + M_HALFPI;
+ Q->cosphi = cos(phi_p);
+ Q->sinphi = sin(phi_p);
+ P->inv = ocea_s_inverse;
+ P->fwd = ocea_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/oea.cpp b/src/projections/oea.cpp
index f2fc1053..ac0f643f 100644
--- a/src/projections/oea.cpp
+++ b/src/projections/oea.cpp
@@ -16,7 +16,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY oea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Az, M, N, cp, sp, cl, shz;
@@ -35,7 +35,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP oea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double N, M, xp, yp, z, Az, cz, sz, cAz;
@@ -77,8 +77,8 @@ PJ *PROJECTION(oea) {
Q->two_r_m = 2. * Q->rm;
Q->hm = 0.5 * Q->m;
Q->hn = 0.5 * Q->n;
- P->fwd = s_forward;
- P->inv = s_inverse;
+ P->fwd = oea_s_forward;
+ P->inv = oea_s_inverse;
P->es = 0.;
}
diff --git a/src/projections/omerc.cpp b/src/projections/omerc.cpp
index e9b7b4a0..954023df 100644
--- a/src/projections/omerc.cpp
+++ b/src/projections/omerc.cpp
@@ -45,7 +45,7 @@ struct pj_opaque {
#define EPS 1.e-10
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY omerc_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double S, T, U, V, W, temp, u, v;
@@ -84,7 +84,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP omerc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double u, v, Qp, Sp, Tp, Vp, Up;
@@ -97,6 +97,10 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
u = xy.y * Q->cosrot + xy.x * Q->sinrot + Q->u_0;
}
Qp = exp(- Q->BrA * v);
+ if( Qp == 0 ) {
+ proj_errno_set(P, PJD_ERR_INVALID_X_OR_Y);
+ return proj_coord_error().lp;
+ }
Sp = .5 * (Qp - 1. / Qp);
Tp = .5 * (Qp + 1. / Qp);
Vp = sin(Q->BrA * u);
@@ -150,6 +154,8 @@ PJ *PROJECTION(omerc) {
phi1 = pj_param(P->ctx, P->params, "rlat_1").f;
lam2 = pj_param(P->ctx, P->params, "rlon_2").f;
phi2 = pj_param(P->ctx, P->params, "rlat_2").f;
+ if (fabs(phi1) > M_HALFPI || fabs(phi2) > M_HALFPI)
+ return pj_default_destructor(P, PJD_ERR_LAT_LARGER_THAN_90);
if (fabs(phi1 - phi2) <= TOL ||
(con = fabs(phi1)) <= TOL ||
fabs(con - M_HALFPI) <= TOL ||
@@ -187,6 +193,9 @@ PJ *PROJECTION(omerc) {
gamma = alpha_c;
} else
alpha_c = aasin(P->ctx, D*sin(gamma0 = gamma));
+ if( fabs(fabs(P->phi0) - M_HALFPI) <= TOL ) {
+ return pj_default_destructor(P, PJD_ERR_LAT_0_OR_ALPHA_EQ_90);
+ }
P->lam0 = lamc - aasin(P->ctx, .5 * (F - 1. / F) *
tan(gamma0)) / Q->B;
} else {
@@ -194,6 +203,10 @@ PJ *PROJECTION(omerc) {
L = pow(pj_tsfn(phi2, sin(phi2), P->e), Q->B);
F = Q->E / H;
p = (L - H) / (L + H);
+ if( p == 0 ) {
+ // Not quite, but es is very close to 1...
+ return pj_default_destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
+ }
J = Q->E * Q->E;
J = (J - L * H) / (J + L * H);
if ((con = lam1 - lam2) < -M_PI)
@@ -202,8 +215,11 @@ PJ *PROJECTION(omerc) {
lam2 += M_TWOPI;
P->lam0 = adjlon(.5 * (lam1 + lam2) - atan(
J * tan(.5 * Q->B * (lam1 - lam2)) / p) / Q->B);
- gamma0 = atan(2. * sin(Q->B * adjlon(lam1 - P->lam0)) /
- (F - 1. / F));
+ const double denom = F - 1. / F;
+ if( denom == 0 ) {
+ return pj_default_destructor(P, PJD_ERR_INVALID_ECCENTRICITY);
+ }
+ gamma0 = atan(2. * sin(Q->B * adjlon(lam1 - P->lam0)) / denom);
gamma = alpha_c = aasin(P->ctx, D * sin(gamma0));
}
Q->singam = sin(gamma0);
@@ -222,8 +238,8 @@ PJ *PROJECTION(omerc) {
F = 0.5 * gamma0;
Q->v_pole_n = Q->ArB * log(tan(M_FORTPI - F));
Q->v_pole_s = Q->ArB * log(tan(M_FORTPI + F));
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = omerc_e_inverse;
+ P->fwd = omerc_e_forward;
return P;
}
diff --git a/src/projections/ortho.cpp b/src/projections/ortho.cpp
index d4300bd5..94764756 100644
--- a/src/projections/ortho.cpp
+++ b/src/projections/ortho.cpp
@@ -3,7 +3,6 @@
#include "proj.h"
#include "proj_internal.h"
#include "proj_math.h"
-#include "proj_internal.h"
PROJ_HEAD(ortho, "Orthographic") "\n\tAzi, Sph";
@@ -33,7 +32,7 @@ static PJ_XY forward_error(PJ *P, PJ_LP lp, PJ_XY xy) {
return xy;
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY ortho_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
@@ -67,7 +66,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP ortho_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, cosc, sinc;
@@ -134,8 +133,8 @@ PJ *PROJECTION(ortho) {
Q->cosph0 = cos(P->phi0);
} else
Q->mode = EQUIT;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = ortho_s_inverse;
+ P->fwd = ortho_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/patterson.cpp b/src/projections/patterson.cpp
index 7f0ea3a9..16e7b746 100644
--- a/src/projections/patterson.cpp
+++ b/src/projections/patterson.cpp
@@ -61,7 +61,7 @@ PROJ_HEAD(patterson, "Patterson Cylindrical") "\n\tCyl";
#define MAX_ITER 100
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY patterson_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double phi2;
(void) P;
@@ -74,7 +74,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP patterson_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double yc, tol, y2, f, fder;
int i;
@@ -111,8 +111,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(patterson) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = patterson_s_inverse;
+ P->fwd = patterson_s_forward;
return P;
}
diff --git a/src/projections/poly.cpp b/src/projections/poly.cpp
index b4b61b00..08a4aaad 100644
--- a/src/projections/poly.cpp
+++ b/src/projections/poly.cpp
@@ -23,7 +23,7 @@ struct pj_opaque {
#define ITOL 1.e-12
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY poly_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double ms, sp, cp;
@@ -42,7 +42,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY poly_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cot, E;
@@ -60,7 +60,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP poly_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -104,7 +104,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP poly_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double B, dphi, tp;
int i;
@@ -159,12 +159,12 @@ PJ *PROJECTION(poly) {
if (!(Q->en = pj_enfn(P->es)))
return pj_default_destructor (P, ENOMEM);
Q->ml0 = pj_mlfn(P->phi0, sin(P->phi0), cos(P->phi0), Q->en);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = poly_e_inverse;
+ P->fwd = poly_e_forward;
} else {
Q->ml0 = -P->phi0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = poly_s_inverse;
+ P->fwd = poly_s_forward;
}
return P;
diff --git a/src/projections/putp2.cpp b/src/projections/putp2.cpp
index d5b3b9f5..a11e479e 100644
--- a/src/projections/putp2.cpp
+++ b/src/projections/putp2.cpp
@@ -15,7 +15,7 @@ PROJ_HEAD(putp2, "Putnins P2") "\n\tPCyl, Sph";
#define PI_DIV_3 1.0471975511965977
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY putp2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double p, c, s, V;
int i;
@@ -41,7 +41,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP putp2_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double c;
@@ -55,8 +55,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(putp2) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp2_s_inverse;
+ P->fwd = putp2_s_forward;
return P;
}
diff --git a/src/projections/putp3.cpp b/src/projections/putp3.cpp
index bc4a02e4..c2df20e8 100644
--- a/src/projections/putp3.cpp
+++ b/src/projections/putp3.cpp
@@ -17,7 +17,7 @@ PROJ_HEAD(putp3p, "Putnins P3'") "\n\tPCyl, Sph";
#define RPISQ 0.1013211836
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY putp3_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
xy.x = C * lp.lam * (1. - static_cast<struct pj_opaque*>(P->opaque)->A * lp.phi * lp.phi);
@@ -27,7 +27,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP putp3_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = xy.y / C;
@@ -46,8 +46,8 @@ PJ *PROJECTION(putp3) {
Q->A = 4. * RPISQ;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp3_s_inverse;
+ P->fwd = putp3_s_forward;
return P;
}
@@ -61,8 +61,8 @@ PJ *PROJECTION(putp3p) {
Q->A = 2. * RPISQ;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp3_s_inverse;
+ P->fwd = putp3_s_forward;
return P;
}
diff --git a/src/projections/putp4p.cpp b/src/projections/putp4p.cpp
index 462dae81..a5728b74 100644
--- a/src/projections/putp4p.cpp
+++ b/src/projections/putp4p.cpp
@@ -16,7 +16,7 @@ PROJ_HEAD(putp4p, "Putnins P4'") "\n\tPCyl, Sph";
PROJ_HEAD(weren, "Werenskiold I") "\n\tPCyl, Sph";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY putp4p_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -29,7 +29,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP putp4p_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -53,8 +53,8 @@ PJ *PROJECTION(putp4p) {
Q->C_y = 3.883251825;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp4p_s_inverse;
+ P->fwd = putp4p_s_forward;
return P;
}
@@ -70,8 +70,8 @@ PJ *PROJECTION(weren) {
Q->C_y = 4.442882938;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp4p_s_inverse;
+ P->fwd = putp4p_s_forward;
return P;
}
diff --git a/src/projections/putp5.cpp b/src/projections/putp5.cpp
index 62cb2ea9..1847e7a9 100644
--- a/src/projections/putp5.cpp
+++ b/src/projections/putp5.cpp
@@ -19,7 +19,7 @@ PROJ_HEAD(putp5p, "Putnins P5'") "\n\tPCyl, Sph";
#define D 1.2158542
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY putp5_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -30,7 +30,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP putp5_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -52,8 +52,8 @@ PJ *PROJECTION(putp5) {
Q->B = 1.;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp5_s_inverse;
+ P->fwd = putp5_s_forward;
return P;
}
@@ -69,8 +69,8 @@ PJ *PROJECTION(putp5p) {
Q->B = 0.5;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp5_s_inverse;
+ P->fwd = putp5_s_forward;
return P;
}
diff --git a/src/projections/putp6.cpp b/src/projections/putp6.cpp
index 4bae7ae6..bcf9ad8e 100644
--- a/src/projections/putp6.cpp
+++ b/src/projections/putp6.cpp
@@ -20,7 +20,7 @@ PROJ_HEAD(putp6p, "Putnins P6'") "\n\tPCyl, Sph";
#define CON_POLE 1.732050807568877
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY putp6_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double p, r, V;
@@ -44,7 +44,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP putp6_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r;
@@ -71,8 +71,8 @@ PJ *PROJECTION(putp6) {
Q->D = 2.;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp6_s_inverse;
+ P->fwd = putp6_s_forward;
return P;
}
@@ -91,8 +91,8 @@ PJ *PROJECTION(putp6p) {
Q->D = 3.;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = putp6_s_inverse;
+ P->fwd = putp6_s_forward;
return P;
}
diff --git a/src/projections/qsc.cpp b/src/projections/qsc.cpp
index 409afb38..98e3755e 100644
--- a/src/projections/qsc.cpp
+++ b/src/projections/qsc.cpp
@@ -119,7 +119,7 @@ static double qsc_shift_lon_origin(double lon, double offset) {
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY qsc_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double lat, lon;
@@ -235,7 +235,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP qsc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double mu, nu, cosmu, tannu;
@@ -382,8 +382,8 @@ PJ *PROJECTION(qsc) {
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = qsc_e_inverse;
+ P->fwd = qsc_e_forward;
/* Determine the cube face from the center of projection. */
if (P->phi0 >= M_HALFPI - M_FORTPI / 2.0) {
Q->face = FACE_TOP;
diff --git a/src/projections/robin.cpp b/src/projections/robin.cpp
index 8f142aad..c08ac0e2 100644
--- a/src/projections/robin.cpp
+++ b/src/projections/robin.cpp
@@ -1,13 +1,12 @@
#define PJ_LIB__
-#include "proj_math.h"
-#include "proj_internal.h"
#include "proj.h"
#include "proj_internal.h"
+#include "proj_math.h"
PROJ_HEAD(robin, "Robinson") "\n\tPCyl, Sph";
#define V(C,z) (C.c0 + z * (C.c1 + z * (C.c2 + z * C.c3)))
-#define DV(C,z) (C.c1 + z * (C.c2 + C.c2 + z * 3. * C.c3))
+#define DV(C,z) (C.c1 + 2 * z * C.c2 + z * z * 3. * C.c3)
/*
note: following terms based upon 5 deg. intervals in degrees.
@@ -74,11 +73,11 @@ static const struct COEFS Y[] = {
#define RC1 0.08726646259971647884
#define NODES 18
#define ONEEPS 1.000001
-#define EPS 1e-8
+#define EPS 1e-10
/* Not sure at all of the appropriate number for MAX_ITER... */
#define MAX_ITER 100
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY robin_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
long i;
double dphi;
@@ -90,7 +89,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
return xy;
}
- if (i >= NODES) i = NODES - 1;
+ if (i >= NODES) i = NODES;
dphi = RAD_TO_DEG * (dphi - RC1 * i);
xy.x = V(X[i], dphi) * FXC * lp.lam;
xy.y = V(Y[i], dphi) * FYC;
@@ -100,7 +99,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP robin_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
long i;
double t, t1;
@@ -133,10 +132,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
T = Y[i];
/* first guess, linear interp */
t = 5. * (lp.phi - T.c0)/(Y[i+1].c0 - T.c0);
- /* make into root */
- T.c0 = (float)(T.c0 - lp.phi);
for (iters = MAX_ITER; iters ; --iters) { /* Newton-Raphson */
- t -= t1 = V(T,t) / DV(T,t);
+ t -= t1 = (V(T,t) - lp.phi) / DV(T,t);
if (fabs(t1) < EPS)
break;
}
@@ -152,8 +149,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(robin) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = robin_s_inverse;
+ P->fwd = robin_s_forward;
return P;
}
diff --git a/src/projections/rouss.cpp b/src/projections/rouss.cpp
index f58277b8..f5a8f12f 100644
--- a/src/projections/rouss.cpp
+++ b/src/projections/rouss.cpp
@@ -44,7 +44,7 @@ struct pj_opaque {
PROJ_HEAD(rouss, "Roussilhe Stereographic") "\n\tAzi, Ell";
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY rouss_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double s, al, cp, sp, al2, s2;
@@ -65,7 +65,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP rouss_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double s, al, x = xy.x / P->k0, y = xy.y / P->k0, x2, y2;;
@@ -150,8 +150,8 @@ PJ *PROJECTION(rouss) {
Q->D10 = R_R0_4 * t * (29. + t2 * (86. + t2 * 48.))/(96. * N0);
Q->D11 = R_R0_4 * t * (37. + t2 * 44.)/(96. * N0);
- P->fwd = e_forward;
- P->inv = e_inverse;
+ P->fwd = rouss_e_forward;
+ P->inv = rouss_e_inverse;
P->destructor = destructor;
return P;
diff --git a/src/projections/rpoly.cpp b/src/projections/rpoly.cpp
index 6e883ab2..58decf66 100644
--- a/src/projections/rpoly.cpp
+++ b/src/projections/rpoly.cpp
@@ -20,7 +20,7 @@ PROJ_HEAD(rpoly, "Rectangular Polyconic")
#define EPS 1e-9
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY rpoly_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double fa;
@@ -53,7 +53,7 @@ PJ *PROJECTION(rpoly) {
Q->fxa = 0.5 / Q->fxb;
}
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = rpoly_s_forward;
return P;
}
diff --git a/src/projections/sch.cpp b/src/projections/sch.cpp
index f4c66688..e302c1da 100644
--- a/src/projections/sch.cpp
+++ b/src/projections/sch.cpp
@@ -55,7 +55,7 @@ struct pj_opaque {
PROJ_HEAD(sch, "Spherical Cross-track Height") "\n\tMisc\n\tplat_0= plon_0= phdg_0= [h_0=]";
-static PJ_LPZ inverse3d(PJ_XYZ xyz, PJ *P) {
+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];
@@ -93,7 +93,7 @@ static PJ_LPZ inverse3d(PJ_XYZ xyz, PJ *P) {
return lpz;
}
-static PJ_XYZ forward3d(PJ_LPZ lpz, PJ *P) {
+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];
@@ -187,8 +187,8 @@ static PJ *setup(PJ *P) { /* general initialization */
Q->xyzoff[1] = pxyz[1] - (Q->rcurv) * clt * slo;
Q->xyzoff[2] = pxyz[2] - (Q->rcurv) * slt;
- P->fwd3d = forward3d;
- P->inv3d = inverse3d;
+ P->fwd3d = sch_forward3d;
+ P->inv3d = sch_inverse3d;
return P;
}
@@ -215,7 +215,7 @@ PJ *PROJECTION(sch) {
return pj_default_destructor(P, PJD_ERR_FAILED_TO_FIND_PROJ);
}
- /* Check if peg latitude is defined */
+ /* Check if peg heading is defined */
if (pj_param(P->ctx, P->params, "tphdg_0").i)
Q->phdg = pj_param(P->ctx, P->params, "rphdg_0").f;
else {
diff --git a/src/projections/sconics.cpp b/src/projections/sconics.cpp
index 7bdd2603..1a16fe24 100644
--- a/src/projections/sconics.cpp
+++ b/src/projections/sconics.cpp
@@ -62,7 +62,7 @@ static int phi12(PJ *P, double *del) {
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY sconics_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
@@ -85,7 +85,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, (and ellipsoidal?) inverse */
+static PJ_LP sconics_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, (and ellipsoidal?) inverse */
PJ_LP lp = {0.0, 0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
@@ -177,8 +177,8 @@ static PJ *setup(PJ *P, enum Type type) {
break;
}
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = sconics_s_inverse;
+ P->fwd = sconics_s_forward;
P->es = 0;
return (P);
}
diff --git a/src/projections/somerc.cpp b/src/projections/somerc.cpp
index ead9090f..be1f660d 100644
--- a/src/projections/somerc.cpp
+++ b/src/projections/somerc.cpp
@@ -18,7 +18,7 @@ struct pj_opaque {
#define NITER 6
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY somerc_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0, 0.0};
double phip, lamp, phipp, lampp, sp, cp;
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
@@ -37,7 +37,7 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP somerc_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double phip, lamp, phipp, lampp, cp, esp, con, delp;
@@ -88,7 +88,7 @@ PJ *PROJECTION(somerc) {
log (tan (M_FORTPI + 0.5 * P->phi0)) - Q->hlf_e *
log ((1. + sp) / (1. - sp)));
Q->kR = P->k0 * sqrt(P->one_es) / (1. - sp * sp);
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = somerc_e_inverse;
+ P->fwd = somerc_e_forward;
return P;
}
diff --git a/src/projections/stere.cpp b/src/projections/stere.cpp
index 9b24a596..683d484c 100644
--- a/src/projections/stere.cpp
+++ b/src/projections/stere.cpp
@@ -41,7 +41,7 @@ static double ssfn_ (double phit, double sinphi, double eccen) {
}
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY stere_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, sinlam, sinX = 0.0, cosX = 0.0, X, A = 0.0, sinphi;
@@ -55,11 +55,18 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
}
switch (Q->mode) {
- case OBLIQ:
- A = Q->akm1 / (Q->cosX1 * (1. + Q->sinX1 * sinX +
- Q->cosX1 * cosX * coslam));
+ case OBLIQ: {
+ const double denom = Q->cosX1 * (1. + Q->sinX1 * sinX +
+ Q->cosX1 * cosX * coslam);
+ if( denom == 0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return proj_coord_error().xy;
+ }
+ A = Q->akm1 / denom;
xy.y = A * (Q->cosX1 * sinX - Q->sinX1 * cosX * coslam);
- goto xmul; /* but why not just xy.x = A * cosX; break; ? */
+ xy.x = A * cosX;
+ break;
+ }
case EQUIT:
/* avoid zero division */
@@ -69,7 +76,6 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
A = Q->akm1 / (1. + cosX * coslam);
xy.y = A * sinX;
}
-xmul:
xy.x = A * cosX;
break;
@@ -89,7 +95,7 @@ xmul:
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY stere_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinphi, cosphi, coslam, sinlam;
@@ -131,7 +137,7 @@ oblcon:
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP stere_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
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;
@@ -165,7 +171,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
break;
}
- for (i = NITER; i--; phi_l = lp.phi) {
+ for (i = NITER; 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) {
@@ -174,6 +180,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
lp.lam = (xy.x == 0. && xy.y == 0.) ? 0. : atan2 (xy.x, xy.y);
return lp;
}
+ phi_l = lp.phi;
}
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
@@ -181,7 +188,7 @@ static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP stere_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c, rh, sinc, cosc;
@@ -258,8 +265,8 @@ static PJ *setup(PJ *P) { /* general initialization */
Q->cosX1 = cos (X);
break;
}
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = stere_e_inverse;
+ P->fwd = stere_e_forward;
} else {
switch (Q->mode) {
case OBLIQ:
@@ -277,8 +284,8 @@ static PJ *setup(PJ *P) { /* general initialization */
break;
}
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = stere_s_inverse;
+ P->fwd = stere_s_forward;
}
return P;
}
diff --git a/src/projections/sterea.cpp b/src/projections/sterea.cpp
index b6ebc7b4..ca3bfd06 100644
--- a/src/projections/sterea.cpp
+++ b/src/projections/sterea.cpp
@@ -44,7 +44,7 @@ PROJ_HEAD(sterea, "Oblique Stereographic Alternative") "\n\tAzimuthal, Sph&Ell";
-static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
+static PJ_XY sterea_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosc, sinc, cosl, k;
@@ -53,14 +53,19 @@ static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */
sinc = sin(lp.phi);
cosc = cos(lp.phi);
cosl = cos(lp.lam);
- k = P->k0 * Q->R2 / (1. + Q->sinc0 * sinc + Q->cosc0 * cosc * cosl);
+ const double denom = 1. + Q->sinc0 * sinc + Q->cosc0 * cosc * cosl;
+ if( denom == 0.0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return proj_coord_error().xy;
+ }
+ k = P->k0 * Q->R2 / denom;
xy.x = k * cosc * sin(lp.lam);
xy.y = k * (Q->cosc0 * sinc - Q->sinc0 * cosc * cosl);
return xy;
}
-static PJ_LP e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
+static PJ_LP sterea_e_inverse (PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho, c, sinc, cosc;
@@ -109,8 +114,8 @@ PJ *PROJECTION(sterea) {
Q->cosc0 = cos (Q->phic0);
Q->R2 = 2. * R;
- P->inv = e_inverse;
- P->fwd = e_forward;
+ P->inv = sterea_e_inverse;
+ P->fwd = sterea_e_forward;
P->destructor = destructor;
return P;
diff --git a/src/projections/sts.cpp b/src/projections/sts.cpp
index 27dc3eb8..4d682a53 100644
--- a/src/projections/sts.cpp
+++ b/src/projections/sts.cpp
@@ -20,7 +20,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY sts_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c;
@@ -40,7 +40,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP sts_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c;
@@ -59,8 +59,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ *setup(PJ *P, double p, double q, int mode) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = sts_s_inverse;
+ P->fwd = sts_s_forward;
static_cast<struct pj_opaque*>(P->opaque)->C_x = q / p;
static_cast<struct pj_opaque*>(P->opaque)->C_y = p;
static_cast<struct pj_opaque*>(P->opaque)->C_p = 1/ q;
diff --git a/src/projections/tcc.cpp b/src/projections/tcc.cpp
index cfac9974..3dd47940 100644
--- a/src/projections/tcc.cpp
+++ b/src/projections/tcc.cpp
@@ -10,7 +10,7 @@ PROJ_HEAD(tcc, "Transverse Central Cylindrical") "\n\tCyl, Sph, no inv";
#define EPS10 1.e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY tcc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
double b, bt;
@@ -27,7 +27,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(tcc) {
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = tcc_s_forward;
P->inv = nullptr;
return P;
diff --git a/src/projections/tcea.cpp b/src/projections/tcea.cpp
index d780718d..a3c771ff 100644
--- a/src/projections/tcea.cpp
+++ b/src/projections/tcea.cpp
@@ -8,7 +8,7 @@
PROJ_HEAD(tcea, "Transverse Cylindrical Equal Area") "\n\tCyl, Sph";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY tcea_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
xy.x = cos (lp.phi) * sin (lp.lam) / P->k0;
xy.y = P->k0 * (atan2 (tan (lp.phi), cos (lp.lam)) - P->phi0);
@@ -16,7 +16,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP tcea_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0, 0.0};
double t;
@@ -30,8 +30,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(tcea) {
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = tcea_s_inverse;
+ P->fwd = tcea_s_forward;
P->es = 0.;
return P;
}
diff --git a/src/projections/times.cpp b/src/projections/times.cpp
index 4a0d0f59..21c6c19a 100644
--- a/src/projections/times.cpp
+++ b/src/projections/times.cpp
@@ -38,7 +38,7 @@
PROJ_HEAD(times, "Times") "\n\tCyl, Sph";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY times_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
double T, S, S2;
PJ_XY xy = {0.0,0.0};
(void) P;
@@ -54,7 +54,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP times_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
double T, S, S2;
PJ_LP lp = {0.0,0.0};
(void) P;
@@ -73,8 +73,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(times) {
P->es = 0.0;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = times_s_inverse;
+ P->fwd = times_s_forward;
return P;
}
diff --git a/src/projections/tmerc.cpp b/src/projections/tmerc.cpp
index c91c5174..bb56f8ae 100644
--- a/src/projections/tmerc.cpp
+++ b/src/projections/tmerc.cpp
@@ -188,6 +188,10 @@ static PJ_LP approx_s_inv (PJ_XY xy, PJ *P) {
double h, g;
h = exp(xy.x / static_cast<struct pj_opaque_approx*>(P->opaque)->esp);
+ if( h == 0 ) {
+ proj_errno_set(P, PJD_ERR_INVALID_X_OR_Y);
+ return proj_coord_error().lp;
+ }
g = .5 * (h - 1. / h);
h = cos (P->phi0 + xy.y / static_cast<struct pj_opaque_approx*>(P->opaque)->esp);
lp.phi = asin(sqrt((1. - h * h) / (1. + g * g)));
diff --git a/src/projections/tobmerc.cpp b/src/projections/tobmerc.cpp
index 95960097..7215f0db 100644
--- a/src/projections/tobmerc.cpp
+++ b/src/projections/tobmerc.cpp
@@ -3,10 +3,9 @@
#include <float.h>
#include <math.h>
-#include "proj_internal.h"
#include "proj.h"
-#include "proj_math.h"
#include "proj_internal.h"
+#include "proj_math.h"
PROJ_HEAD(tobmerc, "Tobler-Mercator") "\n\tCyl, Sph";
@@ -19,7 +18,7 @@ static double logtanpfpim1(double x) { /* log(tan(x/2 + M_FORTPI)) */
return log(tan(M_FORTPI + .5 * x));
}
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY tobmerc_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
double cosphi;
@@ -34,7 +33,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
return xy;
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP tobmerc_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0, 0.0};
double cosphi;
@@ -45,7 +44,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
}
PJ *PROJECTION(tobmerc) {
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = tobmerc_s_inverse;
+ P->fwd = tobmerc_s_forward;
return P;
}
diff --git a/src/projections/tpeqd.cpp b/src/projections/tpeqd.cpp
index 20921de4..b306968c 100644
--- a/src/projections/tpeqd.cpp
+++ b/src/projections/tpeqd.cpp
@@ -16,7 +16,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY tpeqd_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t, z1, z2, dl1, dl2, sp, cp;
@@ -37,7 +37,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP tpeqd_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cz1, cz2, s, d, cp, sp;
@@ -87,6 +87,10 @@ PJ *PROJECTION(tpeqd) {
Q->sc = Q->sp1 * Q->cp2;
Q->ccs = Q->cp1 * Q->cp2 * sin(Q->dlam2);
Q->z02 = aacos(P->ctx, Q->sp1 * Q->sp2 + Q->cp1 * Q->cp2 * cos (Q->dlam2));
+ if( Q->z02 == 0.0 ) {
+ // Actually happens when both lat_1 = lat_2 and |lat_1| = 90
+ return pj_default_destructor(P, PJD_ERR_LAT_1_OR_2_ZERO_OR_90);
+ }
Q->hz0 = .5 * Q->z02;
A12 = atan2(Q->cp2 * sin (Q->dlam2),
Q->cp1 * Q->sp2 - Q->sp1 * Q->cp2 * cos (Q->dlam2));
@@ -100,8 +104,8 @@ PJ *PROJECTION(tpeqd) {
Q->r2z0 = 0.5 / Q->z02;
Q->z02 *= Q->z02;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = tpeqd_s_inverse;
+ P->fwd = tpeqd_s_forward;
P->es = 0.;
return P;
diff --git a/src/projections/urm5.cpp b/src/projections/urm5.cpp
index a93293c0..499644d2 100644
--- a/src/projections/urm5.cpp
+++ b/src/projections/urm5.cpp
@@ -15,7 +15,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY urm5_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t;
@@ -45,12 +45,16 @@ PJ *PROJECTION(urm5) {
Q->q3 = pj_param(P->ctx, P->params, "dq").f / 3.;
alpha = pj_param(P->ctx, P->params, "ralpha").f;
t = Q->n * sin (alpha);
- Q->m = cos (alpha) / sqrt (1. - t * t);
+ const double denom = sqrt (1. - t * t);
+ if( denom == 0 ) {
+ return pj_default_destructor(P, PJD_ERR_LAT_0_OR_ALPHA_EQ_90);
+ }
+ Q->m = cos (alpha) / denom;
Q->rmn = 1. / (Q->m * Q->n);
P->es = 0.;
P->inv = nullptr;
- P->fwd = s_forward;
+ P->fwd = urm5_s_forward;
return P;
}
diff --git a/src/projections/urmfps.cpp b/src/projections/urmfps.cpp
index 3a51798b..3f9fdf23 100644
--- a/src/projections/urmfps.cpp
+++ b/src/projections/urmfps.cpp
@@ -19,7 +19,7 @@ struct pj_opaque {
#define Cy 1.139753528477
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY urmfps_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
lp.phi = aasin (P->ctx,static_cast<struct pj_opaque*>(P->opaque)->n * sin (lp.phi));
xy.x = C_x * lp.lam * cos (lp.phi);
@@ -28,7 +28,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP urmfps_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0, 0.0};
xy.y /= static_cast<struct pj_opaque*>(P->opaque)->C_y;
lp.phi = aasin(P->ctx, sin (xy.y) / static_cast<struct pj_opaque*>(P->opaque)->n);
@@ -40,8 +40,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ *setup(PJ *P) {
static_cast<struct pj_opaque*>(P->opaque)->C_y = Cy / static_cast<struct pj_opaque*>(P->opaque)->n;
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = urmfps_s_inverse;
+ P->fwd = urmfps_s_forward;
return P;
}
diff --git a/src/projections/vandg.cpp b/src/projections/vandg.cpp
index 89620356..7d485aff 100644
--- a/src/projections/vandg.cpp
+++ b/src/projections/vandg.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(vandg, "van der Grinten (I)") "\n\tMisc Sph";
# define HPISQ 4.93480220054467930934
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY vandg_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double al, al2, g, g2, p2;
@@ -58,7 +58,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP vandg_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
double t, c0, c1, c2, c3, al, r2, r, m, d, ay, x2, y2;
@@ -80,7 +80,14 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
al = c1 / c3 - THIRD * c2 * c2;
m = 2. * sqrt(-THIRD * al);
d = C2_27 * c2 * c2 * c2 + (c0 * c0 - THIRD * c2 * c1) / c3;
- if (((t = fabs(d = 3. * d / (al * m))) - TOL) <= 1.) {
+ const double al_mul_m = al * m;
+ if( al_mul_m == 0 ) {
+ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ return proj_coord_error().lp;
+ }
+ d = 3. * d /al_mul_m;
+ t = fabs(d);
+ if ((t - TOL) <= 1.) {
d = t > 1. ? (d > 0. ? 0. : M_PI) : acos(d);
lp.phi = M_PI * (m * cos(d * THIRD + PI4_3) - THIRD * c2);
if (xy.y < 0.) lp.phi = -lp.phi;
@@ -98,8 +105,8 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(vandg) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = vandg_s_inverse;
+ P->fwd = vandg_s_forward;
return P;
}
diff --git a/src/projections/vandg2.cpp b/src/projections/vandg2.cpp
index de63b085..05314833 100644
--- a/src/projections/vandg2.cpp
+++ b/src/projections/vandg2.cpp
@@ -18,7 +18,7 @@ PROJ_HEAD(vandg3, "van der Grinten III") "\n\tMisc Sph, no inv";
#define TOL 1e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY vandg2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double x1, at, bt, ct;
@@ -58,7 +58,7 @@ PJ *PROJECTION(vandg2) {
P->opaque = Q;
Q->vdg3 = 0;
- P->fwd = s_forward;
+ P->fwd = vandg2_s_forward;
return P;
}
@@ -71,7 +71,7 @@ PJ *PROJECTION(vandg3) {
Q->vdg3 = 1;
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = vandg2_s_forward;
return P;
}
diff --git a/src/projections/vandg4.cpp b/src/projections/vandg4.cpp
index 8511431d..a5cfd8e6 100644
--- a/src/projections/vandg4.cpp
+++ b/src/projections/vandg4.cpp
@@ -10,7 +10,7 @@ PROJ_HEAD(vandg4, "van der Grinten IV") "\n\tMisc Sph, no inv";
#define TOL 1e-10
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY vandg4_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
double x1, t, bt, ct, ft, bt2, ct2, dt, dt2;
(void) P;
@@ -50,7 +50,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(vandg4) {
P->es = 0.;
- P->fwd = s_forward;
+ P->fwd = vandg4_s_forward;
return P;
}
diff --git a/src/projections/wag2.cpp b/src/projections/wag2.cpp
index e04cc648..4e7c28ac 100644
--- a/src/projections/wag2.cpp
+++ b/src/projections/wag2.cpp
@@ -13,7 +13,7 @@ PROJ_HEAD(wag2, "Wagner II") "\n\tPCyl, Sph";
#define C_p2 0.88550
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY wag2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
lp.phi = aasin (P->ctx,C_p1 * sin (C_p2 * lp.phi));
xy.x = C_x * lp.lam * cos (lp.phi);
@@ -22,7 +22,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP wag2_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = xy.y / C_y;
lp.lam = xy.x / (C_x * cos(lp.phi));
@@ -33,7 +33,7 @@ static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(wag2) {
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = wag2_s_inverse;
+ P->fwd = wag2_s_forward;
return P;
}
diff --git a/src/projections/wag3.cpp b/src/projections/wag3.cpp
index ed695ffd..33313cdb 100644
--- a/src/projections/wag3.cpp
+++ b/src/projections/wag3.cpp
@@ -17,7 +17,7 @@ struct pj_opaque {
} // anonymous namespace
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY wag3_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
xy.x = static_cast<struct pj_opaque*>(P->opaque)->C_x * lp.lam * cos(TWOTHIRD * lp.phi);
xy.y = lp.phi;
@@ -25,7 +25,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP wag3_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = xy.y;
lp.lam = xy.x / (static_cast<struct pj_opaque*>(P->opaque)->C_x * cos(TWOTHIRD * lp.phi));
@@ -44,8 +44,8 @@ PJ *PROJECTION(wag3) {
ts = pj_param (P->ctx, P->params, "rlat_ts").f;
static_cast<struct pj_opaque*>(P->opaque)->C_x = cos (ts) / cos (2.*ts/3.);
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = wag3_s_inverse;
+ P->fwd = wag3_s_forward;
return P;
}
diff --git a/src/projections/wag7.cpp b/src/projections/wag7.cpp
index 45b70ee2..3afb5a03 100644
--- a/src/projections/wag7.cpp
+++ b/src/projections/wag7.cpp
@@ -9,7 +9,7 @@ PROJ_HEAD(wag7, "Wagner VII") "\n\tMisc Sph, no inv";
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY wag7_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
double theta, ct, D;
@@ -24,7 +24,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(wag7) {
- P->fwd = s_forward;
+ P->fwd = wag7_s_forward;
P->inv = nullptr;
P->es = 0.;
return P;
diff --git a/src/projections/wink1.cpp b/src/projections/wink1.cpp
index 75abbffc..d097978f 100644
--- a/src/projections/wink1.cpp
+++ b/src/projections/wink1.cpp
@@ -16,7 +16,7 @@ struct pj_opaque {
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY wink1_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0,0.0};
xy.x = .5 * lp.lam * (static_cast<struct pj_opaque*>(P->opaque)->cosphi1 + cos(lp.phi));
xy.y = lp.phi;
@@ -24,7 +24,7 @@ static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
}
-static PJ_LP s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
+static PJ_LP wink1_s_inverse (PJ_XY xy, PJ *P) { /* Spheroidal, inverse */
PJ_LP lp = {0.0,0.0};
lp.phi = xy.y;
lp.lam = 2. * xy.x / (static_cast<struct pj_opaque*>(P->opaque)->cosphi1 + cos(lp.phi));
@@ -40,8 +40,8 @@ PJ *PROJECTION(wink1) {
static_cast<struct pj_opaque*>(P->opaque)->cosphi1 = cos (pj_param(P->ctx, P->params, "rlat_ts").f);
P->es = 0.;
- P->inv = s_inverse;
- P->fwd = s_forward;
+ P->inv = wink1_s_inverse;
+ P->fwd = wink1_s_forward;
return P;
}
diff --git a/src/projections/wink2.cpp b/src/projections/wink2.cpp
index 6957bde1..4aaf1972 100644
--- a/src/projections/wink2.cpp
+++ b/src/projections/wink2.cpp
@@ -18,7 +18,7 @@ struct pj_opaque {
#define LOOP_TOL 1e-7
-static PJ_XY s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
+static PJ_XY wink2_s_forward (PJ_LP lp, PJ *P) { /* Spheroidal, forward */
PJ_XY xy = {0.0, 0.0};
double k, V;
int i;
@@ -51,7 +51,7 @@ PJ *PROJECTION(wink2) {
static_cast<struct pj_opaque*>(P->opaque)->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_1").f);
P->es = 0.;
P->inv = nullptr;
- P->fwd = s_forward;
+ P->fwd = wink2_s_forward;
return P;
}