[geos-commits] r4007 - in trunk: src/triangulate/quadedge tests/unit/triangulate/quadedge

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Sep 16 08:00:44 PDT 2014


Author: strk
Date: 2014-09-16 08:00:44 -0700 (Tue, 16 Sep 2014)
New Revision: 4007

Modified:
   trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
   trunk/tests/unit/triangulate/quadedge/QuadEdgeSubdivisionTest.cpp
Log:
Do not output duplicated vertices from QuadEdgeSubdivision class (#705)

Includes testcase

Modified: trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
===================================================================
--- trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp	2014-09-16 09:52:21 UTC (rev 4006)
+++ trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp	2014-09-16 15:00:44 UTC (rev 4007)
@@ -559,7 +559,8 @@
 	QuadEdge *startQE = qe;
 	do{
 		Coordinate cc = qe->rot().orig().getCoordinate();
-		cellPts.push_back(cc);
+		if ( cellPts.empty() || cellPts.back() != cc ) // no duplicates
+			cellPts.push_back(cc);
 		qe = &qe->oPrev();
 
 	}while ( qe != startQE);
@@ -572,7 +573,6 @@
 
 	if(coordList.size() < 4)
 	{
-		cout << coordList << endl;
 		coordList.insert(coordList.end(),*(coordList.end()),true);
 	}
 	
@@ -594,7 +594,8 @@
 	QuadEdge *startQE = qe;
 	do{
 		Coordinate cc = qe->rot().orig().getCoordinate();
-		cellPts.push_back(cc);
+		if ( cellPts.empty() || cellPts.back() != cc ) // no duplicates
+			cellPts.push_back(cc);
 		qe = &qe->oPrev();
 
 	}while ( qe != startQE);

Modified: trunk/tests/unit/triangulate/quadedge/QuadEdgeSubdivisionTest.cpp
===================================================================
--- trunk/tests/unit/triangulate/quadedge/QuadEdgeSubdivisionTest.cpp	2014-09-16 09:52:21 UTC (rev 4006)
+++ trunk/tests/unit/triangulate/quadedge/QuadEdgeSubdivisionTest.cpp	2014-09-16 15:00:44 UTC (rev 4007)
@@ -10,10 +10,12 @@
 #include <geos/triangulate/quadedge/QuadEdgeSubdivision.h>
 #include <geos/triangulate/DelaunayTriangulationBuilder.h>
 #include <geos/geom/PrecisionModel.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/Polygon.h>
 #include <geos/geom/GeometryCollection.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/CoordinateSequence.h>
-//#include <geos/io/WKTWriter.h>
+#include <geos/io/WKTWriter.h>
 #include <geos/io/WKTReader.h>
 #include <geos/geom/Envelope.h>
 #include <geos/geom/Coordinate.h>
@@ -38,12 +40,15 @@
 		geos::geom::PrecisionModel pm;
 		geos::geom::GeometryFactory gf;
 		geos::io::WKTReader reader;
+		geos::io::WKTWriter writer;
 		test_quadedgesub_data()
       :
 			pm(),
 			gf(&pm),
-			reader(gf)
+			reader(gf),
+			writer()
 		{
+			writer.setTrim(true);
 		}
 	};
 
@@ -115,6 +120,51 @@
 //		ensure(polys->getCoordinateDimension() == expected->getCoordinateDimension());
 	}
 
+  // Test that returned polygons do not have duplicated points
+  // See http://trac.osgeo.org/geos/ticket/705
+  template<> template<> void object::test<3>()
+  {
+    const char *wkt = 
+      "MULTIPOINT ("
+        " (170 270),"
+        " (190 230),"
+        " (230 250),"
+        " (210 290)"
+      ")";
+    std::auto_ptr<Geometry> sites ( reader.read(wkt) );
+    std::auto_ptr<CoordinateSequence> siteCoords (
+      DelaunayTriangulationBuilder::extractUniqueCoordinates(*sites)
+    );
+
+    Envelope env = DelaunayTriangulationBuilder::envelope(*siteCoords);
+    double expandBy = std::max(env.getWidth() , env.getHeight());
+    env.expandBy(expandBy);
+    std::auto_ptr<QuadEdgeSubdivision> subdiv(
+      new quadedge::QuadEdgeSubdivision(env,10)
+    );
+
+    std::auto_ptr<IncrementalDelaunayTriangulator::VertexList> vertices (
+      DelaunayTriangulationBuilder::toVertices(*siteCoords)
+    );
+
+    IncrementalDelaunayTriangulator triangulator(subdiv.get());
+    triangulator.insertSites(*vertices);
+
+    //Test for getVoronoiDiagram::
+    GeometryFactory geomFact;
+    std::auto_ptr<GeometryCollection> polys = subdiv->getVoronoiDiagram(geomFact);
+    for (std::size_t i=0; i<polys->getNumGeometries(); ++i) {
+      const Polygon* p = dynamic_cast<const Polygon*>(polys->getGeometryN(i));
+      ensure(p);
+      std::auto_ptr<CoordinateSequence> cs (
+        p->getExteriorRing()->getCoordinates()
+      );
+      size_t from = cs->size();
+      cs->removeRepeatedPoints();
+      ensure_equals(from, cs->size());
+    }
+  }
+
 } // namespace tut
 
 



More information about the geos-commits mailing list