aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Karney <charles@karney.com>2018-02-22 20:59:57 -0500
committerCharles Karney <charles@karney.com>2018-02-22 20:59:57 -0500
commit6d5e19110046ea2aefc645f40dfce4b3dadb8109 (patch)
tree1fa2dbcd199eb69cdc25294a6ccc4992c638ae38
parent3fcaf7dd2f5334908536126429bc6a4f26261bde (diff)
downloadPROJ-6d5e19110046ea2aefc645f40dfce4b3dadb8109.tar.gz
PROJ-6d5e19110046ea2aefc645f40dfce4b3dadb8109.zip
Fix issue #812
Implement Polygon AddEdge fix in C library (will be version 1.49.2 of C library for proj 5.0.0). Still to do: add tests to expand code coverage. This will only affect geodtest.c which is not part of the compiled library.
-rw-r--r--src/geodesic.c14
-rw-r--r--src/geodesic.h2
-rw-r--r--src/geodtest.c18
3 files changed, 28 insertions, 6 deletions
diff --git a/src/geodesic.c b/src/geodesic.c
index 233dc34c..6a383b72 100644
--- a/src/geodesic.c
+++ b/src/geodesic.c
@@ -89,10 +89,14 @@ static void Init() {
tolb = tol0 * tol2;
xthresh = 1000 * tol2;
degree = pi/180;
+ #if defined(NAN)
+ NaN = NAN;
+ #else
{
real minus1 = -1;
NaN = sqrt(minus1);
}
+ #endif
init = 1;
}
}
@@ -1809,13 +1813,13 @@ int transitdirect(real lon1, real lon2) {
#if HAVE_C99_MATH
lon1 = remainder(lon1, (real)(720));
lon2 = remainder(lon2, (real)(720));
- return ( (lon2 >= 0 && lon2 < 360 ? 0 : 1) -
- (lon1 >= 0 && lon1 < 360 ? 0 : 1) );
+ return ( (lon2 <= 0 && lon2 > -360 ? 1 : 0) -
+ (lon1 <= 0 && lon1 > -360 ? 1 : 0) );
#else
lon1 = fmod(lon1, (real)(720));
lon2 = fmod(lon2, (real)(720));
- return ( ((lon2 >= 0 && lon2 < 360) || lon2 < -360 ? 0 : 1) -
- ((lon1 >= 0 && lon1 < 360) || lon1 < -360 ? 0 : 1) );
+ return ( ((lon2 <= 0 && lon2 > -360) || lon2 > 360 ? 1 : 0) -
+ ((lon1 <= 0 && lon1 > -360) || lon1 > 360 ? 1 : 0) );
#endif
}
@@ -1888,7 +1892,7 @@ void geod_polygon_addpoint(const struct geod_geodesic* g,
void geod_polygon_addedge(const struct geod_geodesic* g,
struct geod_polygon* p,
real azi, real s) {
- if (p->num) { /* Do nothing is num is zero */
+ if (p->num) { /* Do nothing is num is zero */
real lat, lon, S12 = 0; /* Initialize S12 to stop Visual Studio warning */
geod_gendirect(g, p->lat, p->lon, azi, GEOD_LONG_UNROLL, s,
&lat, &lon, 0,
diff --git a/src/geodesic.h b/src/geodesic.h
index 43fd0d1f..536ba7c4 100644
--- a/src/geodesic.h
+++ b/src/geodesic.h
@@ -132,7 +132,7 @@
* The patch level of the geodesic library. (This tracks the version of
* GeographicLib.)
**********************************************************************/
-#define GEODESIC_VERSION_PATCH 1
+#define GEODESIC_VERSION_PATCH 2
/**
* Pack the version components into a single integer. Users should not rely on
diff --git a/src/geodtest.c b/src/geodtest.c
index 0f2c0ac2..517e5bed 100644
--- a/src/geodtest.c
+++ b/src/geodtest.c
@@ -787,6 +787,23 @@ static int Planimeter13() {
return result;
}
+static int AddEdge1() {
+ /* Check fix to transitdirect vs transit zero handling inconsistency */
+ struct geod_geodesic g;
+ struct geod_polygon p;
+ double area;
+ int result = 0;
+ geod_init(&g, wgs84_a, wgs84_f);
+ geod_polygon_init(&p, 0);
+ geod_polygon_addpoint(&g, &p, 0, 0);
+ geod_polygon_addedge(&g, &p, 90, 1000);
+ geod_polygon_addedge(&g, &p, 0, 1000);
+ geod_polygon_addedge(&g, &p, -90, 1000);
+ geod_polygon_compute(&g, &p, 0, 1, &area, 0);
+ result += assertEquals(area, 1000000.0, 0.01);
+ return result;
+}
+
int main() {
int n = 0, i;
if ((i = testinverse())) {++n; printf("testinverse fail: %d\n", i);}
@@ -823,6 +840,7 @@ int main() {
if ((i = Planimeter6())) {++n; printf("Planimeter6 fail: %d\n", i);}
if ((i = Planimeter12())) {++n; printf("Planimeter12 fail: %d\n", i);}
if ((i = Planimeter13())) {++n; printf("Planimeter13 fail: %d\n", i);}
+ if ((i = AddEdge1())) {++n; printf("AddEdge1 fail: %d\n", i);}
return n;
}