aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJavier Goizueta <jgoizueta@gmail.com>2018-04-11 17:56:08 +0200
committerKristian Evers <kristianevers@gmail.com>2018-04-12 20:03:01 +0200
commit647637f81247d341b8865d5d0eda1cad3c8cec8a (patch)
tree5bb23f888e1e64c20df9458fbb37859e487fa1a9 /src
parent92168bc712d72d68b010c9d0495dccb0807a39bf (diff)
downloadPROJ-647637f81247d341b8865d5d0eda1cad3c8cec8a.tar.gz
PROJ-647637f81247d341b8865d5d0eda1cad3c8cec8a.zip
Enhance the precision of Spherical Mercator projection near the equator
This uses a linear approximation of tan(x+pi/4) for better precision at small latitudes. As a result points of latitude 0 maintain a 0 Y coordinate and 0,0 is transformed to 0,0
Diffstat (limited to 'src')
-rw-r--r--src/PJ_merc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/PJ_merc.c b/src/PJ_merc.c
index a3e5e846..3801b828 100644
--- a/src/PJ_merc.c
+++ b/src/PJ_merc.c
@@ -8,6 +8,13 @@ PROJ_HEAD(webmerc, "Web Mercator / Pseudo Mercator") "\n\tCyl, Sph\n\t";
#define EPS10 1.e-10
+static double _tan_near_fort_pi(double x) {
+ if (fabs(x) <= __DBL_EPSILON__) {
+ return 2*x + 1.0;
+ }
+ return tan(M_FORTPI + x);
+}
+
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
if (fabs(fabs(lp.phi) - M_HALFPI) <= EPS10) {
@@ -27,7 +34,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
return xy;
}
xy.x = P->k0 * lp.lam;
- xy.y = P->k0 * log(tan(M_FORTPI + .5 * lp.phi));
+ xy.y = P->k0 * log(_tan_near_fort_pi(.5 * lp.phi));
return xy;
}