From cff58ea23f20306d7cc0410b808f0d46d73e6978 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Wed, 15 Nov 2017 09:05:41 +0100 Subject: Adjust adjlon to use canonical M_PI defines (#665) A year or so ago, @micahcochran put quite some effort into rationalizing the PI usage in PROJ.4, by ensuring that a useful number of M_PI related constants were defined in projects.h. But apparently adjlon.c was left behind still using its own set of definitions - perhaps because it bends the values slightly, to avoid unwanted sign switching near the date line. In this PR the "bending trick" is reimplemented using the rationalized M_PI constants only. --- src/adjlon.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/adjlon.c b/src/adjlon.c index 09b3b14b..784a90aa 100644 --- a/src/adjlon.c +++ b/src/adjlon.c @@ -1,15 +1,20 @@ /* reduce argument to range +/- PI */ #include -#include - -#define SPI 3.14159265359 -#define TWOPI 6.2831853071795864769 -#define ONEPI 3.14159265358979323846 +#include "projects.h" double adjlon (double lon) { - if (fabs(lon) <= SPI) return( lon ); - lon += ONEPI; /* adjust to 0..2pi rad */ - lon -= TWOPI * floor(lon / TWOPI); /* remove integral # of 'revolutions'*/ - lon -= ONEPI; /* adjust back to -pi..pi rad */ - return( lon ); + /* Let lon slightly overshoot, to avoid spurious sign switching at the date line */ + if (fabs (lon) < M_PI + 1e-12) + return lon; + + /* adjust to 0..2pi range */ + lon += M_PI; + + /* remove integral # of 'revolutions'*/ + lon -= M_TWOPI * floor(lon / M_TWOPI); + + /* adjust back to -pi..pi range */ + lon -= M_PI; + + return lon; } -- cgit v1.2.3