diff options
| author | Thomas Knudsen <busstoptaktik@users.noreply.github.com> | 2017-11-15 09:05:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-15 09:05:41 +0100 |
| commit | cff58ea23f20306d7cc0410b808f0d46d73e6978 (patch) | |
| tree | 45605d518d585a632259e7600d919c591dae33a7 /src | |
| parent | 7aeb1fb3aaf5a7c14ba2a0513d5eca13a9ddd9d0 (diff) | |
| download | PROJ-cff58ea23f20306d7cc0410b808f0d46d73e6978.tar.gz PROJ-cff58ea23f20306d7cc0410b808f0d46d73e6978.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/adjlon.c | 25 |
1 files 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 <math.h> -#include <projects.h> - -#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; } |
