OffsetCurve.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
*
* 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.
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/operation/buffer/BufferParameters.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/constants.h>
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
class CoordinateSequence;
class Geometry;
class LineString;
class Polygon;
}
namespace operation {
namespace buffer {
class OffsetCurveSection;
class SegmentMCIndex;
}
}
}
namespace geos {
namespace operation {
namespace buffer {
class GEOS_DLL OffsetCurve {
using Coordinate = geos::geom::Coordinate;
using CoordinateSequence = geos::geom::CoordinateSequence;
using Geometry = geos::geom::Geometry;
using GeometryFactory = geos::geom::GeometryFactory;
using LineString = geos::geom::LineString;
using Polygon = geos::geom::Polygon;
private:
// Members
const Geometry& inputGeom;
double distance;
bool isJoined = false;
BufferParameters bufferParams;
double matchDistance;
const GeometryFactory* geomFactory;
// Methods
std::unique_ptr<Geometry> computePolygonCurve(
const Polygon& polyGeom, double distance);
std::unique_ptr<Geometry> computeCurve(
const LineString& lineGeom, double distance);
std::vector<std::unique_ptr<OffsetCurveSection>> computeSections(
const LineString& lineGeom, double distance);
std::unique_ptr<LineString> offsetSegment(
const CoordinateSequence* pts, double distance);
static std::unique_ptr<Polygon> getBufferOriented(
const LineString& geom, double distance,
BufferParameters& bufParams);
static const Polygon* extractMaxAreaPolygon(const Geometry* geom);
void computeCurveSections(
const CoordinateSequence* bufferRingPts,
const CoordinateSequence& rawCurve,
std::vector<std::unique_ptr<OffsetCurveSection>>& sections);
std::size_t matchSegments(
const Coordinate& raw0, const Coordinate& raw1,
std::size_t rawCurveIndex,
SegmentMCIndex& bufferSegIndex,
const CoordinateSequence* bufferPts,
std::vector<double>& rawCurvePos);
static double segmentMatchFrac(
const Coordinate& p0, const Coordinate& p1,
const Coordinate& seg0, const Coordinate& seg1,
double matchDistance);
void extractSections(
const CoordinateSequence* ringPts,
std::vector<double>& rawCurveLoc,
std::size_t startIndex,
std::vector<std::unique_ptr<OffsetCurveSection>>& sections);
std::size_t findSectionStart(
const std::vector<double>& loc,
std::size_t end);
std::size_t findSectionEnd(
const std::vector<double>& loc,
std::size_t start,
std::size_t firstStartIndex);
static std::size_t nextIndex(std::size_t i, std::size_t size);
static std::size_t prevIndex(std::size_t i, std::size_t size);
public:
// Constants
static constexpr int MATCH_DISTANCE_FACTOR = 10000;
static constexpr int MIN_QUADRANT_SEGMENTS = 8;
OffsetCurve(const Geometry& geom, double dist)
: inputGeom(geom)
, distance(dist)
, matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
, geomFactory(geom.getFactory())
{
if (!std::isfinite(dist)) {
throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
}
};
OffsetCurve(const Geometry& geom, double dist, BufferParameters& bp)
: inputGeom(geom)
, distance(dist)
, matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
, geomFactory(geom.getFactory())
{
if (!std::isfinite(dist)) {
throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
}
//-- set buffer params, leaving cap style as the default CAP_ROUND
int quadSegs = bp.getQuadrantSegments();
if (quadSegs < MIN_QUADRANT_SEGMENTS) {
quadSegs = MIN_QUADRANT_SEGMENTS;
}
bufferParams.setQuadrantSegments(quadSegs);
bufferParams.setJoinStyle( bp.getJoinStyle());
bufferParams.setMitreLimit( bp.getMitreLimit());
};
void setJoined(bool pIsJoined);
static std::unique_ptr<Geometry> getCurve(
const Geometry& geom,
double dist,
int quadSegs,
BufferParameters::JoinStyle joinStyle,
double mitreLimit);
static std::unique_ptr<Geometry> getCurve(
const Geometry& geom, double dist);
static std::unique_ptr<Geometry> getCurveJoined(
const Geometry& geom, double dist);
std::unique_ptr<Geometry> getCurve();
static std::unique_ptr<CoordinateSequence> rawOffsetCurve(
const LineString& line,
double distance,
BufferParameters& bufParams);
static std::unique_ptr<CoordinateSequence> rawOffset(
const LineString& line,
double distance);
};
} // 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::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::LineString
Definition LineString.h:66
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::operation::buffer::BufferParameters
Contains the parameters which describe how a buffer should be constructed.
Definition BufferParameters.h:56
geos::operation::buffer::BufferParameters::getMitreLimit
double getMitreLimit() const
Definition BufferParameters.h:224
geos::operation::buffer::BufferParameters::getJoinStyle
JoinStyle getJoinStyle() const
Definition BufferParameters.h:199
geos::operation::buffer::BufferParameters::getQuadrantSegments
int getQuadrantSegments() const
Definition BufferParameters.h:137
geos::operation::buffer::BufferParameters::JoinStyle
JoinStyle
Join styles.
Definition BufferParameters.h:74
geos::operation::buffer::OffsetCurveSection
Definition OffsetCurveSection.h:49
geos::operation::buffer::OffsetCurve::OffsetCurve
OffsetCurve(const Geometry &geom, double dist, BufferParameters &bp)
Definition OffsetCurve.h:230
geos::operation::buffer::OffsetCurve::getCurve
std::unique_ptr< Geometry > getCurve()
geos::operation::buffer::OffsetCurve::MIN_QUADRANT_SEGMENTS
static constexpr int MIN_QUADRANT_SEGMENTS
Definition OffsetCurve.h:198
geos::operation::buffer::OffsetCurve::rawOffsetCurve
static std::unique_ptr< CoordinateSequence > rawOffsetCurve(const LineString &line, double distance, BufferParameters &bufParams)
geos::operation::buffer::OffsetCurve::rawOffset
static std::unique_ptr< CoordinateSequence > rawOffset(const LineString &line, double distance)
geos::operation::buffer::OffsetCurve::getCurveJoined
static std::unique_ptr< Geometry > getCurveJoined(const Geometry &geom, double dist)
geos::operation::buffer::OffsetCurve::setJoined
void setJoined(bool pIsJoined)
geos::operation::buffer::OffsetCurve::OffsetCurve
OffsetCurve(const Geometry &geom, double dist)
Definition OffsetCurve.h:210
geos::util::IllegalArgumentException
Indicates one or more illegal arguments.
Definition IllegalArgumentException.h:33
geos::geom
Definition Angle.h:26
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