[geos-commits] r3887 - in branches/3.3: src/operation/overlay/snap tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Aug 16 08:29:41 PDT 2013


Author: strk
Date: 2013-08-16 08:29:40 -0700 (Fri, 16 Aug 2013)
New Revision: 3887

Modified:
   branches/3.3/src/operation/overlay/snap/LineStringSnapper.cpp
   branches/3.3/tests/unit/capi/GEOSSnapTest.cpp
Log:
Fix assertion failure in snapping code (#649)

The bug affected attempts to snapping lines to the points
of a rectangle with a side smaller than the tolerance.

Modified: branches/3.3/src/operation/overlay/snap/LineStringSnapper.cpp
===================================================================
--- branches/3.3/src/operation/overlay/snap/LineStringSnapper.cpp	2013-08-16 15:26:51 UTC (rev 3886)
+++ branches/3.3/src/operation/overlay/snap/LineStringSnapper.cpp	2013-08-16 15:29:40 UTC (rev 3887)
@@ -352,7 +352,7 @@
     CoordinateList::iterator to = segpos; ++to;
     LineSegment seg(*segpos, *to);
     double pf = seg.projectionFactor(snapPt);
-    if ( pf > 1.0 ) {
+    if ( pf >= 1.0 ) {
 #if GEOS_DEBUG
       cerr << " Segment to be snapped is closer on his end point" << endl;
 #endif
@@ -391,7 +391,7 @@
         srcCoords.insert(segpos, newSnapPt);
       }
     }
-    else if ( pf < 0.0 ) {
+    else if ( pf <= 0.0 ) {
 #if GEOS_DEBUG
       cerr << " Segment to be snapped is closer on his start point" << endl;
 #endif
@@ -436,7 +436,7 @@
       }
     }
     else {
-      assert(pf != 0.0);
+      //assert(pf != 0.0);
 #if GEOS_DEBUG
 cerr << " Segment to be snapped found, projection factor is " << pf << ", inserting point" << endl;
 #endif

Modified: branches/3.3/tests/unit/capi/GEOSSnapTest.cpp
===================================================================
--- branches/3.3/tests/unit/capi/GEOSSnapTest.cpp	2013-08-16 15:26:51 UTC (rev 3886)
+++ branches/3.3/tests/unit/capi/GEOSSnapTest.cpp	2013-08-16 15:29:40 UTC (rev 3887)
@@ -43,6 +43,7 @@
             initGEOS(notice, notice);
             w_ = GEOSWKTWriter_create();
             GEOSWKTWriter_setTrim(w_, 1);
+            GEOSWKTWriter_setRoundingPrecision(w_, 8);
         }       
 
         ~test_capigeossnap_data()
@@ -217,5 +218,21 @@
         ensure_equals(out, "LINESTRING (0 2, 5 2, 9 2, 5 0)");
     }
 
+    // See http://trac.osgeo.org/geos/ticket/649
+    template<>
+    template<>
+    void object::test<10>()
+    {
+        geom1_ = GEOSGeomFromWKT("LINESTRING(-71.1317 42.2511,-71.1317 42.2509)");
+        geom2_ = GEOSGeomFromWKT("MULTIPOINT(-71.1261 42.2703,-71.1257 42.2703,-71.1261 42.2702)");
+        geom3_ = GEOSSnap(geom1_, geom2_, 0.5);
+
+        char* wkt_c = GEOSWKTWriter_write(w_, geom3_);
+        std::string out(wkt_c); 
+        free(wkt_c);
+
+        ensure_equals(out, "LINESTRING (-71.1257 42.2703, -71.1261 42.2703, -71.1261 42.2702, -71.1317 42.2509)");
+    }
+
 } // namespace tut
 



More information about the geos-commits mailing list