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

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Jul 11 08:34:43 PDT 2013


Author: strk
Date: 2013-07-11 08:34:43 -0700 (Thu, 11 Jul 2013)
New Revision: 3835

Modified:
   trunk/include/geos/triangulate/quadedge/QuadEdge.h
   trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
   trunk/include/geos/triangulate/quadedge/Vertex.h
   trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
   trunk/tests/unit/triangulate/DelaunayTest.cpp
Log:
Fix memory in QuadEdgeSubdivision (#604)

Modified: trunk/include/geos/triangulate/quadedge/QuadEdge.h
===================================================================
--- trunk/include/geos/triangulate/quadedge/QuadEdge.h	2013-07-11 08:21:54 UTC (rev 3834)
+++ trunk/include/geos/triangulate/quadedge/QuadEdge.h	2013-07-11 15:34:43 UTC (rev 3835)
@@ -33,14 +33,14 @@
  * The quadedge algebra was described in a well-known paper by Guibas and Stolfi,
  * "Primitives for the manipulation of general subdivisions and the computation of Voronoi diagrams", 
  * <i>ACM Transactions on Graphics</i>, 4(2), 1985, 75-123.
- * <p>
+ * 
  * Each edge object is part of a quartet of 4 edges,
  * linked via their <tt>_rot</tt> references.
  * Any edge in the group may be accessed using a series of {@link #rot()} operations.
  * Quadedges in a subdivision are linked together via their <tt>next</tt> references.
  * The linkage between the quadedge quartets determines the topology
  * of the subdivision. 
- * <p>
+ *
  * The edge class does not contain separate information for vertice or faces; a vertex is implicitly
  * defined as a ring of edges (created using the <tt>next</tt> field).
  * 
@@ -151,6 +151,8 @@
 	 * that this quadedge quartet no longer participates
 	 * in a subdivision.
 	 *
+	 * NOTE: called "delete" in JTS
+	 *
 	 */
 	void remove();
 	

Modified: trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
===================================================================
--- trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h	2013-07-11 08:21:54 UTC (rev 3834)
+++ trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h	2013-07-11 15:34:43 UTC (rev 3835)
@@ -91,7 +91,7 @@
 
 private:
 	QuadEdgeList quadEdges;
-	QuadEdgeList removedEdges;
+	QuadEdgeList createdEdges;
 	QuadEdge* startingEdges[3];
 	double tolerance;
 	double edgeCoincidenceTolerance;

Modified: trunk/include/geos/triangulate/quadedge/Vertex.h
===================================================================
--- trunk/include/geos/triangulate/quadedge/Vertex.h	2013-07-11 08:21:54 UTC (rev 3834)
+++ trunk/include/geos/triangulate/quadedge/Vertex.h	2013-07-11 15:34:43 UTC (rev 3835)
@@ -43,15 +43,15 @@
  * Models a site (node) in a {@link QuadEdgeSubdivision}. 
  * The sites can be points on a line string representing a
  * linear site. 
- * <p>
+ * 
  * The vertex can be considered as a vector with a norm, length, inner product, cross
  * product, etc. Additionally, point relations (e.g., is a point to the left of a line, the circle
  * defined by this point and two others, etc.) are also defined in this class.
- * <p>
+ *
  * It is common to want to attach user-defined data to 
  * the vertices of a subdivision.  
  * One way to do this is to subclass <tt>Vertex</tt>
- * to carry any desired information (see {@link ConstraintVertex}.
+ * to carry any desired information (see {@link ConstraintVertex}).
  * 
  * @author JTS: David Skea
  * @author JTS: Martin Davis

Modified: trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
===================================================================
--- trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp	2013-07-11 08:21:54 UTC (rev 3834)
+++ trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp	2013-07-11 15:34:43 UTC (rev 3835)
@@ -63,23 +63,20 @@
 	createFrame(env);
 	initSubdiv(startingEdges);
 	quadEdges.push_back(startingEdges[0]);
+	createdEdges.push_back(startingEdges[0]);
 	quadEdges.push_back(startingEdges[1]);
+	createdEdges.push_back(startingEdges[1]);
 	quadEdges.push_back(startingEdges[2]);
+	createdEdges.push_back(startingEdges[2]);
 }
 
 QuadEdgeSubdivision::~QuadEdgeSubdivision()
 {
-	for(QuadEdgeList::iterator iter=quadEdges.begin(); iter!=quadEdges.end(); ++iter)
+	for(QuadEdgeList::iterator iter=createdEdges.begin(); iter!=createdEdges.end(); ++iter)
 	{
 		(*iter)->free();
 		delete *iter;
 	}
-
-	for(QuadEdgeList::iterator iter=removedEdges.begin(); iter!=removedEdges.end(); ++iter)
-	{
-		(*iter)->free();
-		delete *iter;
-	}
 }
 
 void
@@ -134,6 +131,7 @@
 	QuadEdge *q0_ptr = q0.get();
 	q0.release();
 
+	createdEdges.push_back(q0_ptr);
 	quadEdges.push_back(q0_ptr);
 	return *q0_ptr;
 }
@@ -145,6 +143,7 @@
 	QuadEdge *q0_ptr = q0.get();
 	q0.release();
 
+	createdEdges.push_back(q0_ptr);
 	quadEdges.push_back(q0_ptr);
 	return *q0_ptr;
 }
@@ -161,9 +160,6 @@
 	//mark these edges as removed
 	e.remove();
 
-	//keep a list of removed edges so that we can
-	//properly free memory
-	removedEdges.push_back(&e);
 }
 
 QuadEdge*

Modified: trunk/tests/unit/triangulate/DelaunayTest.cpp
===================================================================
--- trunk/tests/unit/triangulate/DelaunayTest.cpp	2013-07-11 08:21:54 UTC (rev 3834)
+++ trunk/tests/unit/triangulate/DelaunayTest.cpp	2013-07-11 15:34:43 UTC (rev 3835)
@@ -41,13 +41,14 @@
 	group test_incdelaunaytri_group("geos::triangulate::Delaunay");
 
 	//helper function for funning triangulation
-	void runDelaunay(const char *sitesWkt, bool computeTriangles, const char *expectedWkt)
+	void runDelaunay(const char *sitesWkt, bool computeTriangles, const char *expectedWkt, double tolerance=0.0)
 	{
 		WKTReader reader;
 		std::auto_ptr<Geometry> results;
 		Geometry *sites = reader.read(sitesWkt);
 		Geometry *expected = reader.read(expectedWkt);
 		DelaunayTriangulationBuilder builder;
+		builder.setTolerance(tolerance);
 		GeometryFactory geomFact;
 
 		builder.setSites(*sites);
@@ -59,8 +60,8 @@
 		results->normalize();
 		expected->normalize();
 			
-		ensure(results->equalsExact(expected, 1e-7));
-		ensure(results->getCoordinateDimension() == expected->getCoordinateDimension());
+		ensure(results->toString(), results->equalsExact(expected, 1e-7));
+		ensure_equals(results->getCoordinateDimension(), expected->getCoordinateDimension());
 
 		delete sites;
 		delete expected;
@@ -160,5 +161,16 @@
 		runDelaunay(wkt, false, expectedEdges);
 		runDelaunay(wkt, true, expectedTri);
 	}
+
+	// 8 - Tolerance robustness - http://trac.osgeo.org/geos/ticket/604
+	template<>
+	template<>
+	void object::test<8>()
+	{
+		const char * wkt = "MULTIPOINT(-118.3964065 56.0557,-118.396406 56.0475,-118.396407 56.04,-118.3968 56)";
+		const char* expectedEdges = "MULTILINESTRING ((-118.3964065 56.0557, -118.396406 56.0475), (-118.396407 56.04, -118.396406 56.0475), (-118.3968 56, -118.396407 56.04))";
+
+		runDelaunay(wkt, false, expectedEdges, 0.001);
+	}
 } // namespace tut
 



More information about the geos-commits mailing list