[geos-commits] [SCM] GEOS branch master updated. 3af99a815b30eaac61b9bf234c6677c5e41fcf73
git at osgeo.org
git at osgeo.org
Thu May 23 12:51:36 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 3af99a815b30eaac61b9bf234c6677c5e41fcf73 (commit)
via 449b033d832d2fefeb86d5d43964a19ba70e4688 (commit)
via 356f7568c300a2071efeb0623aa2fdde2b3bb25e (commit)
via 3a8cc94f3daa75820696d6e0870010be79ef3a62 (commit)
from 534da33a191e86371be607f21d707ef4d79c38b5 (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 3af99a815b30eaac61b9bf234c6677c5e41fcf73
Merge: 449b033 356f756
Author: Daniel Baston <dbaston at gmail.com>
Date: Thu May 23 15:51:21 2019 -0400
Merge branch 'prep-geom-uniqueptr'
commit 449b033d832d2fefeb86d5d43964a19ba70e4688
Merge: 534da33 3a8cc94
Author: Daniel Baston <dbaston at gmail.com>
Date: Thu May 23 15:51:00 2019 -0400
Merge branch 'coordseq-unique-ptr'
commit 356f7568c300a2071efeb0623aa2fdde2b3bb25e
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed May 22 22:04:03 2019 -0400
Use unique_ptr for prepared geometries
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 5744252..827c73b 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -5280,7 +5280,7 @@ extern "C" {
const geos::geom::prep::PreparedGeometry* prep = 0;
try {
- prep = geos::geom::prep::PreparedGeometryFactory::prepare(g);
+ prep = geos::geom::prep::PreparedGeometryFactory::prepare(g).release();
}
catch(const std::exception& e) {
handle->ERROR_MESSAGE("%s", e.what());
diff --git a/include/geos/geom/prep/PreparedGeometryFactory.h b/include/geos/geom/prep/PreparedGeometryFactory.h
index 3260772..a44b9e4 100644
--- a/include/geos/geom/prep/PreparedGeometryFactory.h
+++ b/include/geos/geom/prep/PreparedGeometryFactory.h
@@ -23,6 +23,8 @@
#include <geos/export.h>
#include <geos/geom/prep/PreparedGeometry.h>
+#include <memory>
+
namespace geos {
namespace geom {
namespace prep {
@@ -58,7 +60,7 @@ public:
* @param geom the geometry to prepare
* @return the prepared geometry
*/
- static const PreparedGeometry*
+ static std::unique_ptr<PreparedGeometry>
prepare(const geom::Geometry* geom)
{
PreparedGeometryFactory pf;
@@ -82,7 +84,7 @@ public:
* @param geom the geometry to prepare
* @return the prepared geometry
*/
- const PreparedGeometry* create(const geom::Geometry* geom) const;
+ std::unique_ptr<PreparedGeometry> create(const geom::Geometry* geom) const;
};
diff --git a/src/geom/prep/PreparedGeometryFactory.cpp b/src/geom/prep/PreparedGeometryFactory.cpp
index a37b75a..899eff9 100644
--- a/src/geom/prep/PreparedGeometryFactory.cpp
+++ b/src/geom/prep/PreparedGeometryFactory.cpp
@@ -36,7 +36,7 @@ namespace geos {
namespace geom { // geos.geom
namespace prep { // geos.geom.prep
-const PreparedGeometry*
+std::unique_ptr<PreparedGeometry>
PreparedGeometryFactory::create(const geom::Geometry* g) const
{
using geos::geom::GeometryTypeId;
@@ -45,27 +45,27 @@ PreparedGeometryFactory::create(const geom::Geometry* g) const
throw util::IllegalArgumentException("PreparedGeometry constructed with null Geometry object");
}
- PreparedGeometry* pg = nullptr;
+ std::unique_ptr<PreparedGeometry> pg;
switch(g->getGeometryTypeId()) {
case GEOS_MULTIPOINT:
case GEOS_POINT:
- pg = new PreparedPoint(g);
+ pg.reset(new PreparedPoint(g));
break;
case GEOS_LINEARRING:
case GEOS_LINESTRING:
case GEOS_MULTILINESTRING:
- pg = new PreparedLineString(g);
+ pg.reset(new PreparedLineString(g));
break;
case GEOS_POLYGON:
case GEOS_MULTIPOLYGON:
- pg = new PreparedPolygon(g);
+ pg.reset(new PreparedPolygon(g));
break;
default:
- pg = new BasicPreparedGeometry(g);
+ pg.reset(new BasicPreparedGeometry(g));
}
return pg;
}
diff --git a/tests/unit/geom/prep/PreparedGeometry/touchesTest.cpp b/tests/unit/geom/prep/PreparedGeometry/touchesTest.cpp
index 6d99264..a042c17 100644
--- a/tests/unit/geom/prep/PreparedGeometry/touchesTest.cpp
+++ b/tests/unit/geom/prep/PreparedGeometry/touchesTest.cpp
@@ -14,6 +14,7 @@
#include <memory>
using namespace geos::geom;
+using geos::geom::prep::PreparedGeometry;
namespace tut {
@@ -22,15 +23,14 @@ namespace tut {
//
struct test_preparedgeometrytouches_data {
- typedef std::unique_ptr<geos::geom::prep::PreparedGeometry> PrepGeomAutoPtr;
typedef geos::geom::GeometryFactory GeometryFactory;
geos::geom::GeometryFactory::Ptr factory;
geos::io::WKTReader reader;
GeometryPtr g1;
GeometryPtr g2;
- PreparedGeometryPtr pg1;
- PreparedGeometryPtr pg2;
+ std::unique_ptr<PreparedGeometry> pg1;
+ std::unique_ptr<PreparedGeometry> pg2;
test_preparedgeometrytouches_data()
: factory(GeometryFactory::create())
@@ -42,8 +42,6 @@ struct test_preparedgeometrytouches_data {
{}
~test_preparedgeometrytouches_data()
{
- prep::PreparedGeometryFactory::destroy(pg1);
- prep::PreparedGeometryFactory::destroy(pg2);
factory->destroyGeometry(g1);
factory->destroyGeometry(g2);
}
diff --git a/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp b/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
index f6369fe..f2c2168 100644
--- a/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
+++ b/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
@@ -27,7 +27,7 @@ namespace tut {
struct test_preparedgeometryfactory_data {
typedef geos::geom::GeometryFactory GeometryFactory;
GeometryPtr g_;
- PreparedGeometryPtr pg_;
+ std::unique_ptr<geos::geom::prep::PreparedGeometry> pg_;
geos::geom::PrecisionModel pm_;
geos::geom::GeometryFactory::Ptr factory_;
geos::io::WKTReader reader_;
@@ -44,9 +44,7 @@ struct test_preparedgeometryfactory_data {
~test_preparedgeometryfactory_data()
{
// FREE MEMORY per test case
- prep::PreparedGeometryFactory::destroy(pg_);
factory_->destroyGeometry(g_);
- pg_ = nullptr;
g_ = nullptr;
}
@@ -122,7 +120,7 @@ void object::test<4>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty GEOMETRY
@@ -138,7 +136,7 @@ void object::test<5>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare empty POINT
@@ -153,7 +151,7 @@ void object::test<6>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty POINT
@@ -169,7 +167,7 @@ void object::test<7>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare empty LINESTRING
@@ -184,7 +182,7 @@ void object::test<8>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty LINESTRING
@@ -199,7 +197,7 @@ void object::test<9>
prep::PreparedGeometryFactory pgf;
pg_ = pgf.create(g_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare empty POLYGON
@@ -214,7 +212,7 @@ void object::test<10>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty POLYGON
@@ -230,7 +228,7 @@ void object::test<11>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare empty MULTIPOINT
@@ -245,7 +243,7 @@ void object::test<12>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty MULTIPOINT
@@ -261,7 +259,7 @@ void object::test<13>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare empty MULTILINESTRING
@@ -276,7 +274,7 @@ void object::test<14>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty MULTILINESTRING
@@ -292,7 +290,7 @@ void object::test<15>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare empty MULTIPOLYGON
@@ -307,7 +305,7 @@ void object::test<16>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create empty MULTIPOLYGON
@@ -323,7 +321,7 @@ void object::test<17>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare non-empty POINT
@@ -338,7 +336,7 @@ void object::test<18>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create non-empty POINT
@@ -354,7 +352,7 @@ void object::test<19>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare non-empty LINESTRING
@@ -369,7 +367,7 @@ void object::test<20>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create non-empty LINESTRING
@@ -385,7 +383,7 @@ void object::test<21>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare non-empty LINESTRING
@@ -400,7 +398,7 @@ void object::test<22>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create non-empty LINESTRING
@@ -416,7 +414,7 @@ void object::test<23>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare non-empty MULTIPOINT
@@ -431,7 +429,7 @@ void object::test<24>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create non-empty MULTIPOINT
@@ -447,7 +445,7 @@ void object::test<25>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare non-empty MULTILINESTRING
@@ -462,7 +460,7 @@ void object::test<26>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create non-empty MULTILINESTRING
@@ -478,7 +476,7 @@ void object::test<27>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test prepare non-empty POLYGON
@@ -493,7 +491,7 @@ void object::test<28>
pg_ = prep::PreparedGeometryFactory::prepare(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
// Test create non-empty POLYGON
@@ -509,7 +507,7 @@ void object::test<29>
pg_ = pgf.create(g_);
ensure(nullptr != pg_);
- ensure_equals_geometry(g_, pg_);
+ ensure_equals_geometry(g_, pg_.get());
}
} // namespace tut
diff --git a/tests/xmltester/XMLTester.cpp b/tests/xmltester/XMLTester.cpp
index 715d3f2..98da320 100644
--- a/tests/xmltester/XMLTester.cpp
+++ b/tests/xmltester/XMLTester.cpp
@@ -98,7 +98,7 @@ namespace {
std::unique_ptr<const PreparedGeometry>
prepare(const geom::Geometry* g)
{
- return std::unique_ptr<const PreparedGeometry> (PreparedGeometryFactory::prepare(g));
+ return PreparedGeometryFactory::prepare(g);
}
// Asymmetric Rounding Algorithm - equivalent to Java Math.round()
commit 3a8cc94f3daa75820696d6e0870010be79ef3a62
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed May 22 20:55:32 2019 -0400
Use unique_ptr for functions returning CoordinateSequence
This incrementally chips away at the long-term goal of using managed
pointers throughout GEOS, while also working to solidify the
CoordinateSequence interface before building additional implementations.
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 5744252..c867684 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3672,7 +3672,7 @@ extern "C" {
try {
const GeometryFactory* gf = handle->geomFactory;
- return gf->getCoordinateSequenceFactory()->create(size, dims);
+ return gf->getCoordinateSequenceFactory()->create(size, dims).release();
}
catch(const std::exception& e) {
handle->ERROR_MESSAGE("%s", e.what());
@@ -3747,7 +3747,7 @@ extern "C" {
}
try {
- return cs->clone();
+ return cs->clone().release();
}
catch(const std::exception& e) {
handle->ERROR_MESSAGE("%s", e.what());
diff --git a/include/geos/algorithm/ConvexHull.h b/include/geos/algorithm/ConvexHull.h
index 6b687a1..3b7b0ef 100644
--- a/include/geos/algorithm/ConvexHull.h
+++ b/include/geos/algorithm/ConvexHull.h
@@ -22,10 +22,12 @@
#define GEOS_ALGORITHM_CONVEXHULL_H
#include <geos/export.h>
+#include <memory>
#include <vector>
// FIXME: avoid using Cordinate:: typedefs to avoid full include
#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
#ifdef _MSC_VER
#pragma warning(push)
@@ -37,7 +39,6 @@ namespace geos {
namespace geom {
class Geometry;
class GeometryFactory;
-class CoordinateSequence;
}
}
@@ -66,7 +67,7 @@ private:
/// This is needed to construct the geometries.
/// Here coordinate copies happen
/// The returned object is newly allocated !NO EXCEPTION SAFE!
- geom::CoordinateSequence* toCoordinateSequence(geom::Coordinate::ConstVect& cv);
+ std::unique_ptr<geom::CoordinateSequence> toCoordinateSequence(geom::Coordinate::ConstVect& cv);
void computeOctPts(const geom::Coordinate::ConstVect& src,
geom::Coordinate::ConstVect& tgt);
diff --git a/include/geos/algorithm/MinimumDiameter.h b/include/geos/algorithm/MinimumDiameter.h
index 92141ab..31ba1bb 100644
--- a/include/geos/algorithm/MinimumDiameter.h
+++ b/include/geos/algorithm/MinimumDiameter.h
@@ -20,6 +20,7 @@
#ifndef GEOS_ALGORITHM_MINIMUMDIAMETER_H
#define GEOS_ALGORITHM_MINIMUMDIAMETER_H
+#include <memory>
#include <geos/export.h>
// Forward declarations
@@ -67,7 +68,7 @@ private:
const geom::Geometry* inputGeom;
bool isConvex;
- geom::CoordinateSequence* convexHullPts;
+ std::unique_ptr<geom::CoordinateSequence> convexHullPts;
geom::LineSegment* minBaseSeg;
geom::Coordinate* minWidthPt;
diff --git a/include/geos/geom/CoordinateArraySequence.h b/include/geos/geom/CoordinateArraySequence.h
index 9d8fa18..f25103e 100644
--- a/include/geos/geom/CoordinateArraySequence.h
+++ b/include/geos/geom/CoordinateArraySequence.h
@@ -41,7 +41,7 @@ public:
CoordinateArraySequence(const CoordinateSequence& cl);
- CoordinateSequence* clone() const override;
+ std::unique_ptr<CoordinateSequence> clone() const override;
//const Coordinate& getCoordinate(int pos) const;
const Coordinate& getAt(std::size_t pos) const override;
diff --git a/include/geos/geom/CoordinateArraySequenceFactory.h b/include/geos/geom/CoordinateArraySequenceFactory.h
index 9bb3abb..870a8ff 100644
--- a/include/geos/geom/CoordinateArraySequenceFactory.h
+++ b/include/geos/geom/CoordinateArraySequenceFactory.h
@@ -43,14 +43,14 @@ namespace geom { // geos::geom
class GEOS_DLL CoordinateArraySequenceFactory: public CoordinateSequenceFactory {
public:
- CoordinateSequence* create() const override;
+ std::unique_ptr<CoordinateSequence> create() const override;
- CoordinateSequence* create(std::vector<Coordinate>* coords, std::size_t dims = 0) const override;
+ std::unique_ptr<CoordinateSequence> create(std::vector<Coordinate>* coords, std::size_t dims = 0) const override;
/** @see CoordinateSequenceFactory::create(std::size_t, int) */
- CoordinateSequence* create(std::size_t size, std::size_t dimension = 0) const override;
+ std::unique_ptr<CoordinateSequence> create(std::size_t size, std::size_t dimension = 0) const override;
- CoordinateSequence* create(const CoordinateSequence& coordSeq) const override;
+ std::unique_ptr<CoordinateSequence> create(const CoordinateSequence& coordSeq) const override;
/** \brief
* Returns the singleton instance of CoordinateArraySequenceFactory
diff --git a/include/geos/geom/CoordinateArraySequenceFactory.inl b/include/geos/geom/CoordinateArraySequenceFactory.inl
index 39bc0d6..dfee25f 100644
--- a/include/geos/geom/CoordinateArraySequenceFactory.inl
+++ b/include/geos/geom/CoordinateArraySequenceFactory.inl
@@ -22,32 +22,36 @@
namespace geos {
namespace geom { // geos::geom
-INLINE CoordinateSequence*
+INLINE std::unique_ptr<CoordinateSequence>
CoordinateArraySequenceFactory::create() const
{
- return new CoordinateArraySequence(
- reinterpret_cast<std::vector<Coordinate>*>(0), 0);
+ return std::unique_ptr<CoordinateSequence>(
+ new CoordinateArraySequence(
+ reinterpret_cast<std::vector<Coordinate>*>(0), 0));
}
-INLINE CoordinateSequence*
+INLINE std::unique_ptr<CoordinateSequence>
CoordinateArraySequenceFactory::create(std::vector<Coordinate>* coords,
size_t dimension) const
{
- return new CoordinateArraySequence(coords, dimension);
+ return std::unique_ptr<CoordinateSequence>(
+ new CoordinateArraySequence(coords, dimension));
}
-INLINE CoordinateSequence*
+INLINE std::unique_ptr<CoordinateSequence>
CoordinateArraySequenceFactory::create(std::size_t size, std::size_t dimension)
const
{
- return new CoordinateArraySequence(size, dimension);
+ return std::unique_ptr<CoordinateSequence>(
+ new CoordinateArraySequence(size, dimension));
}
-INLINE CoordinateSequence*
+INLINE std::unique_ptr<CoordinateSequence>
CoordinateArraySequenceFactory::create(const CoordinateSequence& seq)
const
{
- return new CoordinateArraySequence(seq);
+ return std::unique_ptr<CoordinateSequence>(
+ new CoordinateArraySequence(seq));
}
diff --git a/include/geos/geom/CoordinateSequence.h b/include/geos/geom/CoordinateSequence.h
index f6fe861..f4c5764 100644
--- a/include/geos/geom/CoordinateSequence.h
+++ b/include/geos/geom/CoordinateSequence.h
@@ -73,7 +73,7 @@ public:
/** \brief
* Returns a deep copy of this collection.
*/
- virtual CoordinateSequence* clone() const = 0;
+ virtual std::unique_ptr<CoordinateSequence> clone() const = 0;
/** \brief
* Returns a read-only reference to Coordinate at position i.
diff --git a/include/geos/geom/CoordinateSequenceFactory.h b/include/geos/geom/CoordinateSequenceFactory.h
index 273e6a8..0cb5151 100644
--- a/include/geos/geom/CoordinateSequenceFactory.h
+++ b/include/geos/geom/CoordinateSequenceFactory.h
@@ -21,6 +21,7 @@
#include <geos/export.h>
+#include <memory>
#include <vector>
//#include <geos/geom/Coordinate.h>
@@ -51,7 +52,7 @@ public:
* Returns an empty CoordinateSequence, the dimensions will be autodetected
* when it is populated.
*/
- virtual CoordinateSequence* create() const = 0;
+ virtual std::unique_ptr<CoordinateSequence> create() const = 0;
/** \brief
* Returns a CoordinateSequence based on the given array.
@@ -68,7 +69,7 @@ public:
* @param coordinates the coordinates
* @param dimension 0, 2 or 3 with 0 indicating unknown at this time.
*/
- virtual CoordinateSequence* create(
+ virtual std::unique_ptr<CoordinateSequence> create(
std::vector<Coordinate>* coordinates,
std::size_t dimension = 0) const = 0;
@@ -82,8 +83,8 @@ public:
* @param dimension the dimension of the coordinates in the sequence
* (0=unknown, 2, or 3 - ignored if not user specifiable)
*/
- virtual CoordinateSequence* create(std::size_t size,
- std::size_t dimension = 0) const = 0;
+ virtual std::unique_ptr<CoordinateSequence> create(std::size_t size,
+ std::size_t dimension = 0) const = 0;
/** \brief
* Creates a CoordinateSequence which is a copy of the given one.
@@ -92,7 +93,7 @@ public:
*
* @param coordSeq the coordinate sequence to copy
*/
- virtual CoordinateSequence* create(const CoordinateSequence& coordSeq) const = 0;
+ virtual std::unique_ptr<CoordinateSequence> create(const CoordinateSequence& coordSeq) const = 0;
virtual ~CoordinateSequenceFactory();
};
diff --git a/include/geos/geom/Geometry.h b/include/geos/geom/Geometry.h
index 64a9967..10f223d 100644
--- a/include/geos/geom/Geometry.h
+++ b/include/geos/geom/Geometry.h
@@ -298,7 +298,7 @@ public:
* Returns this Geometry vertices.
* Caller takes ownership of the returned object.
*/
- virtual CoordinateSequence* getCoordinates() const = 0; //Abstract
+ virtual std::unique_ptr<CoordinateSequence> getCoordinates() const = 0; //Abstract
/// Returns the count of this Geometrys vertices.
virtual std::size_t getNumPoints() const = 0; //Abstract
diff --git a/include/geos/geom/GeometryCollection.h b/include/geos/geom/GeometryCollection.h
index 151997f..60acc7d 100644
--- a/include/geos/geom/GeometryCollection.h
+++ b/include/geos/geom/GeometryCollection.h
@@ -94,7 +94,7 @@ public:
* @return the collected coordinates
*
*/
- CoordinateSequence* getCoordinates() const override;
+ std::unique_ptr<CoordinateSequence> getCoordinates() const override;
bool isEmpty() const override;
diff --git a/include/geos/geom/LineString.h b/include/geos/geom/LineString.h
index 16a14ab..0352460 100644
--- a/include/geos/geom/LineString.h
+++ b/include/geos/geom/LineString.h
@@ -86,7 +86,7 @@ public:
*/
Geometry* clone() const override;
- CoordinateSequence* getCoordinates() const override;
+ std::unique_ptr<CoordinateSequence> getCoordinates() const override;
/// Returns a read-only pointer to internal CoordinateSequence
const CoordinateSequence* getCoordinatesRO() const;
diff --git a/include/geos/geom/LinearRing.h b/include/geos/geom/LinearRing.h
index 43b55d9..11cb494 100644
--- a/include/geos/geom/LinearRing.h
+++ b/include/geos/geom/LinearRing.h
@@ -106,7 +106,7 @@ public:
GeometryTypeId getGeometryTypeId() const override;
- void setPoints(CoordinateSequence* cl);
+ void setPoints(const CoordinateSequence* cl);
Geometry* reverse() const override;
diff --git a/include/geos/geom/Point.h b/include/geos/geom/Point.h
index 060cf6e..8d8741e 100644
--- a/include/geos/geom/Point.h
+++ b/include/geos/geom/Point.h
@@ -86,7 +86,7 @@ public:
return new Point(*this);
}
- CoordinateSequence* getCoordinates(void) const override;
+ std::unique_ptr<CoordinateSequence> getCoordinates(void) const override;
const CoordinateSequence* getCoordinatesRO() const;
diff --git a/include/geos/geom/Polygon.h b/include/geos/geom/Polygon.h
index dd85752..7c06522 100644
--- a/include/geos/geom/Polygon.h
+++ b/include/geos/geom/Polygon.h
@@ -85,7 +85,7 @@ public:
return new Polygon(*this);
}
- CoordinateSequence* getCoordinates() const override;
+ std::unique_ptr<CoordinateSequence> getCoordinates() const override;
size_t getNumPoints() const override;
diff --git a/include/geos/geomgraph/EdgeRing.h b/include/geos/geomgraph/EdgeRing.h
index b6a8bb0..d384f12 100644
--- a/include/geos/geomgraph/EdgeRing.h
+++ b/include/geos/geomgraph/EdgeRing.h
@@ -27,9 +27,10 @@
#include <geos/inline.h>
-#include <vector>
#include <cassert> // for testInvariant
#include <iosfwd> // for operator<<
+#include <memory>
+#include <vector>
#ifdef _MSC_VER
#pragma warning(push)
diff --git a/include/geos/io/WKBReader.h b/include/geos/io/WKBReader.h
index a12ca39..d507815 100644
--- a/include/geos/io/WKBReader.h
+++ b/include/geos/io/WKBReader.h
@@ -153,7 +153,7 @@ private:
geom::GeometryCollection* readGeometryCollection();
// throws IOException, ParseException
- geom::CoordinateSequence* readCoordinateSequence(int); // throws IOException
+ std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(int); // throws IOException
void readCoordinate(); // throws IOException
diff --git a/include/geos/io/WKTReader.h b/include/geos/io/WKTReader.h
index 1dfd4ff..4916995 100644
--- a/include/geos/io/WKTReader.h
+++ b/include/geos/io/WKTReader.h
@@ -86,7 +86,7 @@ public:
// Geometry* read(Reader& reader); //Not implemented yet
protected:
- geom::CoordinateSequence* getCoordinates(io::StringTokenizer* tokenizer);
+ std::unique_ptr<geom::CoordinateSequence> getCoordinates(io::StringTokenizer* tokenizer);
double getNextNumber(io::StringTokenizer* tokenizer);
std::string getNextEmptyOrOpener(io::StringTokenizer* tokenizer);
std::string getNextCloserOrComma(io::StringTokenizer* tokenizer);
diff --git a/include/geos/noding/SegmentStringUtil.h b/include/geos/noding/SegmentStringUtil.h
index 99f3297..a745817 100644
--- a/include/geos/noding/SegmentStringUtil.h
+++ b/include/geos/noding/SegmentStringUtil.h
@@ -60,9 +60,9 @@ public:
// we take ownership of the coordinates here
// TODO: check if this can be optimized by getting
// the internal CS.
- geom::CoordinateSequence* pts = line->getCoordinates();
+ auto pts = line->getCoordinates();
- segStr.push_back(new NodedSegmentString(pts, g));
+ segStr.push_back(new NodedSegmentString(pts.release(), g));
}
}
diff --git a/src/algorithm/ConvexHull.cpp b/src/algorithm/ConvexHull.cpp
index 0d8f650..d0e4573 100644
--- a/src/algorithm/ConvexHull.cpp
+++ b/src/algorithm/ConvexHull.cpp
@@ -99,7 +99,7 @@ public:
} // unnamed namespace
/* private */
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
ConvexHull::toCoordinateSequence(Coordinate::ConstVect& cv)
{
const CoordinateSequenceFactory* csf =
@@ -243,8 +243,8 @@ ConvexHull::getConvexHull()
if(nInputPts == 2) { // Return a LineString
// Copy all Coordinates from the ConstVect
- CoordinateSequence* cs = toCoordinateSequence(inputPts);
- return geomFactory->createLineString(cs);
+ auto cs = toCoordinateSequence(inputPts);
+ return geomFactory->createLineString(cs.release());
}
// use heuristic to reduce points, if large
@@ -352,12 +352,12 @@ ConvexHull::lineOrPolygon(const Coordinate::ConstVect& input)
if(cleaned.size() == 3) { // shouldn't this be 2 ??
cleaned.resize(2);
- CoordinateSequence* cl1 = toCoordinateSequence(cleaned);
- LineString* ret = geomFactory->createLineString(cl1);
+ auto cl1 = toCoordinateSequence(cleaned);
+ LineString* ret = geomFactory->createLineString(cl1.release());
return ret;
}
- CoordinateSequence* cl2 = toCoordinateSequence(cleaned);
- LinearRing* linearRing = geomFactory->createLinearRing(cl2);
+ auto cl2 = toCoordinateSequence(cleaned);
+ LinearRing* linearRing = geomFactory->createLinearRing(cl2.release());
return geomFactory->createPolygon(linearRing, nullptr);
}
diff --git a/src/algorithm/MinimumBoundingCircle.cpp b/src/algorithm/MinimumBoundingCircle.cpp
index bb3951c..57f6776 100644
--- a/src/algorithm/MinimumBoundingCircle.cpp
+++ b/src/algorithm/MinimumBoundingCircle.cpp
@@ -73,10 +73,10 @@ MinimumBoundingCircle::getFarthestPoints()
size_t dims = input->getDimension();
size_t len = 2;
- CoordinateSequence* cs = input->getFactory()->getCoordinateSequenceFactory()->create(len, dims);
+ auto cs = input->getFactory()->getCoordinateSequenceFactory()->create(len, dims);
cs->add(extremalPts[0], true);
cs->add(extremalPts[extremalPts.size() - 1], true);
- return input->getFactory()->createLineString(cs);
+ return input->getFactory()->createLineString(cs.release());
}
/*public*/
@@ -92,12 +92,12 @@ MinimumBoundingCircle::getDiameter()
}
size_t dims = input->getDimension();
size_t len = 2;
- CoordinateSequence* cs = input->getFactory()->getCoordinateSequenceFactory()->create(len, dims);
+ auto cs = input->getFactory()->getCoordinateSequenceFactory()->create(len, dims);
// TODO: handle case of 3 extremal points, by computing a line from one of
// them through the centre point with len = 2*radius
cs->add(extremalPts[0], true);
cs->add(extremalPts[1], true);
- return input->getFactory()->createLineString(cs);
+ return input->getFactory()->createLineString(cs.release());
}
/*public*/
diff --git a/src/algorithm/MinimumDiameter.cpp b/src/algorithm/MinimumDiameter.cpp
index 692da52..08eead9 100644
--- a/src/algorithm/MinimumDiameter.cpp
+++ b/src/algorithm/MinimumDiameter.cpp
@@ -101,7 +101,6 @@ MinimumDiameter::~MinimumDiameter()
{
delete minBaseSeg;
delete minWidthPt;
- delete convexHullPts;
}
/**
@@ -138,10 +137,10 @@ MinimumDiameter::getSupportingSegment()
{
computeMinimumDiameter();
const GeometryFactory* fact = inputGeom->getFactory();
- CoordinateSequence* cl = fact->getCoordinateSequenceFactory()->create();
+ auto cl = fact->getCoordinateSequenceFactory()->create();
cl->add(minBaseSeg->p0);
cl->add(minBaseSeg->p1);
- return fact->createLineString(cl);
+ return fact->createLineString(cl.release());
}
/**
@@ -161,10 +160,10 @@ MinimumDiameter::getDiameter()
Coordinate basePt;
minBaseSeg->project(*minWidthPt, basePt);
- CoordinateSequence* cl = inputGeom->getFactory()->getCoordinateSequenceFactory()->create();
+ auto cl = inputGeom->getFactory()->getCoordinateSequenceFactory()->create();
cl->add(basePt);
cl->add(*minWidthPt);
- return inputGeom->getFactory()->createLineString(cl);
+ return inputGeom->getFactory()->createLineString(cl.release());
}
/* private */
@@ -191,7 +190,6 @@ void
MinimumDiameter::computeWidthConvex(const Geometry* geom)
{
//System.out.println("Input = " + geom);
- delete convexHullPts;
if(typeid(*geom) == typeid(Polygon)) {
const Polygon* p = dynamic_cast<const Polygon*>(geom);
convexHullPts = p->getExteriorRing()->getCoordinates();
@@ -225,7 +223,7 @@ MinimumDiameter::computeWidthConvex(const Geometry* geom)
minBaseSeg->p1 = convexHullPts->getAt(1);
break;
default:
- computeConvexRingMinDiameter(convexHullPts);
+ computeConvexRingMinDiameter(convexHullPts.get());
}
}
@@ -355,14 +353,14 @@ MinimumDiameter::getMinimumRectangle()
const CoordinateSequenceFactory* csf =
inputGeom->getFactory()->getCoordinateSequenceFactory();
- geom::CoordinateSequence* seq = csf->create(5, 2);
+ auto seq = csf->create(5, 2);
seq->setAt(p0, 0);
seq->setAt(p1, 1);
seq->setAt(p2, 2);
seq->setAt(p3, 3);
seq->setAt(p0, 4); // close
- LinearRing* shell = inputGeom->getFactory()->createLinearRing(seq);
+ LinearRing* shell = inputGeom->getFactory()->createLinearRing(seq.release());
return inputGeom->getFactory()->createPolygon(shell, nullptr);
}
diff --git a/src/algorithm/distance/DiscreteFrechetDistance.cpp b/src/algorithm/distance/DiscreteFrechetDistance.cpp
index 408d858..b41225f 100644
--- a/src/algorithm/distance/DiscreteFrechetDistance.cpp
+++ b/src/algorithm/distance/DiscreteFrechetDistance.cpp
@@ -120,8 +120,8 @@ DiscreteFrechetDistance::compute(
const geom::Geometry& discreteGeom,
const geom::Geometry& geom)
{
- const CoordinateSequence* lp = discreteGeom.getCoordinates();
- const CoordinateSequence* lq = geom.getCoordinates();
+ auto lp = discreteGeom.getCoordinates();
+ auto lq = geom.getCoordinates();
size_t pSize, qSize;
if(densifyFrac > 0) {
size_t numSubSegs = std::size_t(util::round(1.0 / densifyFrac));
@@ -139,8 +139,6 @@ DiscreteFrechetDistance::compute(
}
}
ptDist = getFrecheDistance(ca, pSize - 1, qSize - 1, *lp, *lq);
- delete lp;
- delete lq;
}
} // namespace geos.algorithm.distance
diff --git a/src/geom/CoordinateArraySequence.cpp b/src/geom/CoordinateArraySequence.cpp
index e954d74..f30735f 100644
--- a/src/geom/CoordinateArraySequence.cpp
+++ b/src/geom/CoordinateArraySequence.cpp
@@ -73,10 +73,10 @@ CoordinateArraySequence::CoordinateArraySequence(
}
}
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
CoordinateArraySequence::clone() const
{
- return new CoordinateArraySequence(*this);
+ return std::unique_ptr<CoordinateSequence>(new CoordinateArraySequence(*this));
}
void
diff --git a/src/geom/CoordinateSequence.cpp b/src/geom/CoordinateSequence.cpp
index 38bb77c..847d347 100644
--- a/src/geom/CoordinateSequence.cpp
+++ b/src/geom/CoordinateSequence.cpp
@@ -60,7 +60,7 @@ CoordinateSequence::atLeastNCoordinatesOrNothing(size_t n,
}
else {
// FIXME: return NULL rather then empty coordinate array
- return CoordinateArraySequenceFactory::instance()->create();
+ return CoordinateArraySequenceFactory::instance()->create().release();
}
}
diff --git a/src/geom/GeometryCollection.cpp b/src/geom/GeometryCollection.cpp
index 8b03c4f..a026cad 100644
--- a/src/geom/GeometryCollection.cpp
+++ b/src/geom/GeometryCollection.cpp
@@ -90,20 +90,19 @@ GeometryCollection::setSRID(int newSRID)
* Returns a newly the collected coordinates
*
*/
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
GeometryCollection::getCoordinates() const
{
vector<Coordinate>* coordinates = new vector<Coordinate>(getNumPoints());
int k = -1;
for(size_t i = 0; i < geometries->size(); ++i) {
- CoordinateSequence* childCoordinates = (*geometries)[i]->getCoordinates();
+ auto childCoordinates = (*geometries)[i]->getCoordinates();
size_t npts = childCoordinates->getSize();
for(size_t j = 0; j < npts; ++j) {
k++;
(*coordinates)[k] = childCoordinates->getAt(j);
}
- delete childCoordinates;
}
return CoordinateArraySequenceFactory::instance()->create(coordinates);
}
diff --git a/src/geom/GeometryFactory.cpp b/src/geom/GeometryFactory.cpp
index d62f10b..47bc368 100644
--- a/src/geom/GeometryFactory.cpp
+++ b/src/geom/GeometryFactory.cpp
@@ -72,7 +72,7 @@ public:
edit(const CoordinateSequence* coordSeq,
const Geometry*) override
{
- return _gsf->create(*coordSeq);
+ return _gsf->create(*coordSeq).release();
}
};
@@ -277,7 +277,7 @@ GeometryFactory::toGeometry(const Envelope* envelope) const
coord.y = envelope->getMinY();
return createPoint(coord);
}
- CoordinateSequence* cl = CoordinateArraySequenceFactory::instance()->
+ auto cl = CoordinateArraySequenceFactory::instance()->
create((size_t) 0, 2);
coord.x = envelope->getMinX();
coord.y = envelope->getMinY();
@@ -295,7 +295,7 @@ GeometryFactory::toGeometry(const Envelope* envelope) const
coord.y = envelope->getMinY();
cl->add(coord);
- Polygon* p = createPolygon(createLinearRing(cl), nullptr);
+ Polygon* p = createPolygon(createLinearRing(cl.release()), nullptr);
return p;
}
@@ -322,9 +322,9 @@ GeometryFactory::createPoint(const Coordinate& coordinate) const
}
else {
std::size_t dim = std::isnan(coordinate.z) ? 2 : 3;
- CoordinateSequence* cl = coordinateListFactory->create(new vector<Coordinate>(1, coordinate), dim);
+ auto cl = coordinateListFactory->create(new vector<Coordinate>(1, coordinate), dim);
//cl->setAt(coordinate, 0);
- Point* ret = createPoint(cl);
+ Point* ret = createPoint(cl.release());
return ret;
}
}
@@ -340,16 +340,8 @@ GeometryFactory::createPoint(CoordinateSequence* newCoords) const
Point*
GeometryFactory::createPoint(const CoordinateSequence& fromCoords) const
{
- CoordinateSequence* newCoords = fromCoords.clone();
- Point* g = nullptr;
- try {
- g = new Point(newCoords, this);
- }
- catch(...) {
- delete newCoords;
- throw;
- }
- return g;
+ auto newCoords = fromCoords.clone();
+ return new Point(newCoords.release(), this);
}
@@ -499,10 +491,10 @@ GeometryFactory::createLinearRing(CoordinateSequence::Ptr newCoords) const
LinearRing*
GeometryFactory::createLinearRing(const CoordinateSequence& fromCoords) const
{
- CoordinateSequence* newCoords = fromCoords.clone();
+ auto newCoords = fromCoords.clone();
LinearRing* g = nullptr;
// construction failure will delete newCoords
- g = new LinearRing(newCoords, this);
+ g = new LinearRing(newCoords.release(), this);
return g;
}
@@ -668,10 +660,10 @@ LineString*
GeometryFactory::createLineString(const CoordinateSequence& fromCoords)
const
{
- CoordinateSequence* newCoords = fromCoords.clone();
+ auto newCoords = fromCoords.clone();
LineString* g = nullptr;
// construction failure will delete newCoords
- g = new LineString(newCoords, this);
+ g = new LineString(newCoords.release(), this);
return g;
}
diff --git a/src/geom/LineString.cpp b/src/geom/LineString.cpp
index 161facf..6141728 100644
--- a/src/geom/LineString.cpp
+++ b/src/geom/LineString.cpp
@@ -62,10 +62,10 @@ LineString::reverse() const
}
assert(points.get());
- CoordinateSequence* seq = points->clone();
- CoordinateSequence::reverse(seq);
+ auto seq = points->clone();
+ CoordinateSequence::reverse(seq.get());
assert(getFactory());
- return getFactory()->createLineString(seq);
+ return getFactory()->createLineString(seq.release());
}
@@ -74,7 +74,7 @@ void
LineString::validateConstruction()
{
if(points.get() == nullptr) {
- points.reset(getFactory()->getCoordinateSequenceFactory()->create());
+ points = getFactory()->getCoordinateSequenceFactory()->create();
return;
}
@@ -109,7 +109,7 @@ LineString::~LineString()
//delete points;
}
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
LineString::getCoordinates() const
{
assert(points.get());
diff --git a/src/geom/LinearRing.cpp b/src/geom/LinearRing.cpp
index af022fe..b6fe05a 100644
--- a/src/geom/LinearRing.cpp
+++ b/src/geom/LinearRing.cpp
@@ -109,7 +109,7 @@ LinearRing::getGeometryType() const
}
void
-LinearRing::setPoints(CoordinateSequence* cl)
+LinearRing::setPoints(const CoordinateSequence* cl)
{
const vector<Coordinate>* v = cl->toVector();
points->setPoints(*(v));
@@ -130,10 +130,10 @@ LinearRing::reverse() const
}
assert(points.get());
- CoordinateSequence* seq = points->clone();
- CoordinateSequence::reverse(seq);
+ auto seq = points->clone();
+ CoordinateSequence::reverse(seq.get());
assert(getFactory());
- return getFactory()->createLinearRing(seq);
+ return getFactory()->createLinearRing(seq.release());
}
} // namespace geos::geom
diff --git a/src/geom/Point.cpp b/src/geom/Point.cpp
index f9071ab..1d4928c 100644
--- a/src/geom/Point.cpp
+++ b/src/geom/Point.cpp
@@ -49,7 +49,7 @@ Point::Point(CoordinateSequence* newCoords, const GeometryFactory* factory)
coordinates(newCoords)
{
if(coordinates.get() == nullptr) {
- coordinates.reset(factory->getCoordinateSequenceFactory()->create());
+ coordinates = factory->getCoordinateSequenceFactory()->create();
return;
}
if(coordinates->getSize() != 1) {
@@ -65,7 +65,7 @@ Point::Point(const Point& p)
{
}
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
Point::getCoordinates() const
{
return coordinates->clone();
diff --git a/src/geom/Polygon.cpp b/src/geom/Polygon.cpp
index 737d316..abf156f 100644
--- a/src/geom/Polygon.cpp
+++ b/src/geom/Polygon.cpp
@@ -98,7 +98,7 @@ Polygon::Polygon(LinearRing* newShell, vector<Geometry*>* newHoles,
}
}
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
Polygon::getCoordinates() const
{
if(isEmpty()) {
@@ -331,16 +331,15 @@ Polygon::normalize(LinearRing* ring, bool clockwise)
if(ring->isEmpty()) {
return;
}
- CoordinateSequence* uniqueCoordinates = ring->getCoordinates();
+ auto uniqueCoordinates = ring->getCoordinates();
uniqueCoordinates->deleteAt(uniqueCoordinates->getSize() - 1);
- const Coordinate* minCoordinate = CoordinateSequence::minCoordinate(uniqueCoordinates);
- CoordinateSequence::scroll(uniqueCoordinates, minCoordinate);
+ const Coordinate* minCoordinate = CoordinateSequence::minCoordinate(uniqueCoordinates.get());
+ CoordinateSequence::scroll(uniqueCoordinates.get(), minCoordinate);
uniqueCoordinates->add(uniqueCoordinates->getAt(0));
- if(algorithm::Orientation::isCCW(uniqueCoordinates) == clockwise) {
- CoordinateSequence::reverse(uniqueCoordinates);
+ if(algorithm::Orientation::isCCW(uniqueCoordinates.get()) == clockwise) {
+ CoordinateSequence::reverse(uniqueCoordinates.get());
}
- ring->setPoints(uniqueCoordinates);
- delete(uniqueCoordinates);
+ ring->setPoints(uniqueCoordinates.get());
}
const Coordinate*
diff --git a/src/geom/util/CoordinateOperation.cpp b/src/geom/util/CoordinateOperation.cpp
index 367da52..d2d85cd 100644
--- a/src/geom/util/CoordinateOperation.cpp
+++ b/src/geom/util/CoordinateOperation.cpp
@@ -44,9 +44,8 @@ CoordinateOperation::edit(const Geometry* geometry,
return factory->createLineString(newCoords);
}
if(typeid(*geometry) == typeid(Point)) {
- CoordinateSequence* coords = geometry->getCoordinates();
- CoordinateSequence* newCoords = edit(coords, geometry);
- delete coords;
+ auto coords = geometry->getCoordinates();
+ CoordinateSequence* newCoords = edit(coords.get(), geometry);
return factory->createPoint(newCoords);
}
diff --git a/src/geomgraph/EdgeNodingValidator.cpp b/src/geomgraph/EdgeNodingValidator.cpp
index 246f3a0..b16a2d9 100644
--- a/src/geomgraph/EdgeNodingValidator.cpp
+++ b/src/geomgraph/EdgeNodingValidator.cpp
@@ -37,9 +37,9 @@ EdgeNodingValidator::toSegmentStrings(vector<Edge*>& edges)
// convert Edges to SegmentStrings
for(size_t i = 0, n = edges.size(); i < n; ++i) {
Edge* e = edges[i];
- CoordinateSequence* cs = e->getCoordinates()->clone();
- newCoordSeq.push_back(cs);
- segStr.push_back(new BasicSegmentString(cs, e));
+ auto cs = e->getCoordinates()->clone();
+ segStr.push_back(new BasicSegmentString(cs.get(), e));
+ newCoordSeq.push_back(cs.release());
}
return segStr;
}
diff --git a/src/geomgraph/EdgeRing.cpp b/src/geomgraph/EdgeRing.cpp
index 61a80cd..ec6b816 100644
--- a/src/geomgraph/EdgeRing.cpp
+++ b/src/geomgraph/EdgeRing.cpp
@@ -55,7 +55,7 @@ EdgeRing::EdgeRing(DirectedEdge* newStart,
holes(),
maxNodeDegree(-1),
edges(),
- pts(newGeometryFactory->getCoordinateSequenceFactory()->create()),
+ pts(newGeometryFactory->getCoordinateSequenceFactory()->create().release()),
label(Location::UNDEF), // new Label(Location::UNDEF)),
ring(nullptr),
isHoleVar(false),
@@ -77,16 +77,7 @@ EdgeRing::~EdgeRing()
{
testInvariant();
- /*
- * If we constructed a ring, we did by transferring
- * ownership of the CoordinateSequence, so it will be
- * destroyed by `ring' dtor and we must not destroy
- * it twice.
- */
- if(ring == nullptr) {
- delete pts;
- }
- else {
+ if(ring != nullptr) {
delete ring;
}
@@ -200,7 +191,6 @@ EdgeRing::computeRing()
isHoleVar = Orientation::isCCW(pts);
testInvariant();
-
}
/*public*/
diff --git a/src/io/WKBReader.cpp b/src/io/WKBReader.cpp
index 99e2cec..4b04b6d 100644
--- a/src/io/WKBReader.cpp
+++ b/src/io/WKBReader.cpp
@@ -290,8 +290,8 @@ WKBReader::readLineString()
#if DEBUG_WKB_READER
cout << "WKB npoints: " << size << endl;
#endif
- CoordinateSequence* pts = readCoordinateSequence(size);
- return factory.createLineString(pts);
+ auto pts = readCoordinateSequence(size);
+ return factory.createLineString(pts.release());
}
LinearRing*
@@ -301,8 +301,8 @@ WKBReader::readLinearRing()
#if DEBUG_WKB_READER
cout << "WKB npoints: " << size << endl;
#endif
- CoordinateSequence* pts = readCoordinateSequence(size);
- return factory.createLinearRing(pts);
+ auto pts = readCoordinateSequence(size);
+ return factory.createLinearRing(pts.release());
}
Polygon*
@@ -441,10 +441,10 @@ WKBReader::readGeometryCollection()
return factory.createGeometryCollection(geoms);
}
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
WKBReader::readCoordinateSequence(int size)
{
- CoordinateSequence* seq = factory.getCoordinateSequenceFactory()->create(size, inputDimension);
+ auto seq = factory.getCoordinateSequenceFactory()->create(size, inputDimension);
auto targetDim = seq->getDimension();
if(targetDim > inputDimension) {
targetDim = inputDimension;
diff --git a/src/io/WKTReader.cpp b/src/io/WKTReader.cpp
index 4c77ef0..b1c64fb 100644
--- a/src/io/WKTReader.cpp
+++ b/src/io/WKTReader.cpp
@@ -68,7 +68,7 @@ WKTReader::read(const string& wellKnownText)
return g;
}
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
WKTReader::getCoordinates(StringTokenizer* tokenizer)
{
size_t dim;
@@ -81,20 +81,14 @@ WKTReader::getCoordinates(StringTokenizer* tokenizer)
Coordinate coord;
getPreciseCoordinate(tokenizer, coord, dim);
- CoordinateSequence* coordinates = \
- geometryFactory->getCoordinateSequenceFactory()->create((size_t)0, dim);
+ auto coordinates = geometryFactory->getCoordinateSequenceFactory()->create((size_t)0, dim);
coordinates->add(coord);
- try {
+
+ nextToken = getNextCloserOrComma(tokenizer);
+ while(nextToken == ",") {
+ getPreciseCoordinate(tokenizer, coord, dim);
+ coordinates->add(coord);
nextToken = getNextCloserOrComma(tokenizer);
- while(nextToken == ",") {
- getPreciseCoordinate(tokenizer, coord, dim);
- coordinates->add(coord);
- nextToken = getNextCloserOrComma(tokenizer);
- }
- }
- catch(...) {
- delete coordinates;
- throw;
}
return coordinates;
@@ -273,17 +267,17 @@ WKTReader::readPointText(StringTokenizer* tokenizer)
LineString*
WKTReader::readLineStringText(StringTokenizer* tokenizer)
{
- CoordinateSequence* coords = getCoordinates(tokenizer);
- LineString* ret = geometryFactory->createLineString(coords);
+ auto coords = getCoordinates(tokenizer);
+ LineString* ret = geometryFactory->createLineString(coords.release());
return ret;
}
LinearRing*
WKTReader::readLinearRingText(StringTokenizer* tokenizer)
{
- CoordinateSequence* coords = getCoordinates(tokenizer);
+ auto coords = getCoordinates(tokenizer);
LinearRing* ret;
- ret = geometryFactory->createLinearRing(coords);
+ ret = geometryFactory->createLinearRing(coords.release());
return ret;
}
@@ -303,24 +297,18 @@ WKTReader::readMultiPointText(StringTokenizer* tokenizer)
// Try to parse deprecated form "MULTIPOINT(0 0, 1 1)"
const CoordinateSequenceFactory* csf = \
geometryFactory->getCoordinateSequenceFactory();
- CoordinateSequence* coords = csf->create();
- try {
- do {
- Coordinate coord;
- getPreciseCoordinate(tokenizer, coord, dim);
- coords->add(coord);
- nextToken = getNextCloserOrComma(tokenizer);
- }
- while(nextToken == ",");
+ auto coords = csf->create();
- MultiPoint* ret = geometryFactory->createMultiPoint(*coords);
- delete coords;
- return ret;
- }
- catch(...) {
- delete coords;
- throw;
+ do {
+ Coordinate coord;
+ getPreciseCoordinate(tokenizer, coord, dim);
+ coords->add(coord);
+ nextToken = getNextCloserOrComma(tokenizer);
}
+ while(nextToken == ",");
+
+ MultiPoint* ret = geometryFactory->createMultiPoint(*coords);
+ return ret;
}
else if(tok == '(') {
diff --git a/src/linearref/ExtractLineByLocation.cpp b/src/linearref/ExtractLineByLocation.cpp
index 2da4548..3ccff62 100644
--- a/src/linearref/ExtractLineByLocation.cpp
+++ b/src/linearref/ExtractLineByLocation.cpp
@@ -84,7 +84,7 @@ ExtractLineByLocation::reverse(const Geometry* linear)
LineString*
ExtractLineByLocation::computeLine(const LinearLocation& start, const LinearLocation& end)
{
- CoordinateSequence* coordinates = line->getCoordinates();
+ auto coordinates = line->getCoordinates();
CoordinateArraySequence newCoordinateArray;
const size_t indexStep = 1;
diff --git a/src/noding/GeometryNoder.cpp b/src/noding/GeometryNoder.cpp
index 4101a0d..8a4bf13 100644
--- a/src/noding/GeometryNoder.cpp
+++ b/src/noding/GeometryNoder.cpp
@@ -58,9 +58,9 @@ public:
{
const geom::LineString* ls = dynamic_cast<const geom::LineString*>(g);
if(ls) {
- geom::CoordinateSequence* coord = ls->getCoordinates();
+ auto coord = ls->getCoordinates();
// coord ownership transferred to SegmentString
- SegmentString* ss = new NodedSegmentString(coord, nullptr);
+ SegmentString* ss = new NodedSegmentString(coord.release(), nullptr);
_to.push_back(ss);
}
}
@@ -106,7 +106,7 @@ GeometryNoder::toGeometry(SegmentString::NonConstVect& nodedEdges)
// Check if an equivalent edge is known
OrientedCoordinateArray oca1(*coords);
if(ocas.insert(oca1).second) {
- geom::Geometry* tmp = geomFact->createLineString(coords->clone());
+ geom::Geometry* tmp = geomFact->createLineString(coords->clone().release());
lines->push_back(tmp);
}
}
diff --git a/src/operation/buffer/BufferBuilder.cpp b/src/operation/buffer/BufferBuilder.cpp
index 5211d68..b6e6267 100644
--- a/src/operation/buffer/BufferBuilder.cpp
+++ b/src/operation/buffer/BufferBuilder.cpp
@@ -88,7 +88,7 @@ convertSegStrings(const GeometryFactory* fact, Iterator it, Iterator et)
std::vector<Geometry*> lines;
while(it != et) {
const SegmentString* ss = *it;
- LineString* line = fact->createLineString(ss->getCoordinates()->clone());
+ LineString* line = fact->createLineString(ss->getCoordinates()->clone().release());
lines.push_back(line);
++it;
}
@@ -213,7 +213,7 @@ BufferBuilder::bufferLineSingleSided(const Geometry* g, double distance,
SegmentString* ss = (*nodedEdges)[i];
Geometry* tmp = geomFact->createLineString(
- ss->getCoordinates()->clone()
+ ss->getCoordinates()->clone().release()
);
delete ss;
diff --git a/src/operation/buffer/OffsetCurveBuilder.cpp b/src/operation/buffer/OffsetCurveBuilder.cpp
index e377417..83baadc 100644
--- a/src/operation/buffer/OffsetCurveBuilder.cpp
+++ b/src/operation/buffer/OffsetCurveBuilder.cpp
@@ -178,7 +178,7 @@ OffsetCurveBuilder::getRingCurve(const CoordinateSequence* inputPts,
// optimize creating ring for zero distance
if(distance == 0.0) {
- lineList.push_back(inputPts->clone());
+ lineList.push_back(inputPts->clone().release());
return;
}
diff --git a/src/operation/intersection/Rectangle.cpp b/src/operation/intersection/Rectangle.cpp
index ebc7c04..9ba1ac5 100644
--- a/src/operation/intersection/Rectangle.cpp
+++ b/src/operation/intersection/Rectangle.cpp
@@ -50,13 +50,13 @@ geom::LinearRing*
Rectangle::toLinearRing(const geom::GeometryFactory& f) const
{
const geom::CoordinateSequenceFactory* csf = f.getCoordinateSequenceFactory();
- geom::CoordinateSequence* seq = csf->create(5, 2);
+ auto seq = csf->create(5, 2);
seq->setAt(geom::Coordinate(xMin, yMin), 0);
seq->setAt(geom::Coordinate(xMin, yMax), 1);
seq->setAt(geom::Coordinate(xMax, yMax), 2);
seq->setAt(geom::Coordinate(xMax, yMin), 3);
seq->setAt(seq->getAt(0), 4); // close
- return f.createLinearRing(seq);
+ return f.createLinearRing(seq.release());
}
} // namespace geos::operation::intersection
diff --git a/src/operation/intersection/RectangleIntersection.cpp b/src/operation/intersection/RectangleIntersection.cpp
index e9a84e1..bb16564 100644
--- a/src/operation/intersection/RectangleIntersection.cpp
+++ b/src/operation/intersection/RectangleIntersection.cpp
@@ -231,8 +231,8 @@ RectangleIntersection::clip_linestring_parts(const geom::LineString* gi,
std::vector<Coordinate>* coords = new std::vector<Coordinate>(2);
(*coords)[0] = Coordinate(x0, y0);
(*coords)[1] = Coordinate(x, y);
- CoordinateSequence* seq = _csf->create(coords);
- geom::LineString* line = _gf->createLineString(seq);
+ auto seq = _csf->create(coords);
+ geom::LineString* line = _gf->createLineString(seq.release());
parts.add(line);
}
@@ -302,8 +302,8 @@ RectangleIntersection::clip_linestring_parts(const geom::LineString* gi,
coords->push_back(Coordinate(x, y));
}
- CoordinateSequence* seq = _csf->create(coords);
- geom::LineString* line = _gf->createLineString(seq);
+ auto seq = _csf->create(coords);
+ geom::LineString* line = _gf->createLineString(seq.release());
parts.add(line);
}
// And continue main loop on the outside
@@ -323,8 +323,8 @@ RectangleIntersection::clip_linestring_parts(const geom::LineString* gi,
//line->addSubLineString(&g, start_index, i-1);
coords->insert(coords->end(), cs.begin() + start_index, cs.begin() + i);
- CoordinateSequence* seq = _csf->create(coords);
- geom::LineString* line = _gf->createLineString(seq);
+ auto seq = _csf->create(coords);
+ geom::LineString* line = _gf->createLineString(seq.release());
parts.add(line);
}
start_index = i;
@@ -356,8 +356,8 @@ RectangleIntersection::clip_linestring_parts(const geom::LineString* gi,
//line->addSubLineString(&g, start_index, i-1);
coords->insert(coords->end(), cs.begin() + start_index, cs.begin() + i);
- CoordinateSequence* seq = _csf->create(coords);
- geom::LineString* line = _gf->createLineString(seq);
+ auto seq = _csf->create(coords);
+ geom::LineString* line = _gf->createLineString(seq.release());
parts.add(line);
}
diff --git a/src/operation/intersection/RectangleIntersectionBuilder.cpp b/src/operation/intersection/RectangleIntersectionBuilder.cpp
index c0bd960..a95488f 100644
--- a/src/operation/intersection/RectangleIntersectionBuilder.cpp
+++ b/src/operation/intersection/RectangleIntersectionBuilder.cpp
@@ -451,8 +451,8 @@ RectangleIntersectionBuilder::reconnectPolygons(const Rectangle& rect)
if(best_distance < 0 || own_distance < best_distance) {
close_ring(rect, ring);
normalize_ring(*ring);
- geom::CoordinateSequence* shell_cs = _csf.create(ring);
- geom::LinearRing* shell = _gf.createLinearRing(shell_cs);
+ auto shell_cs = _csf.create(ring);
+ geom::LinearRing* shell = _gf.createLinearRing(shell_cs.release());
exterior.push_back(make_pair(shell, new LinearRingVect()));
ring = nullptr;
}
diff --git a/src/operation/linemerge/EdgeString.cpp b/src/operation/linemerge/EdgeString.cpp
index 65123b0..9a23590 100644
--- a/src/operation/linemerge/EdgeString.cpp
+++ b/src/operation/linemerge/EdgeString.cpp
@@ -66,7 +66,7 @@ EdgeString::getCoordinates()
if(coordinates == nullptr) {
int forwardDirectedEdges = 0;
int reverseDirectedEdges = 0;
- coordinates = factory->getCoordinateSequenceFactory()->create();
+ coordinates = factory->getCoordinateSequenceFactory()->create().release();
for(std::size_t i = 0, e = directedEdges.size(); i < e; ++i) {
LineMergeDirectedEdge* directedEdge = directedEdges[i];
if(directedEdge->getEdgeDirection()) {
diff --git a/src/operation/linemerge/LineSequencer.cpp b/src/operation/linemerge/LineSequencer.cpp
index 9827d1d..1c441f2 100644
--- a/src/operation/linemerge/LineSequencer.cpp
+++ b/src/operation/linemerge/LineSequencer.cpp
@@ -241,9 +241,9 @@ LineSequencer::buildSequencedGeometry(const Sequences& sequences)
LineString*
LineSequencer::reverse(const LineString* line)
{
- CoordinateSequence* cs = line->getCoordinates();
- CoordinateSequence::reverse(cs);
- return line->getFactory()->createLineString(cs);
+ auto cs = line->getCoordinates();
+ CoordinateSequence::reverse(cs.get());
+ return line->getFactory()->createLineString(cs.release());
}
/*private static*/
diff --git a/src/operation/overlay/LineBuilder.cpp b/src/operation/overlay/LineBuilder.cpp
index 4312cf7..99512fd 100644
--- a/src/operation/overlay/LineBuilder.cpp
+++ b/src/operation/overlay/LineBuilder.cpp
@@ -192,11 +192,11 @@ LineBuilder::buildLines(OverlayOp::OpCode /* opCode */)
{
for(size_t i = 0, s = lineEdgesList.size(); i < s; ++i) {
Edge* e = lineEdgesList[i];
- CoordinateSequence* cs = e->getCoordinates()->clone();
+ auto cs = e->getCoordinates()->clone();
#if COMPUTE_Z
- propagateZ(cs);
+ propagateZ(cs.get());
#endif
- LineString* line = geometryFactory->createLineString(cs);
+ LineString* line = geometryFactory->createLineString(cs.release());
resultLineList->push_back(line);
e->setInResult(true);
}
diff --git a/src/operation/polygonize/EdgeRing.cpp b/src/operation/polygonize/EdgeRing.cpp
index 730f594..511639d 100644
--- a/src/operation/polygonize/EdgeRing.cpp
+++ b/src/operation/polygonize/EdgeRing.cpp
@@ -221,7 +221,7 @@ const CoordinateSequence*
EdgeRing::getCoordinates()
{
if(ringPts == nullptr) {
- ringPts.reset(factory->getCoordinateSequenceFactory()->create());
+ ringPts = factory->getCoordinateSequenceFactory()->create();
for(const auto& de : deList) {
auto edge = dynamic_cast<PolygonizeEdge*>(de->getEdge());
addEdge(edge->getLine()->getCoordinatesRO(),
diff --git a/src/operation/valid/RepeatedPointTester.cpp b/src/operation/valid/RepeatedPointTester.cpp
index 7947fc0..fcb047d 100644
--- a/src/operation/valid/RepeatedPointTester.cpp
+++ b/src/operation/valid/RepeatedPointTester.cpp
@@ -97,12 +97,12 @@ RepeatedPointTester::hasRepeatedPoint(const CoordinateSequence* coord)
bool
RepeatedPointTester::hasRepeatedPoint(const Polygon* p)
{
- if(hasRepeatedPoint(p->getExteriorRing()->getCoordinates())) {
+ if(hasRepeatedPoint(p->getExteriorRing()->getCoordinatesRO())) {
return true;
}
for(size_t i = 0, n = p->getNumInteriorRing(); i < n; ++i) {
- if(hasRepeatedPoint(p->getInteriorRingN(i)->getCoordinates())) {
+ if(hasRepeatedPoint(p->getInteriorRingN(i)->getCoordinatesRO())) {
return true;
}
}
diff --git a/src/operation/valid/SimpleNestedRingTester.cpp b/src/operation/valid/SimpleNestedRingTester.cpp
index 06e22e3..9d63d21 100644
--- a/src/operation/valid/SimpleNestedRingTester.cpp
+++ b/src/operation/valid/SimpleNestedRingTester.cpp
@@ -37,10 +37,10 @@ SimpleNestedRingTester::isNonNested()
{
for(size_t i = 0, ni = rings.size(); i < ni; i++) {
LinearRing* innerRing = rings[i];
- CoordinateSequence* innerRingPts = innerRing->getCoordinates();
+ const CoordinateSequence* innerRingPts = innerRing->getCoordinatesRO();
for(size_t j = 0, nj = rings.size(); j < nj; j++) {
LinearRing* searchRing = rings[j];
- CoordinateSequence* searchRingPts = searchRing->getCoordinates();
+ const CoordinateSequence* searchRingPts = searchRing->getCoordinatesRO();
if(innerRing == searchRing) {
continue;
}
diff --git a/src/operation/valid/SweeplineNestedRingTester.cpp b/src/operation/valid/SweeplineNestedRingTester.cpp
index 33a6157..d7bb59c 100644
--- a/src/operation/valid/SweeplineNestedRingTester.cpp
+++ b/src/operation/valid/SweeplineNestedRingTester.cpp
@@ -78,8 +78,8 @@ SweeplineNestedRingTester::buildIndex()
bool
SweeplineNestedRingTester::isInside(LinearRing* innerRing, LinearRing* searchRing)
{
- CoordinateSequence* innerRingPts = innerRing->getCoordinates();
- CoordinateSequence* searchRingPts = searchRing->getCoordinates();
+ const CoordinateSequence* innerRingPts = innerRing->getCoordinatesRO();
+ const CoordinateSequence* searchRingPts = searchRing->getCoordinatesRO();
if(!innerRing->getEnvelopeInternal()->intersects(searchRing->getEnvelopeInternal())) {
return false;
diff --git a/src/precision/MinimumClearance.cpp b/src/precision/MinimumClearance.cpp
index 0553a3c..45ac34f 100644
--- a/src/precision/MinimumClearance.cpp
+++ b/src/precision/MinimumClearance.cpp
@@ -51,7 +51,7 @@ MinimumClearance::getLine()
return std::unique_ptr<LineString>(inputGeom->getFactory()->createLineString());
}
- return std::unique_ptr<LineString>(inputGeom->getFactory()->createLineString(minClearancePts->clone()));
+ return std::unique_ptr<LineString>(inputGeom->getFactory()->createLineString(minClearancePts->clone().release()));
}
void
diff --git a/src/precision/PrecisionReducerCoordinateOperation.cpp b/src/precision/PrecisionReducerCoordinateOperation.cpp
index d2b5099..2c710ff 100644
--- a/src/precision/PrecisionReducerCoordinateOperation.cpp
+++ b/src/precision/PrecisionReducerCoordinateOperation.cpp
@@ -55,7 +55,7 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
// reducedCoords take ownership of 'vc'
CoordinateSequence* reducedCoords =
- geom->getFactory()->getCoordinateSequenceFactory()->create(vc);
+ geom->getFactory()->getCoordinateSequenceFactory()->create(vc).release();
// remove repeated points, to simplify returned geometry as
// much as possible.
diff --git a/src/precision/SimpleGeometryPrecisionReducer.cpp b/src/precision/SimpleGeometryPrecisionReducer.cpp
index 04a91d3..3be653b 100644
--- a/src/precision/SimpleGeometryPrecisionReducer.cpp
+++ b/src/precision/SimpleGeometryPrecisionReducer.cpp
@@ -86,7 +86,7 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
// reducedCoords take ownership of 'vc'
CoordinateSequence* reducedCoords =
- geom->getFactory()->getCoordinateSequenceFactory()->create(vc);
+ geom->getFactory()->getCoordinateSequenceFactory()->create(vc).release();
// remove repeated points, to simplify returned geometry as
// much as possible.
diff --git a/src/triangulate/quadedge/QuadEdgeSubdivision.cpp b/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
index 961375f..62cd765 100644
--- a/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
+++ b/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
@@ -401,13 +401,13 @@ public:
void
visit(QuadEdge* triEdges[3]) override
{
- geom::CoordinateSequence* coordSeq = coordSeqFact.create(4, 0);
+ auto coordSeq = coordSeqFact.create(4, 0);
for(int i = 0; i < 3; i++) {
Vertex v = triEdges[i]->orig();
coordSeq->setAt(v.getCoordinate(), i);
}
coordSeq->setAt(triEdges[0]->orig().getCoordinate(), 3);
- triCoords->push_back(coordSeq);
+ triCoords->push_back(coordSeq.release());
}
};
@@ -470,14 +470,12 @@ QuadEdgeSubdivision::getEdges(const geom::GeometryFactory& geomFact)
int i = 0;
for(QuadEdgeSubdivision::QuadEdgeList::iterator it = p_quadEdges->begin(); it != p_quadEdges->end(); ++it) {
QuadEdge* qe = *it;
- CoordinateSequence* coordSeq = coordSeqFact->create((std::vector<geom::Coordinate>*)nullptr);;
+ auto coordSeq = coordSeqFact->create((std::vector<geom::Coordinate>*)nullptr);;
coordSeq->add(qe->orig().getCoordinate());
coordSeq->add(qe->dest().getCoordinate());
- edges[i++] = static_cast<Geometry*>(geomFact.createLineString(*coordSeq));
-
- delete coordSeq;
+ edges[i++] = static_cast<Geometry*>(geomFact.createLineString(coordSeq.release()));
}
geom::MultiLineString* result = geomFact.createMultiLineString(edges);
diff --git a/src/util/GeometricShapeFactory.cpp b/src/util/GeometricShapeFactory.cpp
index bf5ba29..8a0d145 100644
--- a/src/util/GeometricShapeFactory.cpp
+++ b/src/util/GeometricShapeFactory.cpp
@@ -20,6 +20,7 @@
#include <geos/constants.h>
#include <geos/util/GeometricShapeFactory.h>
#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/PrecisionModel.h>
@@ -117,8 +118,8 @@ GeometricShapeFactory::createRectangle()
(*vc)[ipt++] = coord(x, y);
}
(*vc)[ipt++] = (*vc)[0];
- CoordinateSequence* cs = geomFact->getCoordinateSequenceFactory()->create(vc);
- LinearRing* ring = geomFact->createLinearRing(cs);
+ auto cs = geomFact->getCoordinateSequenceFactory()->create(vc);
+ LinearRing* ring = geomFact->createLinearRing(cs.release());
Polygon* poly = geomFact->createPolygon(ring, nullptr);
return poly;
}
@@ -143,8 +144,8 @@ GeometricShapeFactory::createCircle()
(*pts)[iPt++] = coord(x, y);
}
(*pts)[iPt++] = (*pts)[0];
- CoordinateSequence* cs = geomFact->getCoordinateSequenceFactory()->create(pts);
- LinearRing* ring = geomFact->createLinearRing(cs);
+ auto cs = geomFact->getCoordinateSequenceFactory()->create(pts);
+ LinearRing* ring = geomFact->createLinearRing(cs.release());
Polygon* poly = geomFact->createPolygon(ring, nullptr);
return poly;
}
@@ -174,8 +175,8 @@ GeometricShapeFactory::createArc(double startAng, double angExtent)
double y = yRadius * sin(ang) + centreY;
(*pts)[iPt++] = coord(x, y);
}
- CoordinateSequence* cs = geomFact->getCoordinateSequenceFactory()->create(pts);
- LineString* line = geomFact->createLineString(cs);
+ auto cs = geomFact->getCoordinateSequenceFactory()->create(pts);
+ LineString* line = geomFact->createLineString(cs.release());
return line;
}
@@ -207,8 +208,8 @@ GeometricShapeFactory::createArcPolygon(double startAng, double angExtent)
}
(*pts)[iPt++] = coord(centreX, centreY);
- CoordinateSequence* cs = geomFact->getCoordinateSequenceFactory()->create(pts);
- LinearRing* ring = geomFact->createLinearRing(cs);
+ auto cs = geomFact->getCoordinateSequenceFactory()->create(pts);
+ LinearRing* ring = geomFact->createLinearRing(cs.release());
Polygon* geom = geomFact->createPolygon(ring, nullptr);
return geom;
}
diff --git a/tests/unit/algorithm/CGAlgorithms/isCCWTest.cpp b/tests/unit/algorithm/CGAlgorithms/isCCWTest.cpp
index 8a4b30c..eaa4004 100644
--- a/tests/unit/algorithm/CGAlgorithms/isCCWTest.cpp
+++ b/tests/unit/algorithm/CGAlgorithms/isCCWTest.cpp
@@ -28,7 +28,7 @@ namespace tut {
struct test_isccw_data {
typedef std::unique_ptr<geos::geom::Geometry> GeometryPtr;
- geos::geom::CoordinateSequence* cs_;
+ std::unique_ptr<geos::geom::CoordinateSequence> cs_;
geos::io::WKTReader reader_;
geos::io::WKBReader breader_;
@@ -40,8 +40,6 @@ struct test_isccw_data {
~test_isccw_data()
{
- delete cs_;
- cs_ = nullptr;
}
};
@@ -64,7 +62,7 @@ void object::test<1>
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
- bool isCCW = Orientation::isCCW(cs_);
+ bool isCCW = Orientation::isCCW(cs_.get());
ensure_equals(false, isCCW);
}
@@ -79,7 +77,7 @@ void object::test<2>
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
- bool isCCW = Orientation::isCCW(cs_);
+ bool isCCW = Orientation::isCCW(cs_.get());
ensure_equals(true, isCCW);
}
@@ -94,7 +92,7 @@ void object::test<3>
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
- bool isCCW = Orientation::isCCW(cs_);
+ bool isCCW = Orientation::isCCW(cs_.get());
ensure_equals(true, isCCW);
}
@@ -111,7 +109,7 @@ void object::test<4>
wkt("0102000000040000000000000000000000841D588465963540F56BFB214F0341408F26B714B2971B40F66BFB214F0341408C26B714B2971B400000000000000000841D588465963540");
GeometryPtr geom(breader_.readHEX(wkt));
cs_ = geom->getCoordinates();
- bool isCCW = Orientation::isCCW(cs_);
+ bool isCCW = Orientation::isCCW(cs_.get());
ensure_equals(isCCW, true);
}
@@ -127,7 +125,7 @@ void object::test<5>
wkt("0102000000040000000000000000000000841D588465963540F56BFB214F0341408F26B714B2971B40F66BFB214F0341408E26B714B2971B400000000000000000841D588465963540");
GeometryPtr geom(breader_.readHEX(wkt));
cs_ = geom->getCoordinates();
- bool isCCW = Orientation::isCCW(cs_);
+ bool isCCW = Orientation::isCCW(cs_.get());
ensure_equals(isCCW, true);
}
diff --git a/tests/unit/algorithm/CGAlgorithms/isPointInRingTest.cpp b/tests/unit/algorithm/CGAlgorithms/isPointInRingTest.cpp
index da7af8e..53bb741 100644
--- a/tests/unit/algorithm/CGAlgorithms/isPointInRingTest.cpp
+++ b/tests/unit/algorithm/CGAlgorithms/isPointInRingTest.cpp
@@ -24,7 +24,7 @@ namespace tut {
struct test_ispointinring_data {
typedef std::unique_ptr<geos::geom::Geometry> GeomPtr;
- geos::geom::CoordinateSequence* cs_;
+ std::unique_ptr<geos::geom::CoordinateSequence> cs_;
geos::io::WKTReader reader_;
test_ispointinring_data()
@@ -35,8 +35,6 @@ struct test_ispointinring_data {
~test_ispointinring_data()
{
- delete cs_;
- cs_ = nullptr;
}
};
@@ -61,7 +59,7 @@ void object::test<1>
geos::geom::Coordinate pt(10, 10);
cs_ = geom->getCoordinates();
- bool isInRing = PointLocation::isInRing(pt, cs_);
+ bool isInRing = PointLocation::isInRing(pt, cs_.get());
ensure_equals(true, isInRing);
}
@@ -80,7 +78,7 @@ void object::test<2>
geos::geom::Coordinate pt(0, 0);
cs_ = geom->getCoordinates();
- bool isInRing = PointLocation::isInRing(pt, cs_);
+ bool isInRing = PointLocation::isInRing(pt, cs_.get());
ensure_equals(true, isInRing);
}
diff --git a/tests/unit/algorithm/CGAlgorithms/signedAreaTest.cpp b/tests/unit/algorithm/CGAlgorithms/signedAreaTest.cpp
index 91caacd..5d2b370 100644
--- a/tests/unit/algorithm/CGAlgorithms/signedAreaTest.cpp
+++ b/tests/unit/algorithm/CGAlgorithms/signedAreaTest.cpp
@@ -27,7 +27,7 @@ namespace tut {
struct test_signedarea_data {
typedef std::unique_ptr<geos::geom::Geometry> GeometryPtr;
- geos::geom::CoordinateSequence* cs_;
+ std::unique_ptr<geos::geom::CoordinateSequence> cs_;
geos::io::WKTReader reader_;
geos::io::WKBReader breader_;
@@ -39,8 +39,6 @@ struct test_signedarea_data {
~test_signedarea_data()
{
- delete cs_;
- cs_ = nullptr;
}
};
@@ -63,7 +61,7 @@ void object::test<1>
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
- double area = Area::ofRingSigned(cs_);
+ double area = Area::ofRingSigned(cs_.get());
ensure_equals(area, 8400);
}
@@ -78,7 +76,7 @@ void object::test<2>
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
- double area = Area::ofRingSigned(cs_);
+ double area = Area::ofRingSigned(cs_.get());
ensure_equals(area, -2400);
}
@@ -93,7 +91,7 @@ void object::test<3>
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
- double area = Area::ofRingSigned(cs_);
+ double area = Area::ofRingSigned(cs_.get());
ensure_equals(area, -2400);
}
diff --git a/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp b/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp
index e31da6b..ab8d591 100644
--- a/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp
+++ b/tests/unit/geom/CoordinateArraySequenceFactoryTest.cpp
@@ -78,14 +78,11 @@ void object::test<2>
ensure(nullptr != col);
const size_t size0 = 0;
- CoordinateSequencePtr sequence = factory->create(col);
+ auto sequence = factory->create(col);
ensure(nullptr != sequence);
ensure(sequence->isEmpty());
ensure_equals(sequence->size(), size0);
-
- // FREE MEMORY
- delete sequence;
}
catch(std::exception& e) {
fail(e.what());
@@ -112,15 +109,12 @@ void object::test<3>
col->push_back(Coordinate(5, 10, 15));
const size_t size2 = 2;
- CoordinateSequencePtr sequence = factory->create(col);
+ auto sequence = factory->create(col);
ensure(nullptr != sequence);
ensure(!sequence->isEmpty());
ensure_equals(sequence->size(), size2);
ensure(sequence->getAt(0) != sequence->getAt(1));
-
- // FREE MEMORY
- delete sequence;
}
catch(std::exception& e) {
fail(e.what());
@@ -141,7 +135,7 @@ void object::test<4>
ensure(nullptr != factory);
const size_t size1000 = 1000;
- CoordinateSequencePtr sequence = factory->create(size1000, 3);
+ auto sequence = factory->create(size1000, 3);
ensure(nullptr != sequence);
ensure(!sequence->isEmpty());
@@ -149,9 +143,6 @@ void object::test<4>
ensure(sequence->hasRepeatedPoints());
ensure_equals(sequence->getAt(0), sequence->getAt(size1000 - 1));
ensure_equals(sequence->getAt(0), sequence->getAt(size1000 / 2));
-
- // FREE MEMORY
- delete sequence;
}
catch(std::exception& e) {
fail(e.what());
@@ -172,14 +163,11 @@ void object::test<5>
ensure(nullptr != factory);
const size_t size0 = 0;
- CoordinateSequencePtr sequence = factory->create();
+ auto sequence = factory->create();
ensure(nullptr != sequence);
ensure(sequence->isEmpty());
ensure_equals(sequence->size(), size0);
-
- // FREE MEMORY
- delete sequence;
}
catch(std::exception& e) {
fail(e.what());
diff --git a/tests/unit/geom/PolygonTest.cpp b/tests/unit/geom/PolygonTest.cpp
index 9cd146f..adfc363 100644
--- a/tests/unit/geom/PolygonTest.cpp
+++ b/tests/unit/geom/PolygonTest.cpp
@@ -399,13 +399,10 @@ void object::test<26>
ensure(poly_ != nullptr);
// Caller takes ownership of 'coords'
- CoordSeqPtr coords = poly_->getCoordinates();
+ auto coords = poly_->getCoordinates();
ensure(coords != nullptr);
ensure(!coords->isEmpty());
ensure_equals(coords->getSize(), poly_->getNumPoints());
-
- // FREE MEMORY
- delete coords;
}
// Test of clone() and equals() for non-empty Polygon
@@ -497,7 +494,7 @@ void object::test<32>
ensure(poly_ != nullptr);
// "POLYGON((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))"
- CoordSeqPtr coords = poly_->getCoordinates();
+ auto coords = poly_->getCoordinates();
ensure(coords != nullptr);
ensure_equals(coords->getSize(), poly_size_);
@@ -509,9 +506,6 @@ void object::test<32>
const int middlePos = 3;
ensure_equals(coords->getAt(middlePos).x, 15);
ensure_equals(coords->getAt(middlePos).y, 10);
-
- // FREE MEMORY
- delete coords;
}
// Test of getGeometryType() for non-empty Polygon
diff --git a/tests/unit/io/WKTReaderTest.cpp b/tests/unit/io/WKTReaderTest.cpp
index efc46d9..5dc5e4f 100644
--- a/tests/unit/io/WKTReaderTest.cpp
+++ b/tests/unit/io/WKTReaderTest.cpp
@@ -58,12 +58,11 @@ void object::test<1>
()
{
GeomPtr geom(wktreader.read("POINT(-117 33)"));
- geos::geom::CoordinateSequence* coords = geom->getCoordinates();
+ auto coords = geom->getCoordinates();
ensure(coords->getDimension() == 2);
ensure(coords->getX(0) == -117);
ensure(coords->getY(0) == 33);
- delete coords;
}
// 2 - Read a point, confirm 3D.
@@ -73,11 +72,10 @@ void object::test<2>
()
{
GeomPtr geom(wktreader.read("POINT(-117 33 10)"));
- geos::geom::CoordinateSequence* coords = geom->getCoordinates();
+ auto coords = geom->getCoordinates();
ensure(coords->getDimension() == 3);
ensure(coords->getOrdinate(0, geos::geom::CoordinateSequence::Z) == 10.0);
- delete coords;
}
// 3 - Linestring dimension preserved.
@@ -87,11 +85,9 @@ void object::test<3>
()
{
GeomPtr geom(wktreader.read("LINESTRING(-117 33, -116 34)"));
- geos::geom::CoordinateSequence* coords = geom->getCoordinates();
+ auto coords = geom->getCoordinates();
ensure(coords->getDimension() == 2);
-
- delete coords;
}
// 4 - Ensure we can read ZM geometries, just discarding the M.
@@ -101,14 +97,12 @@ void object::test<4>
()
{
GeomPtr geom(wktreader.read("LINESTRING ZM (-117 33 2 3, -116 34 4 5)"));
- geos::geom::CoordinateSequence* coords = geom->getCoordinates();
+ auto coords = geom->getCoordinates();
ensure(coords->getDimension() == 3);
ensure_equals(wktwriter.write(geom.get()),
std::string("LINESTRING Z (-117 33 2, -116 34 4)"));
-
- delete coords;
}
// 5 - Check support for mixed case keywords (and old style 3D)
@@ -161,11 +155,10 @@ void object::test<7>
const std::string str = " POINT (0 0) ";
geom.reset(wktReader.read(str)); //HERE IT FAILS
- geos::geom::CoordinateSequence* coords = geom->getCoordinates();
+ auto coords = geom->getCoordinates();
ensure_equals(coords->getDimension(), 2U);
ensure_distance(coords->getX(0), 0.0, 1e-12);
ensure_distance(coords->getY(0), 0.0, 1e-12);
- delete coords;
}
catch(const geos::util::IllegalArgumentException& ex) {
ensure("Did get expected exception");
diff --git a/tests/unit/util/UniqueCoordinateArrayFilterTest.cpp b/tests/unit/util/UniqueCoordinateArrayFilterTest.cpp
index 6992385..f657064 100644
--- a/tests/unit/util/UniqueCoordinateArrayFilterTest.cpp
+++ b/tests/unit/util/UniqueCoordinateArrayFilterTest.cpp
@@ -60,7 +60,7 @@ void object::test<1>
ensure_equals(geo->getGeometryTypeId(), geos::geom::GEOS_MULTIPOINT);
std::unique_ptr<geos::geom::CoordinateSequence> cs;
- cs.reset(geo->getCoordinates());
+ cs = geo->getCoordinates();
ensure_equals(cs->getSize(), size5);
// Create collection buffer for filtered coordinates
@@ -76,7 +76,7 @@ void object::test<1>
const Coordinate::ConstVect::size_type size3 = 3;
geo->apply_ro(&filter);
- cs.reset(geo->getCoordinates());
+ cs = geo->getCoordinates();
ensure_equals(cs->getSize(), size5);
ensure_equals(coords.size(), size3);
ensure_equals(coords.at(0)->x, 10);
-----------------------------------------------------------------------
Summary of changes:
capi/geos_ts_c.cpp | 6 +--
include/geos/algorithm/ConvexHull.h | 5 +-
include/geos/algorithm/MinimumDiameter.h | 3 +-
include/geos/geom/CoordinateArraySequence.h | 2 +-
include/geos/geom/CoordinateArraySequenceFactory.h | 8 ++--
.../geos/geom/CoordinateArraySequenceFactory.inl | 22 +++++----
include/geos/geom/CoordinateSequence.h | 2 +-
include/geos/geom/CoordinateSequenceFactory.h | 11 +++--
include/geos/geom/Geometry.h | 2 +-
include/geos/geom/GeometryCollection.h | 2 +-
include/geos/geom/LineString.h | 2 +-
include/geos/geom/LinearRing.h | 2 +-
include/geos/geom/Point.h | 2 +-
include/geos/geom/Polygon.h | 2 +-
include/geos/geom/prep/PreparedGeometryFactory.h | 6 ++-
include/geos/geomgraph/EdgeRing.h | 3 +-
include/geos/io/WKBReader.h | 2 +-
include/geos/io/WKTReader.h | 2 +-
include/geos/noding/SegmentStringUtil.h | 4 +-
src/algorithm/ConvexHull.cpp | 14 +++---
src/algorithm/MinimumBoundingCircle.cpp | 8 ++--
src/algorithm/MinimumDiameter.cpp | 16 +++----
src/algorithm/distance/DiscreteFrechetDistance.cpp | 6 +--
src/geom/CoordinateArraySequence.cpp | 4 +-
src/geom/CoordinateSequence.cpp | 2 +-
src/geom/GeometryCollection.cpp | 5 +-
src/geom/GeometryFactory.cpp | 30 +++++-------
src/geom/LineString.cpp | 10 ++--
src/geom/LinearRing.cpp | 8 ++--
src/geom/Point.cpp | 4 +-
src/geom/Polygon.cpp | 15 +++---
src/geom/prep/PreparedGeometryFactory.cpp | 12 ++---
src/geom/util/CoordinateOperation.cpp | 5 +-
src/geomgraph/EdgeNodingValidator.cpp | 6 +--
src/geomgraph/EdgeRing.cpp | 14 +-----
src/io/WKBReader.cpp | 12 ++---
src/io/WKTReader.cpp | 54 ++++++++-------------
src/linearref/ExtractLineByLocation.cpp | 2 +-
src/noding/GeometryNoder.cpp | 6 +--
src/operation/buffer/BufferBuilder.cpp | 4 +-
src/operation/buffer/OffsetCurveBuilder.cpp | 2 +-
src/operation/intersection/Rectangle.cpp | 4 +-
.../intersection/RectangleIntersection.cpp | 16 +++----
.../intersection/RectangleIntersectionBuilder.cpp | 4 +-
src/operation/linemerge/EdgeString.cpp | 2 +-
src/operation/linemerge/LineSequencer.cpp | 6 +--
src/operation/overlay/LineBuilder.cpp | 6 +--
src/operation/polygonize/EdgeRing.cpp | 2 +-
src/operation/valid/RepeatedPointTester.cpp | 4 +-
src/operation/valid/SimpleNestedRingTester.cpp | 4 +-
src/operation/valid/SweeplineNestedRingTester.cpp | 4 +-
src/precision/MinimumClearance.cpp | 2 +-
.../PrecisionReducerCoordinateOperation.cpp | 2 +-
src/precision/SimpleGeometryPrecisionReducer.cpp | 2 +-
src/triangulate/quadedge/QuadEdgeSubdivision.cpp | 10 ++--
src/util/GeometricShapeFactory.cpp | 17 +++----
tests/unit/algorithm/CGAlgorithms/isCCWTest.cpp | 14 +++---
.../algorithm/CGAlgorithms/isPointInRingTest.cpp | 8 ++--
.../unit/algorithm/CGAlgorithms/signedAreaTest.cpp | 10 ++--
.../geom/CoordinateArraySequenceFactoryTest.cpp | 20 ++------
tests/unit/geom/PolygonTest.cpp | 10 +---
.../geom/prep/PreparedGeometry/touchesTest.cpp | 8 ++--
.../unit/geom/prep/PreparedGeometryFactoryTest.cpp | 56 +++++++++++-----------
tests/unit/io/WKTReaderTest.cpp | 17 ++-----
.../unit/util/UniqueCoordinateArrayFilterTest.cpp | 4 +-
tests/xmltester/XMLTester.cpp | 2 +-
66 files changed, 249 insertions(+), 312 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list