aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2017-12-20 11:56:42 +0100
committerGitHub <noreply@github.com>2017-12-20 11:56:42 +0100
commit523953739bb9e8b7c604d2c84dfbb646dfbe4395 (patch)
tree583ad6bde15579d91ac8c0900795e0959ba158e2
parent91be24dbd637c673f38d670f25913c57e92cea00 (diff)
parent15e5a2cafccca560b322dbbe93fe9e56dc94bc1d (diff)
downloadPROJ-523953739bb9e8b7c604d2c84dfbb646dfbe4395.tar.gz
PROJ-523953739bb9e8b7c604d2c84dfbb646dfbe4395.zip
Merge pull request #722 from kbevers/divide-by-zero-ccon
Avoid zero-division in ccon.
-rw-r--r--src/PJ_ccon.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/PJ_ccon.c b/src/PJ_ccon.c
index cf8a9f68..a8c178dd 100644
--- a/src/PJ_ccon.c
+++ b/src/PJ_ccon.c
@@ -25,12 +25,14 @@
#include <proj.h>
#include "projects.h"
+#define EPS10 1e-10
+
struct pj_opaque {
double phi1;
double ctgphi1;
double sinphi1;
double cosphi1;
- double *en;
+ double *en;
};
PROJ_HEAD(ccon, "Central Conic")
@@ -38,20 +40,20 @@ PROJ_HEAD(ccon, "Central Conic")
-static XY forward (LP lp, PJ *P) {
+static XY forward (LP lp, PJ *P) {
XY xy = {0.0,0.0};
struct pj_opaque *Q = P->opaque;
double r;
r = Q->ctgphi1 - tan(lp.phi - Q->phi1);
xy.x = r * sin(lp.lam * Q->sinphi1);
- xy.y = Q->ctgphi1 - r * cos(lp.lam * Q->sinphi1);
+ xy.y = Q->ctgphi1 - r * cos(lp.lam * Q->sinphi1);
return xy;
}
-static LP inverse (XY xy, PJ *P) {
+static LP inverse (XY xy, PJ *P) {
LP lp = {0.0,0.0};
struct pj_opaque *Q = P->opaque;
@@ -63,7 +65,7 @@ static LP inverse (XY xy, PJ *P) {
}
-static void *destructor (PJ *P, int errlev) {
+static void *destructor (PJ *P, int errlev) {
if (0==P)
return 0;
@@ -84,9 +86,11 @@ PJ *PROJECTION(ccon) {
P->destructor = destructor;
Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f;
+ if (fabs(Q->phi1) < EPS10)
+ return destructor (P, PJD_ERR_LAT1_IS_ZERO);
if (!(Q->en = pj_enfn(P->es)))
- return pj_default_destructor(P, ENOMEM);
+ return destructor(P, ENOMEM);
Q->sinphi1 = sin(Q->phi1);
Q->cosphi1 = cos(Q->phi1);
@@ -95,7 +99,7 @@ PJ *PROJECTION(ccon) {
P->inv = inverse;
P->fwd = forward;
-
+
return P;
}