SegmentString.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions 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: noding/SegmentString.java r430 (JTS-1.12+)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/noding/Octant.h>
#include <vector>
// Forward declarations
namespace geos {
namespace algorithm {
class LineIntersector;
}
}
namespace geos {
namespace noding { // geos.noding
class GEOS_DLL SegmentString {
public:
typedef std::vector<const SegmentString*> ConstVect;
typedef std::vector<SegmentString*> NonConstVect;
friend std::ostream& operator<< (std::ostream& os,
const SegmentString& ss);
SegmentString(const void* newContext, geom::CoordinateSequence* newSeq)
:
seq(newSeq),
context(newContext)
{}
virtual
~SegmentString() {}
const void*
getData() const
{
return context;
}
void
setData(const void* data)
{
context = data;
}
std::size_t size() const {
return seq->size();
}
template<typename CoordType = geom::Coordinate>
const CoordType& getCoordinate(std::size_t i) const {
return seq->getAt<CoordType>(i);
}
const geom::CoordinateSequence* getCoordinates() const {
return seq;
}
geom::CoordinateSequence* getCoordinates() {
return seq;
}
int getSegmentOctant(std::size_t index) const
{
if (index >= size() - 1) {
return -1;
}
return safeOctant(seq->getAt<geom::CoordinateXY>(index),
seq->getAt<geom::CoordinateXY>(index + 1));
};
static int getSegmentOctant(const SegmentString& ss, std::size_t index) {
return ss.getSegmentOctant(index);
}
const geom::CoordinateXY& nextInRing(std::size_t index) const
{
std::size_t nextIndex = index + 1;
if (nextIndex > size() - 1) {
nextIndex = 1;
}
return getCoordinate(nextIndex);
}
const geom::CoordinateXY& prevInRing(std::size_t index) const
{
std::size_t prevIndex;
if (index == 0)
prevIndex = size() - 2;
else
prevIndex = index - 1;
return getCoordinate( prevIndex );
}
bool isClosed() const {
return seq->front<geom::CoordinateXY>().equals(seq->back<geom::CoordinateXY>());
}
virtual std::ostream& print(std::ostream& os) const;
protected:
geom::CoordinateSequence* seq;
private:
const void* context;
static int safeOctant(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1)
{
if(p0.equals2D(p1)) {
return 0;
}
return Octant::octant(p0, p1);
};
// Declare type as noncopyable
SegmentString(const SegmentString& other) = delete;
SegmentString& operator=(const SegmentString& rhs) = delete;
};
std::ostream& operator<< (std::ostream& os, const SegmentString& ss);
} // namespace geos.noding
} // namespace geos
geos::algorithm::LineIntersector
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:53
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::noding::SegmentString
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
geos::noding::SegmentString::SegmentString
SegmentString(const void *newContext, geom::CoordinateSequence *newSeq)
Construct a SegmentString.
Definition SegmentString.h:60
geos::noding::SegmentString::nextInRing
const geom::CoordinateXY & nextInRing(std::size_t index) const
Definition SegmentString.h:142
geos::noding::SegmentString::getData
const void * getData() const
Gets the user-defined data for this segment string.
Definition SegmentString.h:75
geos::noding::SegmentString::getCoordinates
const geom::CoordinateSequence * getCoordinates() const
Return a pointer to the CoordinateSequence associated with this SegmentString.
Definition SegmentString.h:106
geos::noding::SegmentString::getSegmentOctant
int getSegmentOctant(std::size_t index) const
Gets the octant of the segment starting at vertex index.
Definition SegmentString.h:121
geos::noding::SegmentString::prevInRing
const geom::CoordinateXY & prevInRing(std::size_t index) const
Definition SegmentString.h:159
geos::noding::SegmentString::setData
void setData(const void *data)
Sets the user-defined data for this segment string.
Definition SegmentString.h:86
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::index
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
geos::noding
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition CoverageCleaner.h:42
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38