[geos-commits] [SCM] GEOS branch master updated. f9257802afd040a92fed345b5dba3215c17e463f

git at osgeo.org git at osgeo.org
Tue Sep 17 18:14:30 PDT 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  f9257802afd040a92fed345b5dba3215c17e463f (commit)
       via  431769bb24ba32dd0a08c5341d090067244be972 (commit)
       via  a786e5bba5189a9b800657efc0676af1abe74e10 (commit)
       via  087928fc0ed105aa363374429146300e4892ad07 (commit)
       via  db9278d0f8fd1cfb659ec2e543b78b353adc70fd (commit)
       via  099c88ab7ac809f62747635645ca105ed181cdd5 (commit)
       via  4ffa3449f751e7be8508bd3259da8a8e18ec8003 (commit)
       via  9dc465d2d76e2c22c37a08e69d10d9d8f30d7f84 (commit)
       via  66175c2357e667d19b18d36ddd30622300bc6fc7 (commit)
      from  2c9bfe8a298e41c29046d286b35e8a69345a1807 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f9257802afd040a92fed345b5dba3215c17e463f
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Sep 17 21:13:39 2019 -0400

    Simplify GeometryFactory::buildGeometry

diff --git a/include/geos/geom/GeometryFactory.h b/include/geos/geom/GeometryFactory.h
index ad2a66e..b98ab7a 100644
--- a/include/geos/geom/GeometryFactory.h
+++ b/include/geos/geom/GeometryFactory.h
@@ -28,10 +28,12 @@
 #include <geos/geom/PrecisionModel.h>
 #include <geos/export.h>
 #include <geos/inline.h>
+#include <geos/util.h>
 
 #include <vector>
 #include <memory>
 #include <cassert>
+#include <geos/util/IllegalArgumentException.h>
 
 namespace geos {
 namespace geom {
@@ -359,7 +361,7 @@ public:
 
         // for the single geometry, return a clone
         if(count == 1) {
-            return std::unique_ptr<Geometry>((*from)->clone());
+            return (*from)->clone();
         }
 
         // Now we know it is a collection
@@ -368,31 +370,24 @@ public:
         // Until we tweak all the createMulti* interfaces
         // to support taking iterators we'll have to build
         // a custom vector here.
-        std::vector<const Geometry*> fromGeoms;
+        std::vector<std::unique_ptr<Geometry>> fromGeoms;
         for(T i = from; i != toofar; ++i) {
-            const Geometry* g = *i;
-            fromGeoms.push_back(g);
+            fromGeoms.push_back((*i)->clone());
         }
 
-
         // for an heterogeneous ...
         if(isHeterogeneous) {
-            return std::unique_ptr<Geometry>(createGeometryCollection(fromGeoms));
+            return createGeometryCollection(std::move(fromGeoms));
         }
 
         // At this point we know the collection is not hetereogenous.
-        if(dynamic_cast<const Polygon*>(*from)) {
-            return std::unique_ptr<Geometry>(createMultiPolygon(fromGeoms));
-        }
-        else if(dynamic_cast<const LineString*>(*from)) {
-            return std::unique_ptr<Geometry>(createMultiLineString(fromGeoms));
+        switch((*from)->getDimension()) {
+            case 2: return createMultiPolygon(std::move(fromGeoms));
+            case 1: return createMultiLineString(std::move(fromGeoms));
+            case 0: return createMultiPoint(std::move(fromGeoms));
         }
-        else if(dynamic_cast<const Point*>(*from)) {
-            return std::unique_ptr<Geometry>(createMultiPoint(fromGeoms));
-        }
-        // FIXME: Why not to throw an exception? --mloskot
-        assert(0); // buildGeomtry encountered an unkwnon geometry type
-        return std::unique_ptr<Geometry>(); // nullptr
+
+        throw geos::util::IllegalArgumentException("Invalid geometry type.");
     }
 
     /** \brief

commit 431769bb24ba32dd0a08c5341d090067244be972
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 21:13:53 2019 -0400

    Store GeometryGraph EdgeRing rings using unique_ptr
    
    Clarifies ownership

diff --git a/include/geos/geomgraph/EdgeRing.h b/include/geos/geomgraph/EdgeRing.h
index 63a0119..ff4cdeb 100644
--- a/include/geos/geomgraph/EdgeRing.h
+++ b/include/geos/geomgraph/EdgeRing.h
@@ -124,18 +124,14 @@ public:
     testInvariant() const
     {
         // pts are never NULL
-        assert(pts);
+        // assert(pts);
 
 #ifndef NDEBUG
         // If this is not an hole, check that
         // each hole is not null and
         // has 'this' as it's shell
         if(! shell) {
-            for(std::vector<EdgeRing*>::const_iterator
-                    it = holes.begin(), itEnd = holes.end();
-                    it != itEnd;
-                    ++it) {
-                EdgeRing* hole = *it;
+            for(const auto& hole : holes) {
                 assert(hole);
                 assert(hole->getShell() == this);
             }
@@ -171,7 +167,7 @@ protected:
     void addPoints(Edge* edge, bool isForward, bool isFirstEdge);
 
     /// a list of EdgeRings which are holes in this EdgeRing
-    std::vector<EdgeRing*> holes;
+    std::vector<std::unique_ptr<EdgeRing>> holes;
 
 private:
 
@@ -180,13 +176,13 @@ private:
     /// the DirectedEdges making up this EdgeRing
     std::vector<DirectedEdge*> edges;
 
-    geom::CoordinateArraySequence* pts;
+    std::unique_ptr<geom::CoordinateArraySequence> pts;
 
     // label stores the locations of each geometry on the
     // face surrounded by this ring
     Label label;
 
-    geom::LinearRing* ring;  // the ring created for this EdgeRing
+    std::unique_ptr<geom::LinearRing> ring;  // the ring created for this EdgeRing
 
     bool isHoleVar;
 
diff --git a/src/geom/LinearRing.cpp b/src/geom/LinearRing.cpp
index de3fd9e..afd5dab 100644
--- a/src/geom/LinearRing.cpp
+++ b/src/geom/LinearRing.cpp
@@ -126,7 +126,7 @@ LinearRing::reverse() const
     auto seq = points->clone();
     CoordinateSequence::reverse(seq.get());
     assert(getFactory());
-    return std::unique_ptr<Geometry>(getFactory()->createLinearRing(seq.release()));
+    return getFactory()->createLinearRing(std::move(seq));
 }
 
 } // namespace geos::geom
diff --git a/src/geom/Polygon.cpp b/src/geom/Polygon.cpp
index 0e95a8f..a807938 100644
--- a/src/geom/Polygon.cpp
+++ b/src/geom/Polygon.cpp
@@ -67,7 +67,7 @@ Polygon::Polygon(LinearRing* newShell, std::vector<LinearRing*>* newHoles,
     Geometry(newFactory)
 {
     if(newShell == nullptr) {
-        shell.reset(getFactory()->createLinearRing(nullptr));
+        shell.reset(getFactory()->createLinearRing());
     }
     else {
         if(newHoles != nullptr && newShell->isEmpty() && hasNonEmptyElements(newHoles)) {
@@ -93,7 +93,7 @@ Polygon::Polygon(std::unique_ptr<LinearRing> && newShell,
         shell(std::move(newShell))
 {
     if(shell == nullptr) {
-        shell.reset(getFactory()->createLinearRing(nullptr));
+        shell.reset(getFactory()->createLinearRing());
     }
 }
 
@@ -105,7 +105,7 @@ Polygon::Polygon(std::unique_ptr<LinearRing> && newShell,
                  holes(std::move(newHoles))
 {
     if(shell == nullptr) {
-        shell.reset(getFactory()->createLinearRing(nullptr));
+        shell.reset(getFactory()->createLinearRing());
     }
 
     // TODO move into validateConstruction() method
diff --git a/src/geomgraph/EdgeRing.cpp b/src/geomgraph/EdgeRing.cpp
index f76207a..0b10d37 100644
--- a/src/geomgraph/EdgeRing.cpp
+++ b/src/geomgraph/EdgeRing.cpp
@@ -78,15 +78,6 @@ EdgeRing::EdgeRing(DirectedEdge* newStart,
 EdgeRing::~EdgeRing()
 {
     testInvariant();
-
-    if(ring != nullptr) {
-        delete ring;
-    }
-
-    for(size_t i = 0, n = holes.size(); i < n; ++i) {
-        delete holes[i];
-    }
-
 #ifdef GEOS_DEBUG
     cerr << "EdgeRing[" << this << "] dtor" << endl;
 #endif
@@ -117,8 +108,7 @@ LinearRing*
 EdgeRing::getLinearRing()
 {
     testInvariant();
-//	return new LinearRing(*ring);
-    return ring;
+    return ring.get();
 }
 
 Label&
@@ -155,7 +145,7 @@ EdgeRing::setShell(EdgeRing* newShell)
 void
 EdgeRing::addHole(EdgeRing* edgeRing)
 {
-    holes.push_back(edgeRing);
+    holes.emplace_back(edgeRing);
     testInvariant();
 }
 
@@ -191,8 +181,8 @@ EdgeRing::computeRing()
     if(ring != nullptr) {
         return;    // don't compute more than once
     }
-    ring = geometryFactory->createLinearRing(pts);
-    isHoleVar = Orientation::isCCW(pts);
+    isHoleVar = Orientation::isCCW(pts.get());
+    ring = geometryFactory->createLinearRing(std::move(pts));
 
     testInvariant();
 }
@@ -383,8 +373,7 @@ EdgeRing::containsPoint(const Coordinate& p)
         return false;
     }
 
-    for(vector<EdgeRing*>::iterator i = holes.begin(); i < holes.end(); ++i) {
-        EdgeRing* hole = *i;
+    for(const auto& hole : holes) {
         assert(hole);
         if(hole->containsPoint(p)) {
             return false;
@@ -398,7 +387,7 @@ operator<< (std::ostream& os, const EdgeRing& er)
 {
     os << "EdgeRing[" << &er << "]: "
        << std::endl
-       << "Points: " << er.pts
+       << "Points: " << er.pts.get()
        << std::endl;
     return os;
 }

commit a786e5bba5189a9b800657efc0676af1abe74e10
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 20:59:02 2019 -0400

    Avoid heap-allocating Coordinate vectors in SineStarFactory

diff --git a/src/geom/util/SineStarFactory.cpp b/src/geom/util/SineStarFactory.cpp
index 80a335a..5abcfc7 100644
--- a/src/geom/util/SineStarFactory.cpp
+++ b/src/geom/util/SineStarFactory.cpp
@@ -30,18 +30,16 @@
 #include <cmath>
 #include <memory>
 
-using namespace std;
-//using namespace geos::geom;
 
 namespace geos {
 namespace geom { // geos::geom
 namespace util { // geos::geom::util
 
 /* public */
-unique_ptr<Polygon>
+std::unique_ptr<Polygon>
 SineStarFactory::createSineStar() const
 {
-    unique_ptr<Envelope> env(dim.getEnvelope());
+    std::unique_ptr<Envelope> env(dim.getEnvelope());
     double radius = env->getWidth() / 2.0;
 
     double armRatio = armLengthRatio;
@@ -58,7 +56,7 @@ SineStarFactory::createSineStar() const
     double centreX = env->getMinX() + radius;
     double centreY = env->getMinY() + radius;
 
-    unique_ptr< vector<Coordinate> > pts(new vector<Coordinate>(nPts + 1));
+    std::vector<Coordinate> pts(nPts + 1);
     int iPt = 0;
     for(int i = 0; i < nPts; i++) {
         // the fraction of the way thru the current arm - in [0,1]
@@ -78,15 +76,13 @@ SineStarFactory::createSineStar() const
         double ang = i * (2 * M_PI / nPts);
         double x = curveRadius * cos(ang) + centreX;
         double y = curveRadius * sin(ang) + centreY;
-        (*pts)[iPt++] = coord(x, y);
+        pts[iPt++] = coord(x, y);
     }
-    (*pts)[iPt] = Coordinate((*pts)[0]);
+    pts[iPt] = pts[0];
 
-    unique_ptr<CoordinateSequence> cs(
-        geomFact->getCoordinateSequenceFactory()->create(pts.release())
-    );
-    unique_ptr<LinearRing> ring(geomFact->createLinearRing(cs.release()));
-    unique_ptr<Polygon> poly(geomFact->createPolygon(ring.release(), nullptr));
+    auto cs = geomFact->getCoordinateSequenceFactory()->create(std::move(pts));
+    auto ring = geomFact->createLinearRing(std::move(cs));
+    auto poly = geomFact->createPolygon(std::move(ring));
     return poly;
 }
 

commit 087928fc0ed105aa363374429146300e4892ad07
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 20:55:38 2019 -0400

    Update GeometricShapeFactory
    
    - return unique_ptr for generated objects
    - avoid heap-allocating Coordinate vectors

diff --git a/doc/example.cpp b/doc/example.cpp
index 25fdfdf..182f414 100644
--- a/doc/example.cpp
+++ b/doc/example.cpp
@@ -341,7 +341,7 @@ create_circle(double centerX, double centerY, double radius)
     // same as:
     //	shapefactory.setHeight(radius);
     //	shapefactory.setWidth(radius);
-    return shapefactory.createCircle();
+    return shapefactory.createCircle().release();
 }
 
 //
@@ -355,7 +355,7 @@ create_ellipse(double centerX, double centerY, double width, double height)
     shapefactory.setCentre(Coordinate(centerX, centerY));
     shapefactory.setHeight(height);
     shapefactory.setWidth(width);
-    return shapefactory.createCircle();
+    return shapefactory.createCircle().release();
 }
 
 //
@@ -372,7 +372,7 @@ create_rectangle(double llX, double llY, double width, double height)
     shapefactory.setWidth(width);
     shapefactory.setNumPoints(4); // we don't need more then 4 points for a rectangle...
     // can use setSize for a square
-    return shapefactory.createRectangle();
+    return shapefactory.createRectangle().release();
 }
 
 //
@@ -389,7 +389,7 @@ create_arc(double llX, double llY, double width, double height, double startang,
     shapefactory.setWidth(width);
     // shapefactory.setNumPoints(100); // the default (100 pts)
     // can use setSize for a square
-    return shapefactory.createArc(startang, endang);
+    return shapefactory.createArc(startang, endang).release();
 }
 
 unique_ptr<Polygon>
diff --git a/include/geos/util/GeometricShapeFactory.h b/include/geos/util/GeometricShapeFactory.h
index c8631ed..bb83d27 100644
--- a/include/geos/util/GeometricShapeFactory.h
+++ b/include/geos/util/GeometricShapeFactory.h
@@ -23,6 +23,7 @@
 
 #include <geos/export.h>
 #include <cassert>
+#include <memory>
 
 #include <geos/geom/Coordinate.h>
 
@@ -79,7 +80,7 @@ protected:
         void setHeight(double nHeight);
 
         // Return newly-allocated object, ownership transferred
-        geom::Envelope* getEnvelope() const;
+        std::unique_ptr<geom::Envelope> getEnvelope() const;
     };
     const geom::GeometryFactory* geomFact; // externally owned
     const geom::PrecisionModel* precModel; // externally owned
@@ -112,7 +113,7 @@ public:
      * @param angExtent size of angle in radians
      * @return an elliptical arc
      */
-    geom::LineString* createArc(double startAng, double angExtent);
+    std::unique_ptr<geom::LineString> createArc(double startAng, double angExtent);
 
     /**
      * \brief Creates an elliptical arc polygon.
@@ -125,21 +126,21 @@ public:
      * @param angExt size of angle in radians
      * @return an elliptical arc polygon
      */
-    geom::Polygon* createArcPolygon(double startAng, double angExt);
+    std::unique_ptr<geom::Polygon> createArcPolygon(double startAng, double angExt);
 
     /**
      * \brief Creates a circular Polygon.
      *
      * @return a circle
      */
-    geom::Polygon* createCircle();
+    std::unique_ptr<geom::Polygon> createCircle();
 
     /**
      * \brief Creates a rectangular Polygon.
      *
      * @return a rectangular Polygon
      */
-    geom::Polygon* createRectangle();
+    std::unique_ptr<geom::Polygon> createRectangle();
 
     /**
      * \brief
diff --git a/src/util/GeometricShapeFactory.cpp b/src/util/GeometricShapeFactory.cpp
index 8a0d145..9f5b231 100644
--- a/src/util/GeometricShapeFactory.cpp
+++ b/src/util/GeometricShapeFactory.cpp
@@ -25,13 +25,13 @@
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/Envelope.h>
+#include <geos/util.h>
 
 #include <vector>
 #include <cmath>
 #include <memory>
 
 
-using namespace std;
 using namespace geos::geom;
 
 namespace geos {
@@ -81,7 +81,7 @@ GeometricShapeFactory::setHeight(double height)
     dim.setHeight(height);
 }
 
-Polygon*
+std::unique_ptr<Polygon>
 GeometricShapeFactory::createRectangle()
 {
     int i;
@@ -94,37 +94,36 @@ GeometricShapeFactory::createRectangle()
     double XsegLen = env->getWidth() / nSide;
     double YsegLen = env->getHeight() / nSide;
 
-    vector<Coordinate>* vc = new vector<Coordinate>(4 * nSide + 1);
-    //CoordinateSequence* pts=new CoordinateArraySequence(4*nSide+1);
+    std::vector<Coordinate> vc(4 * nSide + 1);
 
     for(i = 0; i < nSide; i++) {
         double x = env->getMinX() + i * XsegLen;
         double y = env->getMinY();
-        (*vc)[ipt++] = coord(x, y);
+        vc[ipt++] = coord(x, y);
     }
     for(i = 0; i < nSide; i++) {
         double x = env->getMaxX();
         double y = env->getMinY() + i * YsegLen;
-        (*vc)[ipt++] = coord(x, y);
+        vc[ipt++] = coord(x, y);
     }
     for(i = 0; i < nSide; i++) {
         double x = env->getMaxX() - i * XsegLen;
         double y = env->getMaxY();
-        (*vc)[ipt++] = coord(x, y);
+        vc[ipt++] = coord(x, y);
     }
     for(i = 0; i < nSide; i++) {
         double x = env->getMinX();
         double y = env->getMaxY() - i * YsegLen;
-        (*vc)[ipt++] = coord(x, y);
+        vc[ipt++] = coord(x, y);
     }
-    (*vc)[ipt++] = (*vc)[0];
-    auto cs = geomFact->getCoordinateSequenceFactory()->create(vc);
-    LinearRing* ring = geomFact->createLinearRing(cs.release());
-    Polygon* poly = geomFact->createPolygon(ring, nullptr);
+    vc[ipt++] = vc[0];
+    auto cs = geomFact->getCoordinateSequenceFactory()->create(std::move(vc));
+    auto ring = geomFact->createLinearRing(std::move(cs));
+    auto poly = geomFact->createPolygon(std::move(ring));
     return poly;
 }
 
-Polygon*
+std::unique_ptr<Polygon>
 GeometricShapeFactory::createCircle()
 {
     std::unique_ptr<Envelope> env(dim.getEnvelope());
@@ -135,22 +134,22 @@ GeometricShapeFactory::createCircle()
     double centreY = env->getMinY() + yRadius;
     env.reset();
 
-    vector<Coordinate>* pts = new vector<Coordinate>(nPts + 1);
+    std::vector<Coordinate> pts(nPts + 1);
     int iPt = 0;
     for(int i = 0; i < nPts; i++) {
         double ang = i * (2 * 3.14159265358979 / nPts);
         double x = xRadius * cos(ang) + centreX;
         double y = yRadius * sin(ang) + centreY;
-        (*pts)[iPt++] = coord(x, y);
+        pts[iPt++] = coord(x, y);
     }
-    (*pts)[iPt++] = (*pts)[0];
-    auto cs = geomFact->getCoordinateSequenceFactory()->create(pts);
-    LinearRing* ring = geomFact->createLinearRing(cs.release());
-    Polygon* poly = geomFact->createPolygon(ring, nullptr);
+    pts[iPt++] = pts[0];
+    auto cs = geomFact->getCoordinateSequenceFactory()->create(std::move(pts));
+    auto ring = geomFact->createLinearRing(std::move(cs));
+    auto poly = geomFact->createPolygon(std::move(ring));
     return poly;
 }
 
-LineString*
+std::unique_ptr<LineString>
 GeometricShapeFactory::createArc(double startAng, double angExtent)
 {
     std::unique_ptr<Envelope> env(dim.getEnvelope());
@@ -167,20 +166,20 @@ GeometricShapeFactory::createArc(double startAng, double angExtent)
     }
     double angInc = angSize / (nPts - 1);
 
-    vector<Coordinate>* pts = new vector<Coordinate>(nPts);
+    std::vector<Coordinate> pts(nPts);
     int iPt = 0;
     for(int i = 0; i < nPts; i++) {
         double ang = startAng + i * angInc;
         double x = xRadius * cos(ang) + centreX;
         double y = yRadius * sin(ang) + centreY;
-        (*pts)[iPt++] = coord(x, y);
+        pts[iPt++] = coord(x, y);
     }
-    auto cs = geomFact->getCoordinateSequenceFactory()->create(pts);
-    LineString* line = geomFact->createLineString(cs.release());
+    auto cs = geomFact->getCoordinateSequenceFactory()->create(std::move(pts));
+    auto line = geomFact->createLineString(std::move(cs));
     return line;
 }
 
-Polygon*
+std::unique_ptr<Polygon>
 GeometricShapeFactory::createArcPolygon(double startAng, double angExtent)
 {
     std::unique_ptr<Envelope> env(dim.getEnvelope());
@@ -197,21 +196,21 @@ GeometricShapeFactory::createArcPolygon(double startAng, double angExtent)
     }
     double angInc = angSize / (nPts - 1);
 
-    vector<Coordinate>* pts = new vector<Coordinate>(nPts + 2);
+    std::vector<Coordinate> pts(nPts + 2);
     int iPt = 0;
-    (*pts)[iPt++] = coord(centreX, centreY);
+    pts[iPt++] = coord(centreX, centreY);
     for(int i = 0; i < nPts; i++) {
         double ang = startAng + i * angInc;
         double x = xRadius * cos(ang) + centreX;
         double y = yRadius * sin(ang) + centreY;
-        (*pts)[iPt++] = coord(x, y);
+        pts[iPt++] = coord(x, y);
     }
-    (*pts)[iPt++] = coord(centreX, centreY);
+    pts[iPt++] = coord(centreX, centreY);
 
-    auto cs = geomFact->getCoordinateSequenceFactory()->create(pts);
-    LinearRing* ring = geomFact->createLinearRing(cs.release());
-    Polygon* geom = geomFact->createPolygon(ring, nullptr);
-    return geom;
+    auto cs = geomFact->getCoordinateSequenceFactory()->create(std::move(pts));
+    auto ring = geomFact->createLinearRing(std::move(cs));
+
+    return geomFact->createPolygon(std::move(ring));
 }
 
 GeometricShapeFactory::Dimensions::Dimensions()
@@ -252,16 +251,16 @@ GeometricShapeFactory::Dimensions::setHeight(double nHeight)
     height = nHeight;
 }
 
-Envelope*
+std::unique_ptr<Envelope>
 GeometricShapeFactory::Dimensions::getEnvelope() const
 {
     if(!base.isNull()) {
-        return new Envelope(base.x, base.x + width, base.y, base.y + height);
+        return detail::make_unique<Envelope>(base.x, base.x + width, base.y, base.y + height);
     }
     if(!centre.isNull()) {
-        return new Envelope(centre.x - width / 2, centre.x + width / 2, centre.y - height / 2, centre.y + height / 2);
+        return detail::make_unique<Envelope>(centre.x - width / 2, centre.x + width / 2, centre.y - height / 2, centre.y + height / 2);
     }
-    return new Envelope(0, width, 0, height);
+    return detail::make_unique<Envelope>(0, width, 0, height);
 }
 
 /*protected*/

commit db9278d0f8fd1cfb659ec2e543b78b353adc70fd
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 20:46:59 2019 -0400

    Store Polygonizer invalid ring lines as unique_ptr

diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 9d3bd7c..7fbf810 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3400,7 +3400,7 @@ extern "C" {
 
             if(invalid) {
 
-                const std::vector<LineString*>& lines = plgnzr.getInvalidRingLines();
+                const std::vector<std::unique_ptr<LineString>>& lines = plgnzr.getInvalidRingLines();
                 std::vector<Geometry*>* linevec = new std::vector<Geometry*>(lines.size());
                 for(std::size_t i = 0, n = lines.size(); i < n; ++i) {
                     (*linevec)[i] = lines[i]->clone().release();
diff --git a/include/geos/operation/polygonize/Polygonizer.h b/include/geos/operation/polygonize/Polygonizer.h
index e816e9e..ca4202b 100644
--- a/include/geos/operation/polygonize/Polygonizer.h
+++ b/include/geos/operation/polygonize/Polygonizer.h
@@ -110,7 +110,7 @@ private:
 
     static void findValidRings(const std::vector<EdgeRing*>& edgeRingList,
                                std::vector<EdgeRing*>& validEdgeRingList,
-                               std::vector<geom::LineString*>& invalidRingList);
+                               std::vector<std::unique_ptr<geom::LineString>>& invalidRingList);
 
     void findShellsAndHoles(const std::vector<EdgeRing*>& edgeRingList);
 
@@ -129,7 +129,7 @@ protected:
     // initialize with empty collections, in case nothing is computed
     std::vector<const geom::LineString*> dangles;
     std::vector<const geom::LineString*> cutEdges;
-    std::vector<geom::LineString*> invalidRingLines;
+    std::vector<std::unique_ptr<geom::LineString>> invalidRingLines;
 
     std::vector<EdgeRing*> holeList;
     std::vector<EdgeRing*> shellList;
@@ -145,7 +145,7 @@ public:
      */
     explicit Polygonizer(bool onlyPolygonal = false);
 
-    ~Polygonizer();
+    ~Polygonizer() = default;
 
     /** \brief
      * Add a collection of geometries to be polygonized.
@@ -226,7 +226,7 @@ public:
      *         the input LineStrings which form invalid rings
      *
      */
-    const std::vector<geom::LineString*>& getInvalidRingLines();
+    const std::vector<std::unique_ptr<geom::LineString>>& getInvalidRingLines();
 
     bool hasInvalidRingLines();
 
diff --git a/src/operation/polygonize/Polygonizer.cpp b/src/operation/polygonize/Polygonizer.cpp
index ee2d0c5..beb1c05 100644
--- a/src/operation/polygonize/Polygonizer.cpp
+++ b/src/operation/polygonize/Polygonizer.cpp
@@ -72,13 +72,6 @@ Polygonizer::Polygonizer(bool onlyPolygonal):
 {
 }
 
-Polygonizer::~Polygonizer()
-{
-    for(auto& r : invalidRingLines) {
-        delete r;
-    }
-}
-
 /*
  * Add a collection of geometries to be polygonized.
  * May be called multiple times.
@@ -195,7 +188,7 @@ Polygonizer::hasCutEdges()
 }
 
 /* public */
-const vector<LineString*>&
+const std::vector<std::unique_ptr<LineString>>&
 Polygonizer::getInvalidRingLines()
 {
     polygonize();
@@ -268,14 +261,14 @@ Polygonizer::polygonize()
 void
 Polygonizer::findValidRings(const vector<EdgeRing*>& edgeRingList,
                             vector<EdgeRing*>& validEdgeRingList,
-                            vector<LineString*>& invalidRingList)
+                            vector<std::unique_ptr<LineString>>& invalidRingList)
 {
     for(const auto& er : edgeRingList) {
         if(er->isValid()) {
             validEdgeRingList.push_back(er);
         }
         else {
-            invalidRingList.push_back(er->getLineString().release());
+            invalidRingList.push_back(er->getLineString());
         }
         GEOS_CHECK_FOR_INTERRUPTS();
     }

commit 099c88ab7ac809f62747635645ca105ed181cdd5
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 20:39:31 2019 -0400

    Store polygonize EdgeRing holes as unique_ptr
    
    Avoids leak in case of exception

diff --git a/include/geos/operation/polygonize/EdgeRing.h b/include/geos/operation/polygonize/EdgeRing.h
index c218dd2..56113c2 100644
--- a/include/geos/operation/polygonize/EdgeRing.h
+++ b/include/geos/operation/polygonize/EdgeRing.h
@@ -75,7 +75,7 @@ private:
     std::unique_ptr<geom::CoordinateArraySequence> ringPts;
     std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ringLocator;
 
-    std::unique_ptr<std::vector<geom::LinearRing*>> holes;
+    std::unique_ptr<std::vector<std::unique_ptr<geom::LinearRing>>> holes;
 
     EdgeRing* shell = nullptr;
     bool is_hole;
@@ -170,7 +170,7 @@ public:
 
     explicit EdgeRing(const geom::GeometryFactory* newFactory);
 
-    ~EdgeRing();
+    ~EdgeRing() = default;
 
     void build(PolygonizeDirectedEdge* startDE);
 
diff --git a/src/operation/polygonize/EdgeRing.cpp b/src/operation/polygonize/EdgeRing.cpp
index 437a0e3..7d5869a 100644
--- a/src/operation/polygonize/EdgeRing.cpp
+++ b/src/operation/polygonize/EdgeRing.cpp
@@ -145,18 +145,6 @@ EdgeRing::EdgeRing(const GeometryFactory* newFactory)
 #endif // DEBUG_ALLOC
 }
 
-EdgeRing::~EdgeRing()
-{
-#ifdef DEBUG_ALLOC
-    cerr << "[" << this << "] ~EdgeRing()" << endl;
-#endif // DEBUG_ALLOC
-    if(holes) {
-        for(auto& hole : *holes) {
-            delete hole;
-        }
-    }
-}
-
 void
 EdgeRing::build(PolygonizeDirectedEdge* startDE) {
     auto de = startDE;
@@ -187,9 +175,9 @@ void
 EdgeRing::addHole(LinearRing* hole)
 {
     if(holes == nullptr) {
-        holes.reset(new vector<LinearRing*>());
+        holes.reset(new std::vector<std::unique_ptr<LinearRing>>());
     }
-    holes->push_back(hole);
+    holes->emplace_back(hole);
 }
 
 void
@@ -203,8 +191,11 @@ EdgeRing::addHole(EdgeRing* holeER) {
 std::unique_ptr<Polygon>
 EdgeRing::getPolygon()
 {
-    std::unique_ptr<Polygon> poly(factory->createPolygon(ring.release(), holes.release()));
-    return poly;
+    if (holes) {
+        return factory->createPolygon(std::move(ring), std::move(*holes));
+    } else {
+        return factory->createPolygon(std::move(ring));
+    }
 }
 
 /*public*/

commit 4ffa3449f751e7be8508bd3259da8a8e18ec8003
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 19:58:17 2019 -0400

    Simplify BufferBuilder::createEmptyResultGeometry()
    
    Use empty polygon factory function.

diff --git a/src/operation/buffer/BufferBuilder.cpp b/src/operation/buffer/BufferBuilder.cpp
index dfe7951..1f0c9af 100644
--- a/src/operation/buffer/BufferBuilder.cpp
+++ b/src/operation/buffer/BufferBuilder.cpp
@@ -722,7 +722,7 @@ BufferBuilder::buildSubgraphs(const std::vector<BufferSubgraph*>& subgraphList,
 geom::Geometry*
 BufferBuilder::createEmptyResultGeometry() const
 {
-    geom::Geometry* emptyGeom = geomFact->createPolygon(nullptr, nullptr);
+    geom::Geometry* emptyGeom = geomFact->createPolygon();
     return emptyGeom;
 }
 

commit 9dc465d2d76e2c22c37a08e69d10d9d8f30d7f84
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 19:56:51 2019 -0400

    Return unique_ptr from Envelope->Geometry conversion

diff --git a/benchmarks/operation/predicate/RectangleIntersectsPerfTest.cpp b/benchmarks/operation/predicate/RectangleIntersectsPerfTest.cpp
index 5dcf9b2..9ff3b31 100644
--- a/benchmarks/operation/predicate/RectangleIntersectsPerfTest.cpp
+++ b/benchmarks/operation/predicate/RectangleIntersectsPerfTest.cpp
@@ -127,7 +127,7 @@ private:
                 Envelope envRect(
                     baseX, baseX + dx,
                     baseY, baseY + dy);
-                Geometry* rect = fact->toGeometry(&envRect);
+                Geometry* rect = fact->toGeometry(&envRect).release();
                 rectList.push_back(rect);
             }
         }
diff --git a/include/geos/geom/GeometryFactory.h b/include/geos/geom/GeometryFactory.h
index 4fc4760..ad2a66e 100644
--- a/include/geos/geom/GeometryFactory.h
+++ b/include/geos/geom/GeometryFactory.h
@@ -154,7 +154,7 @@ public:
     //
     /// Returned Geometry can be a Point, a Polygon or an EMPTY geom.
     ///
-    Geometry* toGeometry(const Envelope* envelope) const;
+    std::unique_ptr<Geometry> toGeometry(const Envelope* envelope) const;
 
     /// \brief
     /// Returns the PrecisionModel that Geometries created by this
diff --git a/src/geom/GeometryFactory.cpp b/src/geom/GeometryFactory.cpp
index 636607d..f3867ea 100644
--- a/src/geom/GeometryFactory.cpp
+++ b/src/geom/GeometryFactory.cpp
@@ -249,18 +249,18 @@ GeometryFactory::createPointFromInternalCoord(const Coordinate* coord,
 
 
 /*public*/
-Geometry*
+std::unique_ptr<Geometry>
 GeometryFactory::toGeometry(const Envelope* envelope) const
 {
     Coordinate coord;
 
     if(envelope->isNull()) {
-        return createPoint();
+        return std::unique_ptr<Geometry>(createPoint());
     }
     if(envelope->getMinX() == envelope->getMaxX() && envelope->getMinY() == envelope->getMaxY()) {
         coord.x = envelope->getMinX();
         coord.y = envelope->getMinY();
-        return createPoint(coord);
+        return std::unique_ptr<Geometry>(createPoint(coord));
     }
     auto cl = CoordinateArraySequenceFactory::instance()->
                              create((size_t) 5, 2);
@@ -285,8 +285,7 @@ GeometryFactory::toGeometry(const Envelope* envelope) const
     coord.y = envelope->getMinY();
     cl->setAt(coord, 4);
 
-    Polygon* p = createPolygon(createLinearRing(cl.release()), nullptr);
-    return p;
+    return createPolygon(createLinearRing(std::move(cl)));
 }
 
 /*public*/

commit 66175c2357e667d19b18d36ddd30622300bc6fc7
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sun Sep 15 19:53:50 2019 -0400

    Handle triangle coords with unique_ptr in QuadEdgeSubdivsion

diff --git a/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h b/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
index 7bd279a..f8df488 100644
--- a/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
+++ b/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
@@ -349,7 +349,7 @@ public:
 
 private:
     typedef std::stack<QuadEdge*> QuadEdgeStack;
-    typedef std::vector<geom::CoordinateSequence*> TriList;
+    typedef std::vector<std::unique_ptr<geom::CoordinateSequence>> TriList;
 
     /** \brief
      * The quadedges forming a single triangle.
diff --git a/src/triangulate/quadedge/QuadEdgeSubdivision.cpp b/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
index b5bdd55..6c57f47 100644
--- a/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
+++ b/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
@@ -408,7 +408,7 @@ public:
             coordSeq->setAt(v.getCoordinate(), i);
         }
         coordSeq->setAt(triEdges[0]->orig().getCoordinate(), 3);
-        triCoords->push_back(coordSeq.release());
+        triCoords->push_back(std::move(coordSeq));
     }
 };
 
@@ -502,10 +502,9 @@ QuadEdgeSubdivision::getTriangles(const GeometryFactory& geomFact)
     std::vector<std::unique_ptr<Geometry>> tris;
     tris.reserve(triPtsList.size());
 
-    for(CoordinateSequence* coordSeq : triPtsList) {
-        Polygon* tri = geomFact.createPolygon(
-                           geomFact.createLinearRing(coordSeq), nullptr);
-        tris.emplace_back(tri);
+    for(auto& coordSeq : triPtsList) {
+        tris.push_back(
+                geomFact.createPolygon(geomFact.createLinearRing(std::move(coordSeq))));
     }
 
     return geomFact.createGeometryCollection(std::move(tris));

-----------------------------------------------------------------------

Summary of changes:
 .../predicate/RectangleIntersectsPerfTest.cpp      |  2 +-
 capi/geos_ts_c.cpp                                 |  2 +-
 doc/example.cpp                                    |  8 +--
 include/geos/geom/GeometryFactory.h                | 31 ++++-----
 include/geos/geomgraph/EdgeRing.h                  | 14 ++---
 include/geos/operation/polygonize/EdgeRing.h       |  4 +-
 include/geos/operation/polygonize/Polygonizer.h    |  8 +--
 .../triangulate/quadedge/QuadEdgeSubdivision.h     |  2 +-
 include/geos/util/GeometricShapeFactory.h          | 11 ++--
 src/geom/GeometryFactory.cpp                       |  9 ++-
 src/geom/LinearRing.cpp                            |  2 +-
 src/geom/Polygon.cpp                               |  6 +-
 src/geom/util/SineStarFactory.cpp                  | 20 +++---
 src/geomgraph/EdgeRing.cpp                         | 23 ++-----
 src/operation/buffer/BufferBuilder.cpp             |  2 +-
 src/operation/polygonize/EdgeRing.cpp              | 23 +++----
 src/operation/polygonize/Polygonizer.cpp           | 13 +---
 src/triangulate/quadedge/QuadEdgeSubdivision.cpp   |  9 ++-
 src/util/GeometricShapeFactory.cpp                 | 73 +++++++++++-----------
 19 files changed, 110 insertions(+), 152 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list