[geos-commits] r4134 - in branches/3.4: . src/operation/overlay/snap tests/unit/operation/overlay/snap

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Dec 14 09:25:41 PST 2015


Author: strk
Date: 2015-12-14 09:25:41 -0800 (Mon, 14 Dec 2015)
New Revision: 4134

Modified:
   branches/3.4/NEWS
   branches/3.4/src/operation/overlay/snap/LineStringSnapper.cpp
   branches/3.4/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp
Log:
Fix snapping of last segment in a closed linestring

Fixes #758

Modified: branches/3.4/NEWS
===================================================================
--- branches/3.4/NEWS	2015-12-14 17:25:32 UTC (rev 4133)
+++ branches/3.4/NEWS	2015-12-14 17:25:41 UTC (rev 4134)
@@ -2,6 +2,7 @@
 YYYY-MM-DD
 
 - Bug fixes / improvements
+ - Fix snapping of last segment of a closed linestring (#758)
  - Improve robustness of intersection testing (#716)
  - Fixed build configuration for NMAKE with Visual Leak Detector enabled (#715)
  - Fixed compilation against thread-safe PHP (#541)

Modified: branches/3.4/src/operation/overlay/snap/LineStringSnapper.cpp
===================================================================
--- branches/3.4/src/operation/overlay/snap/LineStringSnapper.cpp	2015-12-14 17:25:32 UTC (rev 4133)
+++ branches/3.4/src/operation/overlay/snap/LineStringSnapper.cpp	2015-12-14 17:25:41 UTC (rev 4134)
@@ -153,13 +153,20 @@
     if (vertpos == srcCoords.begin() && isClosed)
     {
       vertpos = srcCoords.end(); --vertpos;
+#if GEOS_DEBUG
+cerr << " Snapped vertex was first in a closed line, also snapping last" << endl;
+#endif
       *vertpos = snapPt;
     }
 
+#if GEOS_DEBUG
+cerr << " After snapping of vertex " << snapPt << ", srcCoors are: " << srcCoords << endl;
+#endif
+
 	}
 
 #if GEOS_DEBUG
-cerr << " After vertex snapping, srcCoors are: " << srcCoords << endl;
+cerr << " After vertices snapping, srcCoors are: " << srcCoords << endl;
 #endif
 
 }
@@ -333,9 +340,11 @@
       LineSegment prevSeg(*segpos, seg.p0);
       if ( prevSeg.distance(newSnapPt) < seg.distance(newSnapPt) ) {
 #if GEOS_DEBUG
-        cerr << " Prev segment closer, inserting " << newSnapPt << " into " << prevSeg << endl;
+        cerr << " Prev segment closer, inserting " << newSnapPt << " into "
+             << prevSeg << endl;
 #endif
         // insert into prev segment
+        ++segpos;
         srcCoords.insert(segpos, newSnapPt);
       } else {
 #if GEOS_DEBUG

Modified: branches/3.4/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp
===================================================================
--- branches/3.4/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp	2015-12-14 17:25:32 UTC (rev 4133)
+++ branches/3.4/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp	2015-12-14 17:25:41 UTC (rev 4134)
@@ -329,4 +329,49 @@
     ensure_equals(ret->operator[](2), src_c);
   }
 
+  // Snap of last segment in closed linestring
+  // See https://trac.osgeo.org/geos/ticket/758
+  template<>
+  template<>
+  void object::test<9>()
+  {
+    using geos::geom::Coordinate;
+    using geos::operation::overlay::snap::LineStringSnapper;
+
+    typedef std::auto_ptr<Coordinate::Vect> CoordsVectAptr;
+
+
+    // Source: (1 1, 5 9, 9 1, 1 1)
+    Coordinate src_a(1, 1);
+    Coordinate src_b(5, 9);
+    Coordinate src_c(9, 1);
+    Coordinate::Vect srcCoords;
+    srcCoords.push_back(src_a);
+    srcCoords.push_back(src_b);
+    srcCoords.push_back(src_c);
+    srcCoords.push_back(src_a);
+
+    // Snap: (0 0, 10 0, 1 0.5)
+    Coordinate snp_a(0, 0);
+    Coordinate snp_b(10, 0);
+    Coordinate snp_c(1, 0.5);
+    Coordinate::ConstVect snpCoords;
+    snpCoords.push_back( &snp_a );
+    snpCoords.push_back( &snp_b );
+    snpCoords.push_back( &snp_c );
+
+    // Snap with tolerance of 2
+    // (both first and second point could be snapped)
+    LineStringSnapper snapper(srcCoords, 2);
+
+    // Expect: (0 0, 5 9, 10 0, 1 0.5, 0 0)
+    CoordsVectAptr ret(snapper.snapTo(snpCoords));
+    ensure_equals(ret->size(), 5u);
+    ensure_equals(ret->operator[](0), snp_a); //  0 0
+    ensure_equals(ret->operator[](1), src_b); //  5 9
+    ensure_equals(ret->operator[](2), snp_b); // 10 0
+    ensure_equals(ret->operator[](3), snp_c); //  1 0.5
+    ensure_equals(ret->operator[](4), snp_a); //  0 0
+  }
+
 } // namespace tut



More information about the geos-commits mailing list