[geos-commits] r3360 - in trunk: src/algorithm tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Thu May 12 05:56:04 EDT 2011


Author: strk
Date: 2011-05-12 02:56:04 -0700 (Thu, 12 May 2011)
New Revision: 3360

Modified:
   trunk/src/algorithm/RobustDeterminant.cpp
   trunk/tests/unit/capi/GEOSIntersectsTest.cpp
Log:
Have RobustDeterminant throw an IllegalArgument if passed any infinite or nan value. Fixes bug #357. Includes regress test.

Modified: trunk/src/algorithm/RobustDeterminant.cpp
===================================================================
--- trunk/src/algorithm/RobustDeterminant.cpp	2011-05-12 07:39:23 UTC (rev 3359)
+++ trunk/src/algorithm/RobustDeterminant.cpp	2011-05-12 09:56:04 UTC (rev 3360)
@@ -20,9 +20,12 @@
  **********************************************************************/
 
 #include <geos/algorithm/RobustDeterminant.h>
+#include <geos/util/IllegalArgumentException.h>
 
 #include <cmath>
 
+#include <geos/platform.h> // for ISNAN, FINITE
+
 #ifdef _MSC_VER
 #pragma warning(disable : 4127)
 #endif
@@ -40,6 +43,15 @@
 	double k;
 	long count=0;
 
+  using std::isfinite;
+
+  // Protect against non-finite numbers
+  if ( ISNAN(x1)   || ISNAN(y1)   || ISNAN(x2)   || ISNAN(y2) ||
+       !FINITE(x1) || !FINITE(y1) || !FINITE(x2) || !FINITE(y2) )
+  {
+    throw util::IllegalArgumentException("RobustDeterminant encountered non-finite numbers ");
+  }
+
 	/*
 	*  testing null entries
 	*/

Modified: trunk/tests/unit/capi/GEOSIntersectsTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSIntersectsTest.cpp	2011-05-12 07:39:23 UTC (rev 3359)
+++ trunk/tests/unit/capi/GEOSIntersectsTest.cpp	2011-05-12 09:56:04 UTC (rev 3360)
@@ -9,6 +9,7 @@
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
+#include <cstring>
 
 namespace tut
 {
@@ -117,7 +118,7 @@
         ensure_equals(int(r2), 1);
     }
 
-    // This is a tef for bug #357
+    // This is a test for bug #357 (GEOSIntersects with nan coords)
     template<>
     template<>
     void object::test<4>()
@@ -132,15 +133,31 @@
         }
         GEOSCoordSeq_setX(cs, 4, 1); GEOSCoordSeq_setY(cs, 4, 1);
 
-	geom1_ = GEOSGeom_createPolygon(
-		GEOSGeom_createLinearRing(cs),
-		NULL, 0);
+        geom1_ = GEOSGeom_createPolygon(GEOSGeom_createLinearRing(cs),
+                                        NULL, 0);
 
         char const r1 = GEOSIntersects(geom1_, geom1_);
 
-        ensure_equals(int(r1), 1);
+        ensure_equals(int(r1), 2);
         
     }
+
+    // This is a test for bug #357 (GEOSIntersects with inf coords)
+    template<>
+    template<>
+    void object::test<5>()
+    {
+        const char *hex = "0103000020E61000000100000005000000737979F3DDCC2CC0F92154F9E7534540000000000000F07F000000000000F07F8F806E993F7E55C0304B29FFEA8554400634E8D1DD424540B5FEE6A37FCD4540737979F3DDCC2CC0F92154F9E7534540";
+
+        geom1_ = GEOSGeomFromHEX_buf((unsigned char*)hex, std::strlen(hex));
+        
+        ensure( 0 != geom1_ );
+
+        char const r1 = GEOSIntersects(geom1_, geom1_);
+
+        ensure_equals(int(r1), 2);
+        
+    }
  
 } // namespace tut
 



More information about the geos-commits mailing list