GEOS 3.11.1
OffsetCurve.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/export.h>
18#include <geos/geom/GeometryFactory.h>
19#include <geos/index/chain/MonotoneChainSelectAction.h>
20#include <geos/operation/buffer/BufferParameters.h>
21
22
23#ifdef _MSC_VER
24#pragma warning(push)
25#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
26#endif
27
28// Forward declarations
29namespace geos {
30namespace geom {
31class Geometry;
32class LineString;
33class LinearRing;
34class Polygon;
36class Coordinate;
37}
38namespace operation {
39namespace buffer {
40class SegmentMCIndex;
41}
42}
43namespace index {
44namespace chain {
45class MonotoneChain;
46}
47}
48}
49
57
58namespace geos {
59namespace operation {
60namespace buffer {
61
91class GEOS_DLL OffsetCurve {
92
93
94private:
95
96 // Constants
97 static constexpr int NEARNESS_FACTOR = 10000;
98
99 // Members
100 const Geometry& inputGeom;
101 double distance;
102 BufferParameters bufferParams;
103 double matchDistance;
104 const GeometryFactory* geomFactory;
105
106 // Methods
107
108 std::unique_ptr<LineString> computeCurve(const LineString& lineGeom, double distance);
109
110 std::unique_ptr<LineString> offsetSegment(const CoordinateSequence* pts, double distance);
111
112 static std::unique_ptr<Polygon> getBufferOriented(const LineString& geom, double distance, BufferParameters& bufParms);
113
121 static std::unique_ptr<Polygon> extractMaxAreaPolygon(const Geometry& geom);
122
123 static std::unique_ptr<LinearRing> extractLongestHole(const Polygon& poly);
124
125 std::unique_ptr<LineString> computeCurve(
126 const CoordinateSequence* bufferPts,
127 std::vector<CoordinateSequence*>& rawOffsetList);
128
129 int markMatchingSegments(const Coordinate& p0, const Coordinate& p1,
130 SegmentMCIndex& segIndex, const CoordinateSequence* bufferPts,
131 std::vector<bool>& isInCurve);
132
133 static double subsegmentMatchFrac(const Coordinate& p0, const Coordinate& p1,
134 const Coordinate& seg0, const Coordinate& seg1, double matchDistance);
135
145 static void extractSection(const CoordinateSequence* ring, int iStartIndex,
146 std::vector<bool>& isExtracted, std::vector<Coordinate>& extractedPoints);
147
148 static std::size_t next(std::size_t i, std::size_t size);
149
150
151 /* private */
152 class MatchCurveSegmentAction : public index::chain::MonotoneChainSelectAction
153 {
154
155 private:
156
157 const Coordinate& p0;
158 const Coordinate& p1;
159 const CoordinateSequence* bufferPts;
160 double matchDistance;
161 std::vector<bool>& isInCurve;
162 double minFrac = -1;
163 int minCurveIndex = -1;
164
165 public:
166
167 MatchCurveSegmentAction(
168 const Coordinate& p_p0, const Coordinate& p_p1,
169 const CoordinateSequence* p_bufferPts, double p_matchDistance,
170 std::vector<bool>& p_isInCurve)
171 : p0(p_p0)
172 , p1(p_p1)
173 , bufferPts(p_bufferPts)
174 , matchDistance(p_matchDistance)
175 , isInCurve(p_isInCurve)
176 , minFrac(-1)
177 , minCurveIndex(-1)
178 {};
179
180 void select(const index::chain::MonotoneChain& mc, std::size_t segIndex) override;
181 void select(const geom::LineSegment& seg) override { (void)seg; return; };
182
183 int getMinCurveIndex() { return minCurveIndex; }
184 };
185
186
187public:
188
199 OffsetCurve(const Geometry& geom, double dist)
200 : inputGeom(geom)
201 , distance(dist)
202 , matchDistance(std::abs(dist)/NEARNESS_FACTOR)
203 , geomFactory(geom.getFactory())
204 {};
205
215 OffsetCurve(const Geometry& geom, double dist, BufferParameters& bp)
216 : inputGeom(geom)
217 , distance(dist)
218 , bufferParams(bp)
219 , matchDistance(std::abs(dist)/NEARNESS_FACTOR)
220 , geomFactory(geom.getFactory())
221 {};
222
234 static std::unique_ptr<Geometry> getCurve(
235 const Geometry& geom,
236 double dist, int quadSegs, BufferParameters::JoinStyle joinStyle, double mitreLimit);
237
238 static std::unique_ptr<Geometry> getCurve(const Geometry& geom, double dist);
239 std::unique_ptr<Geometry> getCurve();
240
256 static void rawOffset(const LineString& geom, double dist, BufferParameters& bufParams, std::vector<CoordinateSequence*>& lineList);
257 static void rawOffset(const LineString& geom, double dist, std::vector<CoordinateSequence*>& lineList);
258
259};
260
261
262} // namespace geos::operation::buffer
263} // namespace geos::operation
264} // namespace geos
265
266#ifdef _MSC_VER
267#pragma warning(pop)
268#endif
269
270
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineSegment.h:60
Definition: LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Definition: MonotoneChainSelectAction.h:44
Monotone Chains are a way of partitioning the segments of a linestring to allow for fast searching of...
Definition: index/chain/MonotoneChain.h:85
Contains the parameters which describe how a buffer should be constructed.
Definition: BufferParameters.h:56
JoinStyle
Join styles.
Definition: BufferParameters.h:74
Definition: OffsetCurve.h:91
OffsetCurve(const Geometry &geom, double dist, BufferParameters &bp)
Definition: OffsetCurve.h:215
static std::unique_ptr< Geometry > getCurve(const Geometry &geom, double dist, int quadSegs, BufferParameters::JoinStyle joinStyle, double mitreLimit)
static void rawOffset(const LineString &geom, double dist, BufferParameters &bufParams, std::vector< CoordinateSequence * > &lineList)
OffsetCurve(const Geometry &geom, double dist)
Definition: OffsetCurve.h:199
Basic namespace for all GEOS functionalities.
Definition: geos.h:39