[geos-commits] r2678 - in trunk/source: geom headers/geos/geom
svn_geos at osgeo.org
svn_geos at osgeo.org
Sat Oct 17 08:28:41 EDT 2009
Author: strk
Date: 2009-10-17 08:28:41 -0400 (Sat, 17 Oct 2009)
New Revision: 2678
Modified:
trunk/source/geom/CoordinateArraySequence.cpp
trunk/source/geom/Polygon.cpp
trunk/source/headers/geos/geom/CoordinateArraySequence.h
trunk/source/headers/geos/geom/CoordinateSequence.h
Log:
Expose a usable toVector method for CoordinateSequence (ie: no memory management issues). Use it from Polygon::getCoordinates.
Modified: trunk/source/geom/CoordinateArraySequence.cpp
===================================================================
--- trunk/source/geom/CoordinateArraySequence.cpp 2009-10-17 12:02:56 UTC (rev 2677)
+++ trunk/source/geom/CoordinateArraySequence.cpp 2009-10-17 12:28:41 UTC (rev 2678)
@@ -72,6 +72,14 @@
return vect; //new vector<Coordinate>(vect->begin(),vect->end());
}
+void
+CoordinateArraySequence::toVector(vector<Coordinate>& out) const
+{
+ assert(0 != vect);
+ // TODO: can this be optimized ?
+ out.insert(out.end(), vect->begin(), vect->end());
+}
+
bool
CoordinateArraySequence::isEmpty() const
{
Modified: trunk/source/geom/Polygon.cpp
===================================================================
--- trunk/source/geom/Polygon.cpp 2009-10-17 12:02:56 UTC (rev 2677)
+++ trunk/source/geom/Polygon.cpp 2009-10-17 12:28:41 UTC (rev 2678)
@@ -107,38 +107,21 @@
return getFactory()->getCoordinateSequenceFactory()->create(NULL);
}
- size_t i, j, npts;
- size_t nholes=holes->size();
-
vector<Coordinate> *cl = new vector<Coordinate>;
+ // reserve space in the vector for all the polygon points
+ cl->reserve(getNumPoints());
+
// Add shell points
const CoordinateSequence* shellCoords=shell->getCoordinatesRO();
- npts=shellCoords->getSize();
+ shellCoords->toVector(*cl);
- /*
- * reserve space in the vector for all the polygon points
- */
- cl->reserve(getNumPoints());
-
- for (j=0; j<npts; ++j)
+ // Add holes points
+ size_t nholes=holes->size();
+ for (size_t i=0; i<nholes; ++i)
{
- // This can be optimized by having CoordinateSequence
- // expose a method to push all coords to a vector
- cl->push_back(shellCoords->getAt(j));
- }
-
- for (i=0; i<nholes; ++i)
- {
- // Add hole points
const CoordinateSequence* childCoords=((LinearRing *)(*holes)[i])->getCoordinatesRO();
- npts=childCoords->getSize();
- for (j=0; j<npts; ++j)
- {
- // This can be optimized by having CoordinateSequence
- // expose a method to push all coords to a vector
- cl->push_back(childCoords->getAt(j));
- }
+ childCoords->toVector(*cl);
}
return getFactory()->getCoordinateSequenceFactory()->create(cl);
Modified: trunk/source/headers/geos/geom/CoordinateArraySequence.h
===================================================================
--- trunk/source/headers/geos/geom/CoordinateArraySequence.h 2009-10-17 12:02:56 UTC (rev 2677)
+++ trunk/source/headers/geos/geom/CoordinateArraySequence.h 2009-10-17 12:28:41 UTC (rev 2678)
@@ -51,8 +51,13 @@
//int size() const;
size_t getSize() const;
+
+ // @deprecated
const std::vector<Coordinate>* toVector() const;
+ // See dox in CoordinateSequence.h
+ void toVector(std::vector<Coordinate>&) const;
+
/// Construct an empty sequence
CoordinateArraySequence();
Modified: trunk/source/headers/geos/geom/CoordinateSequence.h
===================================================================
--- trunk/source/headers/geos/geom/CoordinateSequence.h 2009-10-17 12:02:56 UTC (rev 2677)
+++ trunk/source/headers/geos/geom/CoordinateSequence.h 2009-10-17 12:28:41 UTC (rev 2678)
@@ -142,9 +142,17 @@
* We opted for the second, so the returned object is a const, to
* also ensure that returning an internal pointer doesn't make
* the object mutable.
+ *
+ * @deprecated use toVector(std::vector<Coordinate>&) instead
*/
virtual const std::vector<Coordinate>* toVector() const=0;
+ /// Pushes all Coordinates of this sequence onto the provided vector.
+ //
+ /// This method is a port of the toCoordinateArray() method of JTS.
+ ///
+ virtual void toVector(std::vector<Coordinate>& coords) const=0;
+
/**
* \brief Add an array of coordinates
* @param vc The coordinates
More information about the geos-commits
mailing list