[geos-commits] r3846 - in trunk: src/operation/buffer tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Jul 17 09:07:57 PDT 2013


Author: strk
Date: 2013-07-17 09:07:56 -0700 (Wed, 17 Jul 2013)
New Revision: 3846

Modified:
   trunk/src/operation/buffer/OffsetCurveBuilder.cpp
   trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp
Log:
Make GEOSOffsetCurve survive single-point input (with an exception)

Modified: trunk/src/operation/buffer/OffsetCurveBuilder.cpp
===================================================================
--- trunk/src/operation/buffer/OffsetCurveBuilder.cpp	2013-07-17 15:58:30 UTC (rev 3845)
+++ trunk/src/operation/buffer/OffsetCurveBuilder.cpp	2013-07-17 16:07:56 UTC (rev 3846)
@@ -36,6 +36,7 @@
 #include <geos/algorithm/NotRepresentableException.h>
 #include <geos/algorithm/HCoordinate.h>
 #include <geos/util.h>
+#include <geos/util/IllegalArgumentException.h>
 
 #ifndef GEOS_DEBUG
 #define GEOS_DEBUG 0
@@ -128,6 +129,8 @@
 
 
     int n1 = simp1.size() - 1;
+    if ( ! n1 ) 
+      throw util::IllegalArgumentException("Cannot get offset of single-vertex line");
     segGen->initSideSegments(simp1[0], simp1[1], Position::LEFT);
     segGen->addFirstSegment();
     for (int i = 2; i <= n1; ++i) {
@@ -145,6 +148,8 @@
     const CoordinateSequence& simp2 = *simp2_;
 
     int n2 = simp2.size() - 1;
+    if ( ! n2 ) 
+      throw util::IllegalArgumentException("Cannot get offset of single-vertex line");
     segGen->initSideSegments(simp2[n2], simp2[n2-1], Position::LEFT);
     segGen->addFirstSegment();
     for (int i = n2-2; i >= 0; --i) {

Modified: trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp	2013-07-17 15:58:30 UTC (rev 3845)
+++ trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp	2013-07-17 16:07:56 UTC (rev 3846)
@@ -244,9 +244,7 @@
         geom2_ = GEOSOffsetCurve(geom1_, width, 8, GEOSBUF_JOIN_ROUND, 0);
         ensure( "Unexpected exception", 0 != geom2_ );
         wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
-        GEOSGeom_destroy(geom2_); geom2_ = 0;
         ensure_equals(std::string(wkt_), "LINESTRING (10 9, 1 9, 1 0)");
-        GEOSFree(wkt_); wkt_ = 0;
     }
 
     // Test duplicated final vertex in input 
@@ -263,10 +261,23 @@
         geom2_ = GEOSOffsetCurve(geom1_, width, 8, GEOSBUF_JOIN_ROUND, 0);
         ensure( "Unexpected exception", 0 != geom2_ );
         wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
-        GEOSGeom_destroy(geom2_); geom2_ = 0;
         ensure_equals(std::string(wkt_), "LINESTRING (1 10, 1 0)");
-        GEOSFree(wkt_); wkt_ = 0;
     }
 
+    // Test only duplicated vertex in input 
+    // See http://trac.osgeo.org/postgis/ticket/602
+    template<>
+    template<>
+    void object::test<10>()
+    {
+        double width = -1;
+
+        geom1_ = GEOSGeomFromWKT("LINESTRING(0 10,0 10,0 10)");
+        ensure( 0 != geom1_ );
+
+        geom2_ = GEOSOffsetCurve(geom1_, width, 8, GEOSBUF_JOIN_ROUND, 0);
+        ensure( "Missing expected exception", 0 == geom2_ );
+    }
+
 } // namespace tut
 



More information about the geos-commits mailing list