CoordinateList.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2010 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: geom/CoordinateList.java ?? (never been in complete sync)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/util.h>
#include <list>
#include <ostream> // for operator<<
#include <memory> // for unique_ptr
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
//class Coordinate;
}
}
namespace geos {
namespace geom { // geos::geom
class GEOS_DLL CoordinateList {
public:
typedef std::list<Coordinate>::iterator iterator;
typedef std::list<Coordinate>::const_iterator const_iterator;
friend std::ostream& operator<< (std::ostream& os,
const CoordinateList& cl);
template<typename T>
CoordinateList(const T& v)
:
coords(v.begin(), v.end())
{
}
CoordinateList(const CoordinateSequence& v)
: CoordinateList(v.items<Coordinate>())
{
}
CoordinateList()
:
coords()
{
}
size_t
size() const
{
return coords.size();
}
bool
empty() const
{
return coords.empty();
}
iterator
begin()
{
return coords.begin();
}
iterator
end()
{
return coords.end();
}
const_iterator
begin() const
{
return coords.begin();
}
const_iterator
end() const
{
return coords.end();
}
iterator
insert(iterator pos, const Coordinate& c, bool allowRepeated)
{
if(!allowRepeated && pos != coords.begin()) {
iterator prev = pos;
--prev;
if(c.equals2D(*prev)) {
return prev;
}
}
return coords.insert(pos, c);
}
iterator
add(const Coordinate& c, bool allowRepeated)
{
return insert(coords.end(), c, allowRepeated);
}
iterator
insert(iterator pos, const Coordinate& c)
{
return coords.insert(pos, c);
}
iterator
erase(iterator pos)
{
return coords.erase(pos);
}
iterator
erase(iterator first, iterator last)
{
return coords.erase(first, last);
}
std::unique_ptr<Coordinate::Vect>
toCoordinateArray() const
{
std::unique_ptr<Coordinate::Vect> ret(new Coordinate::Vect);
ret->assign(coords.begin(), coords.end());
return ret;
}
std::unique_ptr<geom::CoordinateSequence>
toCoordinateSequence() const
{
auto ret = detail::make_unique<geom::CoordinateSequence>();
ret->add(begin(), end());
return ret;
}
void
closeRing()
{
if(!coords.empty() && !(*(coords.begin())).equals(*(coords.rbegin()))) {
const Coordinate& c = *(coords.begin());
coords.insert(coords.end(), c);
}
}
static void
closeRing(std::vector<Coordinate>& coords)
{
if(!coords.empty() && !(*(coords.begin())).equals(*(coords.rbegin()))) {
const Coordinate& c = *(coords.begin());
coords.insert(coords.end(), c);
}
}
private:
std::list<Coordinate> coords;
};
inline
std::ostream&
operator<< (std::ostream& os, const CoordinateList& cl)
{
os << "(";
for(CoordinateList::const_iterator
it = cl.begin(), end = cl.end();
it != end;
++it) {
const Coordinate& c = *it;
if(it != cl.begin()) {
os << ", ";
}
os << c;
}
os << ")";
return os;
}
} // namespace geos::geom
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::CoordinateList
A list of Coordinates, which may be set to prevent repeated coordinates from occurring in the list.
Definition CoordinateList.h:56
geos::geom::CoordinateList::insert
iterator insert(iterator pos, const Coordinate &c, bool allowRepeated)
Inserts the specified coordinate at the specified position in this list.
Definition CoordinateList.h:143
geos::geom::CoordinateList::CoordinateList
CoordinateList(const T &v)
Constructs a new list from an array of Coordinates, allowing repeated points.
Definition CoordinateList.h:76
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom
Definition Angle.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38