[geos-commits] r4052 - in trunk: . include/geos/geom src/algorithm src/geom src/geomgraph src/io src/operation/linemerge src/operation/polygonize tests/unit/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Apr 20 09:59:49 PDT 2015


Author: strk
Date: 2015-04-20 09:59:49 -0700 (Mon, 20 Apr 2015)
New Revision: 4052

Modified:
   trunk/NEWS
   trunk/include/geos/geom/CoordinateArraySequenceFactory.h
   trunk/include/geos/geom/CoordinateArraySequenceFactory.inl
   trunk/include/geos/geom/CoordinateSequenceFactory.h
   trunk/src/algorithm/MinimumDiameter.cpp
   trunk/src/geom/CoordinateSequence.cpp
   trunk/src/geom/LineString.cpp
   trunk/src/geom/Point.cpp
   trunk/src/geom/Polygon.cpp
   trunk/src/geomgraph/EdgeRing.cpp
   trunk/src/io/WKTReader.cpp
   trunk/src/operation/linemerge/EdgeString.cpp
   trunk/src/operation/polygonize/EdgeRing.cpp
   trunk/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp
Log:
Cleanup CoordinateSequenceFactory interface

Adds method for creating empty sequence.
Syncronizes CoordinateArraySequenceFactory methods.

Patch by Sandro Mani,
see https://github.com/libgeos/libgeos/pull/46

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/NEWS	2015-04-20 16:59:49 UTC (rev 4052)
@@ -12,6 +12,8 @@
   - Speed-up intersection and difference between geometries
     with small bounding box overlap.
   - CAPI: add MULTILINESTRING support for GEOSisClosed (Benjamin Morel)
+- C++ API changes:
+  - Added no-parameter CoordinateSequenceFactory::create method (Sandro Mani)
 
 Changes in 3.4.2
 2013-08-25

Modified: trunk/include/geos/geom/CoordinateArraySequenceFactory.h
===================================================================
--- trunk/include/geos/geom/CoordinateArraySequenceFactory.h	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/include/geos/geom/CoordinateArraySequenceFactory.h	2015-04-20 16:59:49 UTC (rev 4052)
@@ -43,15 +43,10 @@
 class GEOS_DLL CoordinateArraySequenceFactory: public CoordinateSequenceFactory {
 
 public:
+	CoordinateSequence *create() const;
 
-	/** \brief
-	 * Returns a CoordinateArraySequence based on the given vector
-	 * (the vector is not copied - callers give up ownership).
-	 */
-	CoordinateSequence *create(std::vector<Coordinate> *coords) const;
+	CoordinateSequence *create(std::vector<Coordinate> *coords, std::size_t dims=0) const;
 
-	CoordinateSequence *create(std::vector<Coordinate> *coords, std::size_t dims) const;
-
    	/** @see CoordinateSequenceFactory::create(std::size_t, int) */
 	CoordinateSequence *create(std::size_t size, std::size_t dimension=0) const;
 

Modified: trunk/include/geos/geom/CoordinateArraySequenceFactory.inl
===================================================================
--- trunk/include/geos/geom/CoordinateArraySequenceFactory.inl	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/include/geos/geom/CoordinateArraySequenceFactory.inl	2015-04-20 16:59:49 UTC (rev 4052)
@@ -22,10 +22,11 @@
 namespace geos {
 namespace geom { // geos::geom
 
-INLINE CoordinateSequence*
-CoordinateArraySequenceFactory::create(std::vector<Coordinate> *coords) const
+INLINE CoordinateSequence *
+CoordinateArraySequenceFactory::create() const
 {
-	return new CoordinateArraySequence(coords,3);
+    return new CoordinateArraySequence(
+                reinterpret_cast<std::vector<Coordinate>*>(0), 0);
 }
 
 INLINE CoordinateSequence *

Modified: trunk/include/geos/geom/CoordinateSequenceFactory.h
===================================================================
--- trunk/include/geos/geom/CoordinateSequenceFactory.h	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/include/geos/geom/CoordinateSequenceFactory.h	2015-04-20 16:59:49 UTC (rev 4052)
@@ -48,6 +48,12 @@
 public:
 
 	/** \brief
+	 * Returns an empty CoordinateSequence, the dimensions will be autodetected
+	 * when it is populated.
+	 */
+	virtual CoordinateSequence *create() const=0;
+
+	/** \brief
 	 * Returns a CoordinateSequence based on the given array.
 	 *
 	 * Whether the array is copied or simply referenced
@@ -77,7 +83,7 @@
 	 * 	(0=unknown, 2, or 3 - ignored if not user specifiable)
 	 */
 	virtual CoordinateSequence *create(std::size_t size,
-                                           std::size_t dimension) const=0;
+                                           std::size_t dimension=0) const=0;
 
 	/** \brief
 	 * Creates a CoordinateSequence which is a copy of the given one.

Modified: trunk/src/algorithm/MinimumDiameter.cpp
===================================================================
--- trunk/src/algorithm/MinimumDiameter.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/algorithm/MinimumDiameter.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -127,7 +127,7 @@
 MinimumDiameter::getSupportingSegment() {
 	computeMinimumDiameter();
 	const GeometryFactory *fact = inputGeom->getFactory();
-	CoordinateSequence* cl=fact->getCoordinateSequenceFactory()->create(NULL);
+	CoordinateSequence* cl=fact->getCoordinateSequenceFactory()->create();
 	cl->add(minBaseSeg->p0);
 	cl->add(minBaseSeg->p1);
 	return fact->createLineString(cl);
@@ -149,7 +149,7 @@
 	Coordinate basePt;
 	minBaseSeg->project(*minWidthPt, basePt);
 
-	CoordinateSequence* cl=inputGeom->getFactory()->getCoordinateSequenceFactory()->create(NULL);
+	CoordinateSequence* cl=inputGeom->getFactory()->getCoordinateSequenceFactory()->create();
 	cl->add(basePt);
 	cl->add(*minWidthPt);
 	return inputGeom->getFactory()->createLineString(cl);

Modified: trunk/src/geom/CoordinateSequence.cpp
===================================================================
--- trunk/src/geom/CoordinateSequence.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/geom/CoordinateSequence.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -62,7 +62,7 @@
 	else
 	{
 		// FIXME: return NULL rather then empty coordinate array
-		return CoordinateArraySequenceFactory::instance()->create(NULL);
+		return CoordinateArraySequenceFactory::instance()->create();
 	}
 }      
 

Modified: trunk/src/geom/LineString.cpp
===================================================================
--- trunk/src/geom/LineString.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/geom/LineString.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -71,7 +71,7 @@
 {
 	if (points.get()==NULL)
 	{
-		points.reset(getFactory()->getCoordinateSequenceFactory()->create(NULL));
+		points.reset(getFactory()->getCoordinateSequenceFactory()->create());
 		return;
 	}
 

Modified: trunk/src/geom/Point.cpp
===================================================================
--- trunk/src/geom/Point.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/geom/Point.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -49,7 +49,7 @@
 	coordinates(newCoords)
 {
 	if (coordinates.get()==NULL) {
-		coordinates.reset(factory->getCoordinateSequenceFactory()->create(NULL));
+		coordinates.reset(factory->getCoordinateSequenceFactory()->create());
 		return;
 	}        
 	if (coordinates->getSize() != 1)

Modified: trunk/src/geom/Polygon.cpp
===================================================================
--- trunk/src/geom/Polygon.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/geom/Polygon.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -104,7 +104,7 @@
 Polygon::getCoordinates() const
 {
 	if (isEmpty()) {
-		return getFactory()->getCoordinateSequenceFactory()->create(NULL);
+		return getFactory()->getCoordinateSequenceFactory()->create();
 	}
 
 	vector<Coordinate> *cl = new vector<Coordinate>;

Modified: trunk/src/geomgraph/EdgeRing.cpp
===================================================================
--- trunk/src/geomgraph/EdgeRing.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/geomgraph/EdgeRing.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -62,7 +62,7 @@
 	holes(),
         maxNodeDegree(-1),
 	edges(),
-	pts(newGeometryFactory->getCoordinateSequenceFactory()->create(NULL)),
+	pts(newGeometryFactory->getCoordinateSequenceFactory()->create()),
         label(Location::UNDEF), // new Label(Location::UNDEF)),
         ring(NULL),
         isHoleVar(false),

Modified: trunk/src/io/WKTReader.cpp
===================================================================
--- trunk/src/io/WKTReader.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/io/WKTReader.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -74,7 +74,7 @@
 	size_t dim;
 	string nextToken=getNextEmptyOrOpener(tokenizer);
 	if (nextToken=="EMPTY") {
-		return geometryFactory->getCoordinateSequenceFactory()->create(NULL);
+		return geometryFactory->getCoordinateSequenceFactory()->create();
 		//new CoordinateArraySequence(); 
 	}
 
@@ -290,7 +290,7 @@
 		// Try to parse deprecated form "MULTIPOINT(0 0, 1 1)"
 		const CoordinateSequenceFactory* csf = \
 			geometryFactory->getCoordinateSequenceFactory();
-		CoordinateSequence *coords = csf->create(NULL);
+		CoordinateSequence *coords = csf->create();
 		try {
 			do {
 				Coordinate coord;

Modified: trunk/src/operation/linemerge/EdgeString.cpp
===================================================================
--- trunk/src/operation/linemerge/EdgeString.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/operation/linemerge/EdgeString.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -65,7 +65,7 @@
 	if (coordinates==NULL) {
 		int forwardDirectedEdges = 0;
 		int reverseDirectedEdges = 0;
-		coordinates=factory->getCoordinateSequenceFactory()->create(NULL);
+		coordinates=factory->getCoordinateSequenceFactory()->create();
 		for (std::size_t i=0, e=directedEdges.size(); i<e; ++i) {
 			LineMergeDirectedEdge* directedEdge = directedEdges[i];
 			if (directedEdge->getEdgeDirection()) {

Modified: trunk/src/operation/polygonize/EdgeRing.cpp
===================================================================
--- trunk/src/operation/polygonize/EdgeRing.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/src/operation/polygonize/EdgeRing.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -198,7 +198,7 @@
 {
     if (ringPts==NULL)
     {
-        ringPts=factory->getCoordinateSequenceFactory()->create(NULL);
+        ringPts=factory->getCoordinateSequenceFactory()->create();
         for (DeList::size_type i=0, e=deList.size(); i<e; ++i) {
             const DirectedEdge *de=deList[i];
             assert(dynamic_cast<PolygonizeEdge*>(de->getEdge()));

Modified: trunk/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp
===================================================================
--- trunk/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp	2015-04-16 06:18:13 UTC (rev 4051)
+++ trunk/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp	2015-04-20 16:59:49 UTC (rev 4052)
@@ -162,5 +162,34 @@
 		}
 	}
 
+	// Test of create() without arguments
+	template<>
+	template<>
+	void object::test<5>()
+	{
+		using geos::geom::Coordinate;
 
+		try
+		{
+			CoordinateFactoryCPtr factory = geos::geom::CoordinateArraySequenceFactory::instance();
+
+			ensure( 0 != factory );
+
+			const size_t size0 = 0;
+			CoordinateSequencePtr sequence = factory->create();
+
+			ensure( 0 != sequence);
+			ensure( sequence->isEmpty() );
+			ensure_equals( sequence->size(), size0 );
+
+			// FREE MEMORY
+			delete sequence;
+		}
+		catch (std::exception& e)
+		{
+			fail( e.what() );
+		}
+	}
+
+
 } // namespace tut



More information about the geos-commits mailing list