[geos-commits] r3451 - in trunk: . include/geos/noding src/geom/prep src/noding src/operation/buffer tests/unit/noding

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Jul 26 12:23:31 EDT 2011


Author: strk
Date: 2011-07-26 09:23:30 -0700 (Tue, 26 Jul 2011)
New Revision: 3451

Modified:
   trunk/NEWS
   trunk/include/geos/noding/NodedSegmentString.h
   trunk/include/geos/noding/SegmentNodeList.h
   trunk/include/geos/noding/SegmentStringUtil.h
   trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp
   trunk/src/geom/prep/PreparedLineString.cpp
   trunk/src/geom/prep/PreparedLineStringIntersects.cpp
   trunk/src/geom/prep/PreparedPolygon.cpp
   trunk/src/geom/prep/PreparedPolygonContainsProperly.cpp
   trunk/src/geom/prep/PreparedPolygonIntersects.cpp
   trunk/src/noding/SegmentNodeList.cpp
   trunk/src/operation/buffer/BufferBuilder.cpp
   trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp
   trunk/tests/unit/noding/NodedSegmentStringTest.cpp
   trunk/tests/unit/noding/SegmentNodeTest.cpp
Log:
Have NodedSegmentString take ownership of CoordinateSequence

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/NEWS	2011-07-26 16:23:30 UTC (rev 3451)
@@ -8,6 +8,7 @@
   - Signature of most functions taking an IntersectionMatrix changed
     to take it by reference rather than pointer.
   - GraphComponent::label is now a Label value (from a pointer)
+  - NodedSegmentString takes ownership of CoordinateSequence now
 
 Changes in 3.3.0
 2011-05-30

Modified: trunk/include/geos/noding/NodedSegmentString.h
===================================================================
--- trunk/include/geos/noding/NodedSegmentString.h	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/include/geos/noding/NodedSegmentString.h	2011-07-26 16:23:30 UTC (rev 3451)
@@ -83,7 +83,7 @@
 	 * Creates a new segment string from a list of vertices.
 	 *
 	 * @param newPts CoordinateSequence representing the string,
-	 *                externally owned
+	 *               ownership transferred.
 	 *
 	 * @param data the user-defined data of this segment string
 	 *             (may be null)
@@ -95,7 +95,9 @@
     {}
 
 	~NodedSegmentString()
-	{}
+	{
+		delete pts;
+	}
 
 	/**
 	 * Adds an intersection node for a given point and segment to this segment string.

Modified: trunk/include/geos/noding/SegmentNodeList.h
===================================================================
--- trunk/include/geos/noding/SegmentNodeList.h	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/include/geos/noding/SegmentNodeList.h	2011-07-26 16:23:30 UTC (rev 3451)
@@ -64,9 +64,6 @@
 	// This vector is here to keep track of created splitEdges
 	std::vector<SegmentString*> splitEdges;
 
-	// This vector is here to keep track of created Coordinates
-	std::vector<geom::CoordinateSequence*> splitCoordLists;
-
 	/**
 	 * Checks the correctness of the set of split edges corresponding
 	 * to this edge

Modified: trunk/include/geos/noding/SegmentStringUtil.h
===================================================================
--- trunk/include/geos/noding/SegmentStringUtil.h	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/include/geos/noding/SegmentStringUtil.h	2011-07-26 16:23:30 UTC (rev 3451)
@@ -47,14 +47,7 @@
 	 * @param geom the geometry to extract from
 	 * @param segStr a List of SegmentStrings (output parameter).
 	 *               Ownership of elements pushed to the vector
-	 *		 is transferred to caller. Note that the
-	 *		 CoordinateSequence associated with the
-	 *		 returned SegmentString elements are allocated
-	 *		 by this function, so must also be destroyed
-	 *		 by caller.
-	 *		 TODO: check if this can be optimized by leaving
-	 *		       ownership of actual CoordinateSequence
-	 *		       to the passed Geometry.
+	 *               is transferred to caller. 
 	 */
 	static void extractSegmentStrings(const geom::Geometry * g,
 					  SegmentString::ConstVect& segStr)

Modified: trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp
===================================================================
--- trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -96,7 +96,6 @@
 
 	for (std::size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
 	{
-		delete lineSegStr[i]->getCoordinates();
 		delete lineSegStr[i];
 	}
 }

Modified: trunk/src/geom/prep/PreparedLineString.cpp
===================================================================
--- trunk/src/geom/prep/PreparedLineString.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/geom/prep/PreparedLineString.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -37,7 +37,6 @@
 	for ( noding::SegmentString::ConstVect::size_type i = 0,
 	     ni = segStrings.size(); i < ni; ++i )
 	{
-		delete segStrings[ i ]->getCoordinates();
 		delete segStrings[ i ];
 	}
 }

Modified: trunk/src/geom/prep/PreparedLineStringIntersects.cpp
===================================================================
--- trunk/src/geom/prep/PreparedLineStringIntersects.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/geom/prep/PreparedLineStringIntersects.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -61,7 +61,6 @@
 		bool segsIntersect = fssif->intersects( &lineSegStr);// prepLine.getIntersectionFinder()->intersects(lineSegStr);
 
 		for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ ) {
-			delete lineSegStr[ i ]->getCoordinates();
 			delete lineSegStr[ i ];
 		}
 

Modified: trunk/src/geom/prep/PreparedPolygon.cpp
===================================================================
--- trunk/src/geom/prep/PreparedPolygon.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/geom/prep/PreparedPolygon.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -52,7 +52,6 @@
 
 	for ( std::size_t i = 0, ni = segStrings.size(); i < ni; i++ )
 	{
-		delete segStrings[ i ]->getCoordinates();
 		delete segStrings[ i ];
 	}
 }

Modified: trunk/src/geom/prep/PreparedPolygonContainsProperly.cpp
===================================================================
--- trunk/src/geom/prep/PreparedPolygonContainsProperly.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/geom/prep/PreparedPolygonContainsProperly.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -60,7 +60,6 @@
 	bool segsIntersect = prepPoly->getIntersectionFinder()->intersects( &lineSegStr);
 
 	for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ ) {
-		delete lineSegStr[ i ]->getCoordinates();
 		delete lineSegStr[ i ];
 	}
 

Modified: trunk/src/geom/prep/PreparedPolygonIntersects.cpp
===================================================================
--- trunk/src/geom/prep/PreparedPolygonIntersects.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/geom/prep/PreparedPolygonIntersects.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -60,7 +60,6 @@
 
 	for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ ) 
 	{
-	      delete lineSegStr[ i ]->getCoordinates();
 		delete lineSegStr[ i ];
 	}
 	

Modified: trunk/src/noding/SegmentNodeList.cpp
===================================================================
--- trunk/src/noding/SegmentNodeList.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/noding/SegmentNodeList.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -61,11 +61,6 @@
 	{
 		delete splitEdges[i];
 	}
-
-	for(size_t i=0, n=splitCoordLists.size(); i<n; ++i)
-	{
-		delete splitCoordLists[i];
-	}
 }
 
 SegmentNode*
@@ -285,16 +280,14 @@
 	}
 	if (useIntPt1) 	pts->setAt(ei1->coord, ipt++);
 
+	// SegmentString takes ownership of CoordinateList 'pts'
 	SegmentString *ret = new NodedSegmentString(pts, edge.getData());
+
 #if GEOS_DEBUG
 	std::cerr<<" SegmentString created"<<std::endl;
 #endif
 	splitEdges.push_back(ret);
 
-	// Keep track of created CoordinateSequence to release
-	// it at this SegmentNodeList destruction time
-	splitCoordLists.push_back(pts);
-
 	return ret;
 }
 

Modified: trunk/src/operation/buffer/BufferBuilder.cpp
===================================================================
--- trunk/src/operation/buffer/BufferBuilder.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/operation/buffer/BufferBuilder.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -87,7 +87,7 @@
   std::vector<Geometry*> lines;
   while(it != et) {
     const SegmentString* ss = *it;
-    LineString* line = fact->createLineString(ss->getCoordinates());
+    LineString* line = fact->createLineString(ss->getCoordinates()->clone());
     lines.push_back(line);
     ++it;
   }
@@ -184,10 +184,13 @@
    {
       CoordinateSequence* seq = lineList[i];
 
+      // SegmentString takes ownership of CoordinateSequence
       SegmentString* ss = new NodedSegmentString(seq, NULL);
       curveList.push_back( ss );
    }
+   lineList.clear();
 
+
    // Node these SegmentStrings.
    Noder* noder = getNoder( precisionModel );
    noder->computeNodes( &curveList );
@@ -211,10 +214,6 @@
    for (size_t i=0, n=curveList.size(); i<n; ++i) delete curveList[i];
    curveList.clear();
 
-   for (size_t i=0, n=lineList.size(); i<n; ++i) delete lineList[i];
-   lineList.clear();
-
-
    Geometry* singleSided = geomFact->createMultiLineString(
       singleSidedNodedEdges );
 

Modified: trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp
===================================================================
--- trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/src/operation/buffer/OffsetCurveSetBuilder.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -72,7 +72,6 @@
 	for (size_t i=0, n=curveList.size(); i<n; ++i)
 	{
 		SegmentString* ss = curveList[i];
-		delete ss->getCoordinates();
 		delete ss;
 	}
 	for (size_t i=0, n=newLabels.size(); i<n; ++i)
@@ -119,6 +118,7 @@
 	// add the edge for a coordinate list which is a raw offset curve
 	Label *newlabel = new Label(0, Location::BOUNDARY, leftLoc, rightLoc);
 
+	// coord ownership transferred to SegmentString
 	SegmentString *e=new NodedSegmentString(coord, newlabel);
 
 	// SegmentString doesnt own the sequence, so we need to delete in

Modified: trunk/tests/unit/noding/NodedSegmentStringTest.cpp
===================================================================
--- trunk/tests/unit/noding/NodedSegmentStringTest.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/tests/unit/noding/NodedSegmentStringTest.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -76,15 +76,13 @@
 
         ensure_equals(cs->size(), 2u);
 
-        SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+        SegmentStringAutoPtr ss(makeSegmentString(cs.release()));
         ensure(0 != ss.get());
 
         ensure_equals(ss->size(), 2u);
 
         ensure_equals(ss->getData(), (void*)0);
 
-        ensure_equals(ss->getCoordinates(), cs.get());
-
         ensure_equals(ss->getCoordinate(0), c0);
 
         ensure_equals(ss->getCoordinate(1), c1);
@@ -113,15 +111,13 @@
 
     ensure_equals(cs->size(), 2u);
 
-    SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+    SegmentStringAutoPtr ss(makeSegmentString(cs.release()));
     ensure(0 != ss.get());
 
     ensure_equals(ss->size(), 2u);
 
     ensure_equals(ss->getData(), (void*)0);
 
-    ensure_equals(ss->getCoordinates(), cs.get());
-
     ensure_equals(ss->getCoordinate(0), c0);
 
     ensure_equals(ss->getCoordinate(1), c1);
@@ -153,15 +149,13 @@
 
     ensure_equals(cs->size(), 4u);
 
-    SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+    SegmentStringAutoPtr ss(makeSegmentString(cs.release()));
     ensure(0 != ss.get());
 
     ensure_equals(ss->size(), 4u);
 
     ensure_equals(ss->getData(), (void*)0);
 
-    ensure_equals(ss->getCoordinates(), cs.get());
-
     ensure_equals(ss->getCoordinate(0), c0);
 
     ensure_equals(ss->getCoordinate(1), c1);
@@ -215,7 +209,7 @@
         cs->add(p0);
         cs->add(p1);
 
-        SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+        SegmentStringAutoPtr ss(makeSegmentString(cs.release()));
 
         ensure_equals(ss->getNodeList().size(), 0u);
 

Modified: trunk/tests/unit/noding/SegmentNodeTest.cpp
===================================================================
--- trunk/tests/unit/noding/SegmentNodeTest.cpp	2011-07-26 15:09:35 UTC (rev 3450)
+++ trunk/tests/unit/noding/SegmentNodeTest.cpp	2011-07-26 16:23:30 UTC (rev 3451)
@@ -68,7 +68,7 @@
 
         // Create SegmentString instance
         
-        NodedSegmentString segment(cs.get(), 0);
+        NodedSegmentString segment(cs.release(), 0);
 
         ensure_equals( segment.size(), coords_size );
 
@@ -116,7 +116,7 @@
 
         // Create SegmentString instance
         
-        NodedSegmentString segment(cs.get(), 0);
+        NodedSegmentString segment(cs.release(), 0);
 
         ensure_equals( segment.size(), coords_size );
 
@@ -158,7 +158,7 @@
 
         // Create SegmentString instance
         
-        NodedSegmentString segment(cs.get(), 0);
+        NodedSegmentString segment(cs.release(), 0);
 
         ensure_equals( segment.size(), coords_size );
 
@@ -200,7 +200,7 @@
 
         // Create SegmentString instance
         
-        NodedSegmentString segment(cs.get(), 0);
+        NodedSegmentString segment(cs.release(), 0);
 
         ensure_equals( segment.size(), coords_size );
 



More information about the geos-commits mailing list