GEOS 3.9.1
CoordinateList.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2010 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2006 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: geom/CoordinateList.java ?? (never been in complete sync)
17 *
18 **********************************************************************/
19
20#ifndef GEOS_GEOM_COORDINATELIST_H
21#define GEOS_GEOM_COORDINATELIST_H
22
23#include <geos/export.h>
24#include <geos/geom/Coordinate.h>
25
26#include <list>
27#include <ostream> // for operator<<
28#include <memory> // for unique_ptr
29
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33#endif
34
35// Forward declarations
36namespace geos {
37namespace geom {
38//class Coordinate;
39}
40}
41
42
43namespace geos {
44namespace geom { // geos::geom
45
55class GEOS_DLL CoordinateList {
56
57public:
58
59 typedef std::list<Coordinate>::iterator iterator;
60 typedef std::list<Coordinate>::const_iterator const_iterator;
61
62 friend std::ostream& operator<< (std::ostream& os,
63 const CoordinateList& cl);
64
74 CoordinateList(const std::vector<Coordinate>& v)
75 :
76 coords(v.begin(), v.end())
77 {
78 }
79
81 :
82 coords()
83 {
84 }
85
86 size_t
87 size() const
88 {
89 return coords.size();
90 }
91
92 bool
93 empty() const
94 {
95 return coords.empty();
96 }
97
98 iterator
99 begin()
100 {
101 return coords.begin();
102 }
103
104 iterator
105 end()
106 {
107 return coords.end();
108 }
109
110 const_iterator
111 begin() const
112 {
113 return coords.begin();
114 }
115
116 const_iterator
117 end() const
118 {
119 return coords.end();
120 }
121
135 iterator
136 insert(iterator pos, const Coordinate& c, bool allowRepeated)
137 {
138 if(!allowRepeated && pos != coords.begin()) {
139 iterator prev = pos;
140 --prev;
141 if(c.equals2D(*prev)) {
142 return prev;
143 }
144 }
145 return coords.insert(pos, c);
146 }
147
148 iterator
149 insert(iterator pos, const Coordinate& c)
150 {
151 return coords.insert(pos, c);
152 }
153
154 iterator
155 erase(iterator pos)
156 {
157 return coords.erase(pos);
158 }
159
160 iterator
161 erase(iterator first, iterator last)
162 {
163 return coords.erase(first, last);
164 }
165
166 std::unique_ptr<Coordinate::Vect>
167 toCoordinateArray() const
168 {
169 std::unique_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
170 ret->assign(coords.begin(), coords.end());
171 return ret;
172 }
173 void
174 closeRing()
175 {
176 if(!coords.empty() && !(*(coords.begin())).equals(*(coords.rbegin()))) {
177 const Coordinate& c = *(coords.begin());
178 coords.insert(coords.end(), c);
179 }
180 }
181
182
183private:
184
185 std::list<Coordinate> coords;
186};
187
188inline
189std::ostream&
190operator<< (std::ostream& os, const CoordinateList& cl)
191{
192 os << "(";
193 for(CoordinateList::const_iterator
194 it = cl.begin(), end = cl.end();
195 it != end;
196 ++it) {
197 const Coordinate& c = *it;
198 if(it != cl.begin()) {
199 os << ", ";
200 }
201 os << c;
202 }
203 os << ")";
204
205 return os;
206}
207
208} // namespace geos::geom
209} // namespace geos
210
211#ifdef _MSC_VER
212#pragma warning(pop)
213#endif
214
215#endif // ndef GEOS_GEOM_COORDINATELIST_H
A list of Coordinates, which may be set to prevent repeated coordinates from occuring in the list.
Definition CoordinateList.h:55
CoordinateList(const std::vector< Coordinate > &v)
Constructs a new list from an array of Coordinates, allowing repeated points.
Definition CoordinateList.h:74
iterator insert(iterator pos, const Coordinate &c, bool allowRepeated)
Inserts the specified coordinate at the specified position in this list.
Definition CoordinateList.h:136
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:26