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

git at osgeo.org git at osgeo.org
Tue Sep 17 18:40:03 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  a119a6e37b3a2640562e454c05463e336b1f1eea (commit)
       via  01f78df32cf6118533ce177b5cf8b6539ec66fe0 (commit)
       via  3bc986487433c0617896af18c6b0f6f16f4c1547 (commit)
      from  f9257802afd040a92fed345b5dba3215c17e463f (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 a119a6e37b3a2640562e454c05463e336b1f1eea
Merge: 01f78df f925780
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Sep 17 21:38:59 2019 -0400

    Merge branch 'master' of https://git.osgeo.org/gitea/geos/geos


commit 01f78df32cf6118533ce177b5cf8b6539ec66fe0
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Sep 17 21:36:08 2019 -0400

    Return unique_ptr for empty geometry factory methods

diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 7fbf810..c2a1b80 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -2284,7 +2284,7 @@ extern "C" {
             if(ret == nullptr) {
                 const GeometryFactory* gf = handle->geomFactory;
                 // return an empty point
-                return gf->createPoint();
+                return gf->createPoint().release();
             }
             return ret.release();
         }
@@ -2985,7 +2985,7 @@ extern "C" {
             Geometry* ret = g->getCentroid().release();
             if(0 == ret) {
                 const GeometryFactory* gf = handle->geomFactory;
-                return gf->createPoint();
+                return gf->createPoint().release();
             }
             return ret;
         }
@@ -3021,7 +3021,7 @@ extern "C" {
         try {
             const GeometryFactory* gf = handle->geomFactory;
 
-            Geometry* g = 0;
+            std::unique_ptr<Geometry> g = 0;
             switch(type) {
             case GEOS_GEOMETRYCOLLECTION:
                 g = gf->createGeometryCollection();
@@ -3041,7 +3041,7 @@ extern "C" {
 
             }
 
-            return g;
+            return g.release();
         }
         catch(const std::exception& e) {
             handle->ERROR_MESSAGE("%s", e.what());
@@ -3201,7 +3201,7 @@ extern "C" {
 
             auto polys = plgnzr.getPolygons();
             if (polys->empty()) {
-                out = handle->geomFactory->createGeometryCollection();
+                out = handle->geomFactory->createGeometryCollection().release();
             } else if (polys->size() == 1) {
                 out = (*polys)[0].release();
             } else {
@@ -4137,7 +4137,7 @@ extern "C" {
 
         try {
             const GeometryFactory* gf = handle->geomFactory;
-            return gf->createPoint();
+            return gf->createPoint().release();
         }
         catch(const std::exception& e) {
             handle->ERROR_MESSAGE("%s", e.what());
@@ -4248,7 +4248,7 @@ extern "C" {
         try {
             const GeometryFactory* gf = handle->geomFactory;
 
-            return gf->createLineString();
+            return gf->createLineString().release();
         }
         catch(const std::exception& e) {
             handle->ERROR_MESSAGE("%s", e.what());
@@ -4303,7 +4303,7 @@ extern "C" {
 
         try {
             const GeometryFactory* gf = handle->geomFactory;
-            return gf->createPolygon();
+            return gf->createPolygon().release();
         }
         catch(const std::exception& e) {
             handle->ERROR_MESSAGE("%s", e.what());
diff --git a/include/geos/geom/GeometryFactory.h b/include/geos/geom/GeometryFactory.h
index d7dbef4..0c00b71 100644
--- a/include/geos/geom/GeometryFactory.h
+++ b/include/geos/geom/GeometryFactory.h
@@ -164,7 +164,7 @@ public:
     const PrecisionModel* getPrecisionModel() const;
 
     /// Creates an EMPTY Point
-    Point* createPoint() const;
+    std::unique_ptr<Point> createPoint() const;
 
     /// Creates a Point using the given Coordinate
     Point* createPoint(const Coordinate& coordinate) const;
@@ -176,10 +176,10 @@ public:
     Point* createPoint(const CoordinateSequence& coordinates) const;
 
     /// Construct an EMPTY GeometryCollection
-    GeometryCollection* createGeometryCollection() const;
+    std::unique_ptr<GeometryCollection> createGeometryCollection() const;
 
     /// Construct the EMPTY Geometry
-    Geometry* createEmptyGeometry() const;
+    std::unique_ptr<Geometry> createEmptyGeometry() const;
 
     /// Construct a GeometryCollection taking ownership of given arguments
     GeometryCollection* createGeometryCollection(
@@ -193,7 +193,7 @@ public:
         const std::vector<const Geometry*>& newGeoms) const;
 
     /// Construct an EMPTY MultiLineString
-    MultiLineString* createMultiLineString() const;
+    std::unique_ptr<MultiLineString> createMultiLineString() const;
 
     /// Construct a MultiLineString taking ownership of given arguments
     MultiLineString* createMultiLineString(
@@ -210,7 +210,7 @@ public:
             std::vector<std::unique_ptr<Geometry>> && fromLines) const;
 
     /// Construct an EMPTY MultiPolygon
-    MultiPolygon* createMultiPolygon() const;
+    std::unique_ptr<MultiPolygon> createMultiPolygon() const;
 
     /// Construct a MultiPolygon taking ownership of given arguments
     MultiPolygon* createMultiPolygon(std::vector<Geometry*>* newPolys) const;
@@ -226,7 +226,7 @@ public:
             std::vector<std::unique_ptr<Geometry>> && fromPolys) const;
 
     /// Construct an EMPTY LinearRing
-    LinearRing* createLinearRing() const;
+    std::unique_ptr<LinearRing> createLinearRing() const;
 
     /// Construct a LinearRing taking ownership of given arguments
     LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
@@ -239,7 +239,7 @@ public:
         const CoordinateSequence& coordinates) const;
 
     /// Constructs an EMPTY <code>MultiPoint</code>.
-    MultiPoint* createMultiPoint() const;
+    std::unique_ptr<MultiPoint> createMultiPoint() const;
 
     /// Construct a MultiPoint taking ownership of given arguments
     MultiPoint* createMultiPoint(std::vector<Geometry*>* newPoints) const;
@@ -265,7 +265,7 @@ public:
         const std::vector<Coordinate>& fromCoords) const;
 
     /// Construct an EMPTY Polygon
-    Polygon* createPolygon() const;
+    std::unique_ptr<Polygon> createPolygon() const;
 
     /// Construct a Polygon taking ownership of given arguments
     Polygon* createPolygon(LinearRing* shell,
@@ -281,7 +281,7 @@ public:
                            const std::vector<LinearRing*>& holes) const;
 
     /// Construct an EMPTY LineString
-    LineString* createLineString() const;
+    std::unique_ptr<LineString> createLineString() const;
 
     /// Copy a LineString
     std::unique_ptr<LineString> createLineString(const LineString& ls) const;
diff --git a/include/geos/operation/overlay/OverlayOp.h b/include/geos/operation/overlay/OverlayOp.h
index 1a3d4ba..6132f65 100644
--- a/include/geos/operation/overlay/OverlayOp.h
+++ b/include/geos/operation/overlay/OverlayOp.h
@@ -353,7 +353,7 @@ private:
     * * #opDIFFERENCE - result has the dimension of the left-hand input
     * * #opSYMDIFFERENCE - result has the dimension of the highest input dimension
     */
-    static geom::Geometry* createEmptyResult(
+    static std::unique_ptr<geom::Geometry> createEmptyResult(
         OverlayOp::OpCode overlayOpCode, const geom::Geometry* a,
         const geom::Geometry* b, const geom::GeometryFactory* geomFact);
 
diff --git a/include/geos/operation/union/UnaryUnionOp.h b/include/geos/operation/union/UnaryUnionOp.h
index 9ee14b2..20077ca 100644
--- a/include/geos/operation/union/UnaryUnionOp.h
+++ b/include/geos/operation/union/UnaryUnionOp.h
@@ -197,7 +197,7 @@ private:
         //using geos::operation::overlay::snap::SnapIfNeededOverlayOp;
 
         if(! empty.get()) {
-            empty.reset(geomFact->createEmptyGeometry());
+            empty = geomFact->createEmptyGeometry();
         }
         //return SnapIfNeededOverlayOp::overlayOp(g0, *empty, OverlayOp::opUNION);
         return BinaryOp(&g0, empty.get(), overlay::overlayOp(OverlayOp::opUNION));
diff --git a/src/algorithm/MinimumBoundingCircle.cpp b/src/algorithm/MinimumBoundingCircle.cpp
index 5227d73..2533278 100644
--- a/src/algorithm/MinimumBoundingCircle.cpp
+++ b/src/algorithm/MinimumBoundingCircle.cpp
@@ -66,7 +66,7 @@ MinimumBoundingCircle::getFarthestPoints()
     compute();
     switch(extremalPts.size()) {
     case 0:
-        return input->getFactory()->createLineString();
+        return input->getFactory()->createLineString().release();
     case 1:
         return input->getFactory()->createPoint(centre);
     }
@@ -86,7 +86,7 @@ MinimumBoundingCircle::getDiameter()
     compute();
     switch(extremalPts.size()) {
     case 0:
-        return input->getFactory()->createLineString();
+        return input->getFactory()->createLineString().release();
     case 1:
         return input->getFactory()->createPoint(centre);
     }
diff --git a/src/geom/GeometryFactory.cpp b/src/geom/GeometryFactory.cpp
index f3867ea..368e6d1 100644
--- a/src/geom/GeometryFactory.cpp
+++ b/src/geom/GeometryFactory.cpp
@@ -296,10 +296,10 @@ GeometryFactory::getPrecisionModel() const
 }
 
 /*public*/
-Point*
+std::unique_ptr<Point>
 GeometryFactory::createPoint() const
 {
-    return new Point(nullptr, this);
+    return std::unique_ptr<Point>(new Point(nullptr, this));
 }
 
 /*public*/
@@ -307,7 +307,7 @@ Point*
 GeometryFactory::createPoint(const Coordinate& coordinate) const
 {
     if(coordinate.isNull()) {
-        return createPoint();
+        return createPoint().release();
     }
     else {
         return new Point(coordinate, this);
@@ -331,10 +331,10 @@ GeometryFactory::createPoint(const CoordinateSequence& fromCoords) const
 }
 
 /*public*/
-MultiLineString*
+std::unique_ptr<MultiLineString>
 GeometryFactory::createMultiLineString() const
 {
-    return new MultiLineString(nullptr, this);
+    return std::unique_ptr<MultiLineString>(new MultiLineString(nullptr, this));
 }
 
 /*public*/
@@ -378,17 +378,17 @@ GeometryFactory::createMultiLineString(std::vector<std::unique_ptr<Geometry>> &&
 }
 
 /*public*/
-GeometryCollection*
+std::unique_ptr<GeometryCollection>
 GeometryFactory::createGeometryCollection() const
 {
-    return new GeometryCollection(nullptr, this);
+    return std::unique_ptr<GeometryCollection>(new GeometryCollection(nullptr, this));
 }
 
 /*public*/
-Geometry*
+std::unique_ptr<Geometry>
 GeometryFactory::createEmptyGeometry() const
 {
-    return new GeometryCollection(nullptr, this);
+    return createGeometryCollection();
 }
 
 /*public*/
@@ -418,10 +418,10 @@ GeometryFactory::createGeometryCollection(const std::vector<const Geometry*>& fr
 }
 
 /*public*/
-MultiPolygon*
+std::unique_ptr<MultiPolygon>
 GeometryFactory::createMultiPolygon() const
 {
-    return new MultiPolygon(nullptr, this);
+    return std::unique_ptr<MultiPolygon>(new MultiPolygon(nullptr, this));
 }
 
 /*public*/
@@ -459,10 +459,10 @@ GeometryFactory::createMultiPolygon(const std::vector<const Geometry*>& fromPoly
 }
 
 /*public*/
-LinearRing*
+std::unique_ptr<LinearRing>
 GeometryFactory::createLinearRing() const
 {
-    return new LinearRing(nullptr, this);
+    return std::unique_ptr<LinearRing>(new LinearRing(nullptr, this));
 }
 
 /*public*/
@@ -522,10 +522,10 @@ GeometryFactory::createMultiPoint(const vector<const Geometry*>& fromPoints) con
 }
 
 /*public*/
-MultiPoint*
+std::unique_ptr<MultiPoint>
 GeometryFactory::createMultiPoint() const
 {
-    return new MultiPoint(nullptr, this);
+    return std::unique_ptr<MultiPoint>(new MultiPoint(nullptr, this));
 }
 
 /*public*/
@@ -557,10 +557,10 @@ GeometryFactory::createMultiPoint(const std::vector<Coordinate>& fromCoords) con
 }
 
 /*public*/
-Polygon*
+std::unique_ptr<Polygon>
 GeometryFactory::createPolygon() const
 {
-    return new Polygon(nullptr, nullptr, this);
+    return std::unique_ptr<Polygon>(new Polygon(nullptr, nullptr, this));
 }
 
 /*public*/
@@ -604,10 +604,10 @@ const
 }
 
 /*public*/
-LineString*
+std::unique_ptr<LineString>
 GeometryFactory::createLineString() const
 {
-    return new LineString(nullptr, this);
+    return std::unique_ptr<LineString>(new LineString(nullptr, this));
 }
 
 /*public*/
@@ -654,7 +654,7 @@ GeometryFactory::buildGeometry(vector<Geometry*>* newGeoms) const
     if(newGeoms->empty()) {
         // we do not need the vector anymore
         delete newGeoms;
-        return createGeometryCollection();
+        return createGeometryCollection().release();
     }
 
     bool isHeterogeneous = false;
@@ -707,7 +707,7 @@ GeometryFactory::buildGeometry(const vector<const Geometry*>& fromGeoms) const
 {
     size_t geomsSize = fromGeoms.size();
     if(geomsSize == 0) {
-        return createGeometryCollection();
+        return createGeometryCollection().release();
     }
 
     if(geomsSize == 1) {
diff --git a/src/geom/Polygon.cpp b/src/geom/Polygon.cpp
index a807938..bb95902 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());
+        shell = 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());
+        shell = getFactory()->createLinearRing();
     }
 }
 
@@ -105,7 +105,7 @@ Polygon::Polygon(std::unique_ptr<LinearRing> && newShell,
                  holes(std::move(newHoles))
 {
     if(shell == nullptr) {
-        shell.reset(getFactory()->createLinearRing());
+        shell = getFactory()->createLinearRing();
     }
 
     // TODO move into validateConstruction() method
diff --git a/src/operation/buffer/BufferBuilder.cpp b/src/operation/buffer/BufferBuilder.cpp
index 1f0c9af..2f84c51 100644
--- a/src/operation/buffer/BufferBuilder.cpp
+++ b/src/operation/buffer/BufferBuilder.cpp
@@ -372,7 +372,7 @@ BufferBuilder::bufferLineSingleSided(const Geometry* g, double distance,
     }
     else {
         delete mergedLinesGeom;
-        return geomFact->createLineString();
+        return geomFact->createLineString().release();
     }
 }
 
@@ -722,7 +722,7 @@ BufferBuilder::buildSubgraphs(const std::vector<BufferSubgraph*>& subgraphList,
 geom::Geometry*
 BufferBuilder::createEmptyResultGeometry() const
 {
-    geom::Geometry* emptyGeom = geomFact->createPolygon();
+    geom::Geometry* emptyGeom = geomFact->createPolygon().release();
     return emptyGeom;
 }
 
diff --git a/src/operation/overlay/OverlayOp.cpp b/src/operation/overlay/OverlayOp.cpp
index b623f03..877d697 100644
--- a/src/operation/overlay/OverlayOp.cpp
+++ b/src/operation/overlay/OverlayOp.cpp
@@ -661,12 +661,12 @@ OverlayOp::resultDimension(OverlayOp::OpCode overlayOpCode,
     return resultDimension;
 }
 
-geom::Geometry*
+std::unique_ptr<geom::Geometry>
 OverlayOp::createEmptyResult(OverlayOp::OpCode overlayOpCode,
                              const geom::Geometry* a, const geom::Geometry* b,
                              const GeometryFactory* geomFact)
 {
-    geom::Geometry* result = nullptr;
+    std::unique_ptr<geom::Geometry> result = nullptr;
     switch(resultDimension(overlayOpCode, a, b)) {
     case Dimension::P:
         result = geomFact->createPoint();
@@ -714,7 +714,7 @@ OverlayOp::computeGeometry(vector<Point*>* nResultPointList,
 
     if(geomList->empty()) {
         return createEmptyResult(opCode, arg[0]->getGeometry(),
-                                 arg[1]->getGeometry(), geomFact);
+                                 arg[1]->getGeometry(), geomFact).release();
     }
     // build the most specific geometry possible
     Geometry* g = geomFact->buildGeometry(geomList.release());
diff --git a/src/operation/union/UnaryUnionOp.cpp b/src/operation/union/UnaryUnionOp.cpp
index 26a2d5c..4a2af1f 100644
--- a/src/operation/union/UnaryUnionOp.cpp
+++ b/src/operation/union/UnaryUnionOp.cpp
@@ -132,7 +132,7 @@ UnaryUnionOp::Union()
     }
 
     if(! ret.get()) {
-        ret.reset(geomFact->createGeometryCollection());
+        ret = geomFact->createGeometryCollection();
     }
 
     return ret;
diff --git a/tests/unit/geom/GeometryFactoryTest.cpp b/tests/unit/geom/GeometryFactoryTest.cpp
index 2ad4e51..bf74681 100644
--- a/tests/unit/geom/GeometryFactoryTest.cpp
+++ b/tests/unit/geom/GeometryFactoryTest.cpp
@@ -87,13 +87,10 @@ void object::test<1>
     ensure_equals(gf->getSRID(), 0);
     ensure_equals(gf->getPrecisionModel()->getType(), geos::geom::PrecisionModel::FLOATING);
 
-    geos::geom::Geometry* geo = gf->createEmptyGeometry();
+    auto geo = gf->createEmptyGeometry();
     ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
     ensure_equals(geo->getSRID(), gf->getSRID());
     ensure_equals(geo->getPrecisionModel()->getType(), geos::geom::PrecisionModel::FLOATING);
-
-    // FREE MEMORY
-    gf->destroyGeometry(geo);
 }
 
 // Test of user's constructor
@@ -117,13 +114,10 @@ void object::test<2>
 
         ensure_equals(&csf, gf->getCoordinateSequenceFactory());
 
-        GeometryPtr geo = gf->createEmptyGeometry();
+        auto geo = gf->createEmptyGeometry();
         ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
         ensure_equals(geo->getSRID(), gf->getSRID());
         ensure_equals(geo->getPrecisionModel()->getType(), geos::geom::PrecisionModel::FIXED);
-
-        // FREE MEMORY
-        gf->destroyGeometry(geo);
     }
     // csf lifetime must exceed lifetime of the GeometryFactory instance
 
@@ -146,13 +140,10 @@ void object::test<3>
         ensure_equals(gf->getSRID(), 0);
         ensure_equals(gf->getPrecisionModel()->getType(), geos::geom::PrecisionModel::FLOATING);
 
-        GeometryPtr geo = gf->createEmptyGeometry();
+        auto geo = gf->createEmptyGeometry();
         ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
         ensure_equals(geo->getSRID(), gf->getSRID());
         ensure_equals(geo->getPrecisionModel()->getType(), geos::geom::PrecisionModel::FLOATING);
-
-        // FREE MEMORY
-        gf->destroyGeometry(geo);
     }
     // csf lifetime must exceed lifetime of the GeometryFactory instance
 }
@@ -172,13 +163,10 @@ void object::test<4>
     ensure_equals(gf->getSRID(), 0);
     ensure_equals(gf->getPrecisionModel()->getType(), PrecisionModel::FIXED);
 
-    GeometryPtr geo = gf->createEmptyGeometry();
+    auto geo = gf->createEmptyGeometry();
     ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
     ensure_equals(geo->getSRID(), gf->getSRID());
     ensure_equals(geo->getPrecisionModel()->getType(), PrecisionModel::FIXED);
-
-    // FREE MEMORY
-    gf->destroyGeometry(geo);
 }
 
 // Test of user's constructor
@@ -196,13 +184,10 @@ void object::test<5>
     ensure_equals(gf->getSRID(), srid_);
     ensure_equals(gf->getPrecisionModel()->getType(), PrecisionModel::FIXED);
 
-    GeometryPtr geo = gf->createEmptyGeometry();
+    auto geo = gf->createEmptyGeometry();
     ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
     ensure_equals(geo->getSRID(), gf->getSRID());
     ensure_equals(geo->getPrecisionModel()->getType(), PrecisionModel::FIXED);
-
-    // FREE MEMORY
-    gf->destroyGeometry(geo);
 }
 
 // Test of copy constructor
@@ -224,7 +209,7 @@ template<>
 void object::test<7>
 ()
 {
-    GeometryPtr geo = factory_->createEmptyGeometry();
+    auto geo = factory_->createEmptyGeometry();
 
     ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
     ensure("createEmptyGeometry() returned non-empty geometry.", geo->isEmpty());
@@ -238,9 +223,6 @@ void object::test<7>
     ensure( geo->getCentroid() == 0 );
     ensure( geo->getCoordinate() == 0 );
     */
-
-    // FREE MEMORY
-    factory_->destroyGeometry(geo);
 }
 
 // Test of createPoint() const
@@ -249,7 +231,7 @@ template<>
 void object::test<8>
 ()
 {
-    PointPtr pt = factory_->createPoint();
+    auto pt = factory_->createPoint();
 
     ensure("createPoint() returned null pointer.", pt != nullptr);
     ensure("createPoint() returned non-empty point.", pt->isEmpty());
@@ -277,9 +259,6 @@ void object::test<8>
     ensure_equals(pt->getNumPoints(), 0u);
     ensure_equals(pt->getLength(), 0.0);
     ensure_equals(pt->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(pt);
 }
 
 // Test of createPoint(const Coordinate &coordinate) const
@@ -446,7 +425,7 @@ template<>
 void object::test<12>
 ()
 {
-    LinearRingPtr lr = factory_->createLinearRing();
+    auto lr = factory_->createLinearRing();
 
     ensure("createLinearRing() returned null pointer.", lr != nullptr);
     ensure("createLinearRing() returned non-empty point.", lr->isEmpty());
@@ -469,9 +448,6 @@ void object::test<12>
     ensure_equals(lr->getNumPoints(), 0u);
     ensure_equals(lr->getLength(), 0.0);
     ensure_equals(lr->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(lr);
 }
 
 // Test of createLinearRing(CoordinateSequence* newCoords) const
@@ -538,7 +514,7 @@ template<>
 void object::test<15>
 ()
 {
-    LineStringPtr line = factory_->createLineString();
+    auto line = factory_->createLineString();
 
     ensure("createLineString() returned null pointer.", line != nullptr);
     ensure("createLineString() returned non-empty point.", line->isEmpty());
@@ -569,9 +545,6 @@ void object::test<15>
     ensure_equals(line->getNumPoints(), 0u);
     ensure_equals(line->getLength(), 0.0);
     ensure_equals(line->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(line);
 }
 
 // Test of createLineString(CoordinateSequence* coordinates) const
@@ -637,7 +610,7 @@ template<>
 void object::test<18>
 ()
 {
-    PolygonPtr poly = factory_->createPolygon();
+    auto poly = factory_->createPolygon();
 
     ensure("createPolygon() returned null pointer.", poly != nullptr);
     ensure("createPolygon() returned non-empty point.", poly->isEmpty());
@@ -671,9 +644,6 @@ void object::test<18>
     ensure_equals(poly->getNumPoints(), 0u);
     ensure_equals(poly->getLength(), 0.0);
     ensure_equals(poly->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(poly);
 }
 
 // Test of createPolygon(LinearRing* shell, std::vector<Geometry*>* holes) const
@@ -803,7 +773,7 @@ template<>
 void object::test<21>
 ()
 {
-    GeometryColPtr col = factory_->createGeometryCollection();
+    auto col = factory_->createGeometryCollection();
 
     ensure("createGeometryCollection() returned null pointer.", col != nullptr);
     ensure(col->isEmpty());
@@ -815,9 +785,6 @@ void object::test<21>
     ensure_equals(col->getNumPoints(), 0u);
     ensure_equals(col->getLength(), 0.0);
     ensure_equals(col->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(col);
 }
 
 // Test of createGeometryCollection(std::vector<Geometry*>* newGeoms) const
@@ -903,7 +870,7 @@ template<>
 void object::test<24>
 ()
 {
-    MultiPointPtr mp = factory_->createMultiPoint();
+    auto mp = factory_->createMultiPoint();
 
     ensure("createMultiPoint() returned null pointer.", mp != nullptr);
     ensure("createMultiPoint() returned non-empty point.", mp->isEmpty());
@@ -934,9 +901,6 @@ void object::test<24>
     ensure_equals(mp->getNumPoints(), 0u);
     ensure_equals(mp->getLength(), 0.0);
     ensure_equals(mp->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(mp);
 }
 
 // Test of createMultiPoint(std::vector<Geometry*>* newPoints) const
@@ -1056,7 +1020,7 @@ template<>
 void object::test<28>
 ()
 {
-    MultiLineStringPtr mls = factory_->createMultiLineString();
+    auto mls = factory_->createMultiLineString();
 
     ensure("createMultiLineString() returned null pointer.", mls != nullptr);
     ensure("createMultiLineString() returned non-empty point.", mls->isEmpty());
@@ -1087,9 +1051,6 @@ void object::test<28>
     ensure_equals(mls->getNumPoints(), 0u);
     ensure_equals(mls->getLength(), 0.0);
     ensure_equals(mls->getArea(), 0.0);
-
-    // FREE MEMORY
-    factory_->destroyGeometry(mls);
 }
 
 // Test of createMultiLineString(std::vector<Geometry*>* newLines) const
diff --git a/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp b/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
index b5e7e18..40c8d61 100644
--- a/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
+++ b/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
@@ -107,7 +107,7 @@ template<>
 void object::test<4>
 ()
 {
-    g_.reset(factory_->createEmptyGeometry());
+    g_= factory_->createEmptyGeometry();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -122,7 +122,7 @@ template<>
 void object::test<5>
 ()
 {
-    g_.reset(factory_->createEmptyGeometry());
+    g_ = factory_->createEmptyGeometry();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
@@ -138,7 +138,7 @@ template<>
 void object::test<6>
 ()
 {
-    g_.reset(factory_->createPoint());
+    g_ = factory_->createPoint();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -153,7 +153,7 @@ template<>
 void object::test<7>
 ()
 {
-    g_.reset(factory_->createPoint());
+    g_ = factory_->createPoint();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
@@ -169,7 +169,7 @@ template<>
 void object::test<8>
 ()
 {
-    g_.reset(factory_->createLineString());
+    g_ = factory_->createLineString();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -184,7 +184,7 @@ template<>
 void object::test<9>
 ()
 {
-    g_.reset(factory_->createLineString());
+    g_ = factory_->createLineString();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
@@ -199,7 +199,7 @@ template<>
 void object::test<10>
 ()
 {
-    g_.reset(factory_->createPolygon());
+    g_ = factory_->createPolygon();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -214,7 +214,7 @@ template<>
 void object::test<11>
 ()
 {
-    g_.reset(factory_->createPolygon());
+    g_ = factory_->createPolygon();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
@@ -230,7 +230,7 @@ template<>
 void object::test<12>
 ()
 {
-    g_.reset(factory_->createMultiPoint());
+    g_ = factory_->createMultiPoint();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -245,7 +245,7 @@ template<>
 void object::test<13>
 ()
 {
-    g_.reset(factory_->createMultiPoint());
+    g_ = factory_->createMultiPoint();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
@@ -261,7 +261,7 @@ template<>
 void object::test<14>
 ()
 {
-    g_.reset(factory_->createMultiLineString());
+    g_ = factory_->createMultiLineString();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -276,7 +276,7 @@ template<>
 void object::test<15>
 ()
 {
-    g_.reset(factory_->createMultiLineString());
+    g_ = factory_->createMultiLineString();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
@@ -292,7 +292,7 @@ template<>
 void object::test<16>
 ()
 {
-    g_.reset(factory_->createMultiPolygon());
+    g_ = factory_->createMultiPolygon();
     ensure(nullptr != g_);
 
     pg_ = prep::PreparedGeometryFactory::prepare(g_.get());
@@ -307,7 +307,7 @@ template<>
 void object::test<17>
 ()
 {
-    g_.reset(factory_->createMultiPolygon());
+    g_ = factory_->createMultiPolygon();
     ensure(nullptr != g_);
 
     prep::PreparedGeometryFactory pgf;
diff --git a/tests/xmltester/XMLTester.cpp b/tests/xmltester/XMLTester.cpp
index 77635e6..d94a452 100644
--- a/tests/xmltester/XMLTester.cpp
+++ b/tests/xmltester/XMLTester.cpp
@@ -1272,7 +1272,7 @@ XMLTester::parseTest(const tinyxml2::XMLNode* node)
                 gRealRes->normalize();
             }
             else {
-                gRealRes.reset(factory->createPoint());
+                gRealRes = factory->createPoint();
             }
             gRealRes->normalize();
 
@@ -1471,7 +1471,7 @@ XMLTester::parseTest(const tinyxml2::XMLNode* node)
                 gRealRes->normalize();
             }
             else {
-                gRealRes.reset(factory->createPoint());
+                gRealRes = factory->createPoint();
             }
 
             if(gRes->compareTo(gRealRes.get()) == 0) {

commit 3bc986487433c0617896af18c6b0f6f16f4c1547
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..d7dbef4 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));
-        }
-        else if(dynamic_cast<const Point*>(*from)) {
-            return std::unique_ptr<Geometry>(createMultiPoint(fromGeoms));
+        switch((*from)->getDimension()) {
+            case Dimension::A: return createMultiPolygon(std::move(fromGeoms));
+            case Dimension::L: return createMultiLineString(std::move(fromGeoms));
+            case Dimension::P: return createMultiPoint(std::move(fromGeoms));
+            default:
+                throw geos::util::IllegalArgumentException("Invalid geometry type.");
         }
-        // FIXME: Why not to throw an exception? --mloskot
-        assert(0); // buildGeomtry encountered an unkwnon geometry type
-        return std::unique_ptr<Geometry>(); // nullptr
     }
 
     /** \brief

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

Summary of changes:
 capi/geos_ts_c.cpp                                 | 16 +++---
 include/geos/geom/GeometryFactory.h                | 28 +++++-----
 include/geos/operation/overlay/OverlayOp.h         |  2 +-
 include/geos/operation/union/UnaryUnionOp.h        |  2 +-
 src/algorithm/MinimumBoundingCircle.cpp            |  4 +-
 src/geom/GeometryFactory.cpp                       | 42 +++++++-------
 src/geom/Polygon.cpp                               |  6 +-
 src/operation/buffer/BufferBuilder.cpp             |  4 +-
 src/operation/overlay/OverlayOp.cpp                |  6 +-
 src/operation/union/UnaryUnionOp.cpp               |  2 +-
 tests/unit/geom/GeometryFactoryTest.cpp            | 65 +++++-----------------
 .../unit/geom/prep/PreparedGeometryFactoryTest.cpp | 28 +++++-----
 tests/xmltester/XMLTester.cpp                      |  4 +-
 13 files changed, 85 insertions(+), 124 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list