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

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Apr 27 10:13:45 EDT 2011


Author: strk
Date: 2011-04-27 07:13:45 -0700 (Wed, 27 Apr 2011)
New Revision: 3306

Modified:
   trunk/include/geos/operation/buffer/OffsetCurveSetBuilder.h
   trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp
   trunk/tests/unit/capi/GEOSBufferTest.cpp
Log:
Add test for singlesided buffer (areal). Fix premature exit from OffsetCurveSetBuilder.

Modified: trunk/include/geos/operation/buffer/OffsetCurveSetBuilder.h
===================================================================
--- trunk/include/geos/operation/buffer/OffsetCurveSetBuilder.h	2011-04-27 13:38:53 UTC (rev 3305)
+++ trunk/include/geos/operation/buffer/OffsetCurveSetBuilder.h	2011-04-27 14:13:45 UTC (rev 3306)
@@ -14,7 +14,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/buffer/OffsetCurveSetBuilder.java r262 (JTS-1.11+)
+ * Last port: operation/buffer/OffsetCurveSetBuilder.java r378 (JTS-1.12)
  *
  **********************************************************************/
 

Modified: trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp
===================================================================
--- trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp	2011-04-27 13:38:53 UTC (rev 3305)
+++ trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp	2011-04-27 14:13:45 UTC (rev 3306)
@@ -15,7 +15,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/buffer/OffsetCurveSetBuilder.java r262 (JTS-1.11+)
+ * Last port: operation/buffer/OffsetCurveSetBuilder.java r378 (JTS-1.12)
  *
  **********************************************************************/
 
@@ -194,7 +194,11 @@
 void
 OffsetCurveSetBuilder::addLineString(const LineString *line)
 {
-	if (distance <= 0.0) return;
+	if (distance <= 0.0 && ! curveBuilder.getBufferParameters().isSingleSided())
+	{
+		return;
+	}
+
 #if GEOS_DEBUG
 	std::cerr<<__FUNCTION__<<": "<<line->toString()<<std::endl;
 #endif

Modified: trunk/tests/unit/capi/GEOSBufferTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSBufferTest.cpp	2011-04-27 13:38:53 UTC (rev 3305)
+++ trunk/tests/unit/capi/GEOSBufferTest.cpp	2011-04-27 14:13:45 UTC (rev 3306)
@@ -23,6 +23,8 @@
         GEOSGeometry* geom1_;
         GEOSGeometry* geom2_;
         char* wkt_;
+        GEOSBufferParams* bp_;
+        GEOSWKTWriter* wktw_;
         double area_;
 
         static void notice(const char *fmt, ...)
@@ -38,15 +40,19 @@
         }
 
         test_capigeosbuffer_data()
-            : geom1_(0), geom2_(0), wkt_(0)
+            : geom1_(0), geom2_(0), wkt_(0), bp_(0)
         {
             initGEOS(notice, notice);
+            wktw_ = GEOSWKTWriter_create();
+            GEOSWKTWriter_setTrim(wktw_, 1);
         }       
 
         ~test_capigeosbuffer_data()
         {
             GEOSGeom_destroy(geom1_);
             GEOSGeom_destroy(geom2_);
+            GEOSWKTWriter_destroy(wktw_);
+            GEOSBufferParams_destroy(bp_);
             GEOSFree(wkt_);
             geom1_ = 0;
             geom2_ = 0;
@@ -444,5 +450,81 @@
 
     }
 
+    // Buffer with params:
+    // flat end cap on a straight line
+    template<>
+    template<>
+    void object::test<17>()
+    {
+        geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
+
+        ensure( 0 != geom1_ );
+
+        bp_ = GEOSBufferParams_create();
+
+        GEOSBufferParams_setEndCapStyle(bp_, GEOSBUF_CAP_SQUARE);
+        geom2_ = GEOSBufferWithParams(geom1_, bp_, 2);
+
+        ensure( 0 != geom2_ );
+
+        wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
+
+        ensure_equals(std::string(wkt_), std::string(
+"POLYGON ((10 12, 12 12, 12 8, 5 8, 3 8, 3 12, 10 12))"
+));
+    }
+
+    // Buffer with params:
+    // flat end cap on a straight line
+    // Single sided (left)
+    template<>
+    template<>
+    void object::test<18>()
+    {
+        geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
+
+        ensure( 0 != geom1_ );
+
+        bp_ = GEOSBufferParams_create();
+
+        GEOSBufferParams_setEndCapStyle(bp_, GEOSBUF_CAP_SQUARE);
+        GEOSBufferParams_setSingleSided(bp_, 1);
+        geom2_ = GEOSBufferWithParams(geom1_, bp_, 2);
+
+        ensure( 0 != geom2_ );
+
+        wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
+
+        ensure_equals(std::string(wkt_), std::string(
+"POLYGON ((10 10, 5 10, 5 12, 10 12, 10 10))"
+));
+    }
+
+    // Buffer with params:
+    // flat end cap on a straight line
+    // Single sided (right)
+    template<>
+    template<>
+    void object::test<19>()
+    {
+        geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
+
+        ensure( 0 != geom1_ );
+
+        bp_ = GEOSBufferParams_create();
+
+        GEOSBufferParams_setEndCapStyle(bp_, GEOSBUF_CAP_SQUARE);
+        GEOSBufferParams_setSingleSided(bp_, 1);
+        geom2_ = GEOSBufferWithParams(geom1_, bp_, -2);
+
+        ensure( 0 != geom2_ );
+
+        wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
+
+        ensure_equals(std::string(wkt_), std::string(
+"POLYGON ((5 10, 10 10, 10 8, 5 8, 5 10))"
+));
+    }
+
 } // namespace tut
 



More information about the geos-commits mailing list