Skip to content

Commit 88a9878

Browse files
authored
SimpleCurve / SegmentString: Store coordinates as std::shared_ptr (#1329)
1 parent e8c6acc commit 88a9878

File tree

79 files changed

+408
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+408
-331
lines changed

include/geos/coverage/CoverageCleaner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class GEOS_DLL CoverageCleaner {
323323
*/
324324
std::vector<const Polygon*> getMergedGaps();
325325

326-
std::unique_ptr<Geometry> toGeometry(
326+
static std::unique_ptr<Geometry> toGeometry(
327327
std::vector<std::unique_ptr<SegmentString>>& segStrings,
328328
const GeometryFactory* geomFact);
329329

include/geos/coverage/CoverageEdge.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GEOS_DLL CoverageEdge {
5656
private:
5757

5858
// Members
59-
std::unique_ptr<CoordinateSequence> m_pts;
59+
std::shared_ptr<const CoordinateSequence> m_pts;
6060
std::size_t m_ringCount ;
6161
bool m_isFreeRing = true;
6262

@@ -119,7 +119,7 @@ class GEOS_DLL CoverageEdge {
119119
const GeometryFactory* geomFactory);
120120

121121
std::unique_ptr<LineString> toLineString(
122-
const GeometryFactory* geomFactory);
122+
const GeometryFactory* geomFactory) const;
123123

124124
/* public */
125125
void incRingCount()
@@ -144,14 +144,14 @@ class GEOS_DLL CoverageEdge {
144144
return m_isFreeRing;
145145
}
146146

147-
void setCoordinates(const CoordinateSequence* pts)
147+
void setCoordinates(const std::shared_ptr<const CoordinateSequence>& pts)
148148
{
149-
m_pts = pts->clone();
149+
m_pts = pts;
150150
}
151151

152-
const CoordinateSequence* getCoordinates() const
152+
const std::shared_ptr<const CoordinateSequence>& getCoordinates() const
153153
{
154-
return m_pts.get();
154+
return m_pts;
155155
}
156156

157157
const Coordinate& getEndCoordinate() const

include/geos/coverage/CoveragePolygonValidator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ class GEOS_DLL CoveragePolygonValidator {
204204
double gapWidth = 0.0;
205205
std::vector<std::unique_ptr<CoveragePolygon>> m_adjCovPolygons;
206206
std::deque<CoverageRing> coverageRingStore;
207-
std::vector<std::unique_ptr<CoordinateSequence>> localCoordinateSequences;
208207
std::deque<CoverageRingSegment> coverageRingSegmentStore;
209208

210209
typedef std::unordered_map<CoverageRingSegment*, CoverageRingSegment*, CoverageRingSegment::CoverageRingSegHash, CoverageRingSegment::CoverageRingSegEq> CoverageRingSegmentMap;

include/geos/coverage/CoverageRing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class GEOS_DLL CoverageRing : public noding::BasicSegmentString {
7878

7979
public:
8080

81-
CoverageRing(CoordinateSequence* pts, bool interiorOnRight);
81+
CoverageRing(const std::shared_ptr<const CoordinateSequence>& pts, bool interiorOnRight);
8282

8383
CoverageRing(const LinearRing* ring, bool isShell);
8484

include/geos/geom/CircularString.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class GEOS_DLL CircularString : public SimpleCurve {
5858
CircularString(std::unique_ptr<CoordinateSequence>&& pts,
5959
const GeometryFactory& newFactory);
6060

61+
CircularString(const std::shared_ptr<const CoordinateSequence>& pts,
62+
const GeometryFactory& newFactory);
63+
6164
CircularString* cloneImpl() const override
6265
{
6366
return new CircularString(*this);

include/geos/geom/GeometryFactory.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ class GEOS_DLL GeometryFactory {
236236
std::unique_ptr<LinearRing> createLinearRing(
237237
std::unique_ptr<CoordinateSequence> && newCoords) const;
238238

239+
std::unique_ptr<LinearRing> createLinearRing(
240+
const std::shared_ptr<const CoordinateSequence>& newCoords) const;
241+
239242
/// Construct a LinearRing with a deep-copy of given arguments
240243
std::unique_ptr<LinearRing> createLinearRing(
241244
const CoordinateSequence& coordinates) const;
@@ -312,6 +315,10 @@ class GEOS_DLL GeometryFactory {
312315
std::unique_ptr<LineString> createLineString(
313316
const CoordinateSequence& coordinates) const;
314317

318+
/// Construct a LineString with a reference to shared coordinates
319+
std::unique_ptr<LineString> createLineString(
320+
const std::shared_ptr<const CoordinateSequence>&) const;
321+
315322
/// Construct an EMPTY CircularString
316323
std::unique_ptr<CircularString> createCircularString(bool hasZ, bool hasM) const;
317324

@@ -322,6 +329,10 @@ class GEOS_DLL GeometryFactory {
322329
std::unique_ptr<CircularString> createCircularString(
323330
std::unique_ptr<CoordinateSequence> && coordinates) const;
324331

332+
/// Construct a CircularStrign with a reference to shared coordinates
333+
std::unique_ptr<CircularString> createCircularString(
334+
const std::shared_ptr<const CoordinateSequence>& coordinates) const;
335+
325336
/// Construct a CircularString with a deep-copy of given argument
326337
std::unique_ptr<CircularString> createCircularString(
327338
const CoordinateSequence& coordinates) const;

include/geos/geom/LineString.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class GEOS_DLL LineString: public SimpleCurve {
114114
LineString(CoordinateSequence::Ptr && pts,
115115
const GeometryFactory& newFactory);
116116

117+
LineString(const std::shared_ptr<const CoordinateSequence> & pts,
118+
const GeometryFactory& newFactory);
119+
117120
LineString* cloneImpl() const override { return new LineString(*this); }
118121

119122
LineString* reverseImpl() const override;

include/geos/geom/LinearRing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class GEOS_DLL LinearRing : public LineString {
7878
LinearRing(CoordinateSequence::Ptr && points,
7979
const GeometryFactory& newFactory);
8080

81+
LinearRing(const std::shared_ptr<const CoordinateSequence>& points,
82+
const GeometryFactory& newFactory);
83+
8184
std::unique_ptr<LinearRing> clone() const
8285
{
8386
return std::unique_ptr<LinearRing>(cloneImpl());

include/geos/geom/SimpleCurve.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class GEOS_DLL SimpleCurve : public Curve {
6161
/// Returns a read-only pointer to internal CoordinateSequence
6262
const CoordinateSequence* getCoordinatesRO() const;
6363

64+
/// Returns a read-only pointer to internal CoordinateSequence
65+
const std::shared_ptr<const CoordinateSequence>& getSharedCoordinates() const;
66+
6467
const SimpleCurve* getCurveN(std::size_t) const override;
6568

6669
/// \brief
@@ -107,19 +110,14 @@ class GEOS_DLL SimpleCurve : public Curve {
107110
*/
108111
void normalize() override;
109112

110-
/**
111-
* \brief
112-
* Take ownership of the CoordinateSequence managed by this geometry.
113-
* After releasing the coordinates, the geometry should be considered
114-
* in a moved-from state and should not be accessed.
115-
* @return this Geometry's CoordinateSequence.
116-
*/
117-
std::unique_ptr<CoordinateSequence> releaseCoordinates();
118-
119113
protected:
120114

121115
SimpleCurve(const SimpleCurve& other);
122116

117+
SimpleCurve(const std::shared_ptr<const CoordinateSequence>& newCoords,
118+
bool isLinear,
119+
const GeometryFactory& factory);
120+
123121
SimpleCurve(std::unique_ptr<CoordinateSequence>&& newCoords,
124122
bool isLinear,
125123
const GeometryFactory& factory);
@@ -128,8 +126,7 @@ class GEOS_DLL SimpleCurve : public Curve {
128126

129127
Envelope computeEnvelopeInternal(bool isLinear) const;
130128

131-
// TODO: hold value or shared_ptr instead of unique_ptr?
132-
std::unique_ptr<CoordinateSequence> points;
129+
std::shared_ptr<const CoordinateSequence> points;
133130
mutable Envelope envelope;
134131

135132

include/geos/geomgraph/EdgeNodingValidator.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ class GEOS_DLL EdgeNodingValidator final {
6262
// in turn expects this member to be initialized
6363
std::vector<std::unique_ptr<noding::SegmentString>> segStr;
6464

65-
// Make sure this member is initialized *before*
66-
// the NodingValidator, as initialization of
67-
// NodingValidator will use toSegmentString(), that
68-
// in turn expects this member to be initialized
69-
std::vector<geom::CoordinateSequence*> newCoordSeq;
70-
7165
noding::FastNodingValidator nv;
7266

7367
public:
@@ -91,7 +85,6 @@ class GEOS_DLL EdgeNodingValidator final {
9185
EdgeNodingValidator(std::vector<Edge*>& edges)
9286
:
9387
segStr(),
94-
newCoordSeq(),
9588
nv(toSegmentStrings(edges))
9689
{}
9790

0 commit comments

Comments
 (0)