[geos-commits] r4131 - in branches/3.5: . src/operation/overlay/snap tests/unit/operation/overlay/snap
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Dec 14 09:20:49 PST 2015
Author: strk
Date: 2015-12-14 09:20:49 -0800 (Mon, 14 Dec 2015)
New Revision: 4131
Modified:
branches/3.5/NEWS
branches/3.5/src/operation/overlay/snap/LineStringSnapper.cpp
branches/3.5/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp
Log:
Fix snapping of last segment in a closed linestring
See #758
Modified: branches/3.5/NEWS
===================================================================
--- branches/3.5/NEWS 2015-12-14 17:20:41 UTC (rev 4130)
+++ branches/3.5/NEWS 2015-12-14 17:20:49 UTC (rev 4131)
@@ -5,6 +5,7 @@
- Fix CMake configuration to allow build from released sources package (#753)
- Fix memory leaks in single-sided buffers (#747), PlanarGraph and tests
- Fix GeometryEditor to correctly update factory of empty geometries (#749)
+ - Fix snapping of last segment of a closed linestring (#758)
Changes in 3.5.0
2015-08-15
Modified: branches/3.5/src/operation/overlay/snap/LineStringSnapper.cpp
===================================================================
--- branches/3.5/src/operation/overlay/snap/LineStringSnapper.cpp 2015-12-14 17:20:41 UTC (rev 4130)
+++ branches/3.5/src/operation/overlay/snap/LineStringSnapper.cpp 2015-12-14 17:20:49 UTC (rev 4131)
@@ -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.5/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp
===================================================================
--- branches/3.5/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp 2015-12-14 17:20:41 UTC (rev 4130)
+++ branches/3.5/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp 2015-12-14 17:20:49 UTC (rev 4131)
@@ -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