OffsetSegmentString.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2007 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: operation/buffer/OffsetSegmentString.java r378 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <geos/geom/Coordinate.h> // for inlines
#include <geos/geom/CoordinateSequence.h> // for inlines
#include <geos/geom/PrecisionModel.h> // for inlines
#include <vector>
#include <memory>
#include <cassert>
namespace geos {
namespace operation { // geos.operation
namespace buffer { // geos.operation.buffer
class OffsetSegmentString {
private:
geom::CoordinateSequence* ptList;
const geom::PrecisionModel* precisionModel;
double minimumVertexDistance;
bool
isRedundant(const geom::Coordinate& pt) const
{
if(ptList->size() < 1) {
return false;
}
const geom::Coordinate& lastPt = ptList->back();
double ptDist = pt.distance(lastPt);
if(ptDist < minimumVertexDistance) {
return true;
}
return false;
}
OffsetSegmentString(const OffsetSegmentString&) = delete;
OffsetSegmentString& operator=(const OffsetSegmentString&) = delete;
public:
friend std::ostream& operator<< (std::ostream& os, const OffsetSegmentString& node);
OffsetSegmentString()
:
ptList(new geom::CoordinateSequence()),
precisionModel(nullptr),
minimumVertexDistance(0.0)
{
}
~OffsetSegmentString()
{
delete ptList;
}
void
reset()
{
if(ptList) {
ptList->clear();
}
else {
ptList = new geom::CoordinateSequence();
}
precisionModel = nullptr;
minimumVertexDistance = 0.0;
}
void
setPrecisionModel(const geom::PrecisionModel* nPrecisionModel)
{
precisionModel = nPrecisionModel;
}
void
setMinimumVertexDistance(double nMinVertexDistance)
{
minimumVertexDistance = nMinVertexDistance;
}
void
addPt(const geom::Coordinate& pt)
{
assert(precisionModel);
geom::Coordinate bufPt = pt;
precisionModel->makePrecise(bufPt);
// don't add duplicate (or near-duplicate) points
if(isRedundant(bufPt)) {
return;
}
// we ask to allow repeated as we checked this ourself
// (JTS uses a vector for ptList, not a CoordinateSequence,
// we should do the same)
ptList->add(bufPt, true);
}
void
addPts(const geom::CoordinateSequence& pts, bool isForward)
{
if(isForward) {
for(std::size_t i = 0, n = pts.size(); i < n; ++i) {
addPt(pts[i]);
}
}
else {
for(std::size_t i = pts.size(); i > 0; --i) {
addPt(pts[i - 1]);
}
}
}
void
closeRing()
{
if(ptList->size() < 1) {
return;
}
const geom::Coordinate& startPt = ptList->front();
const geom::Coordinate& lastPt = ptList->back();
if(startPt.equals(lastPt)) {
return;
}
// we ask to allow repeated as we checked this ourself
ptList->add(startPt, true);
}
geom::CoordinateSequence*
getCoordinates()
{
closeRing();
geom::CoordinateSequence* ret = ptList;
ptList = nullptr;
return ret;
}
inline size_t
size() const
{
return ptList ? ptList->size() : 0 ;
}
};
inline std::ostream&
operator<< (std::ostream& os,
const OffsetSegmentString& lst)
{
if(lst.ptList) {
os << *(lst.ptList);
}
else {
os << "empty (consumed?)";
}
return os;
}
} // namespace geos.operation.buffer
} // namespace geos.operation
} // namespace geos
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::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
geos::operation::buffer::OffsetSegmentString::closeRing
void closeRing()
Definition OffsetSegmentString.h:160
geos::operation::buffer::OffsetSegmentString::getCoordinates
geom::CoordinateSequence * getCoordinates()
Definition OffsetSegmentString.h:183
geos::geom::CoordinateSequence::size
size_t size() const
Returns the number of Coordinates.
Definition CoordinateSequence.h:185
geos::operation::buffer
Provides classes for computing buffers of geometries.
Definition namespaces.h:182
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38