GEOS 3.14.0dev
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
19#include <geos/operation/buffer/BufferParameters.h>
20#include <geos/geom/GeometryFactory.h>
21#include <geos/constants.h>
22
23// Forward declarations
24namespace geos {
25namespace geom {
26class Coordinate;
27class CoordinateSequence;
28class Geometry;
29class LineString;
30class Polygon;
31}
32namespace operation {
33namespace buffer {
34class OffsetCurveSection;
35class SegmentMCIndex;
36}
37}
38}
39
40namespace geos {
41namespace operation {
42namespace buffer {
43
83class GEOS_DLL OffsetCurve {
90
91private:
92
93 // Members
94 const Geometry& inputGeom;
95 double distance;
96 bool isJoined = false;
97
98 BufferParameters bufferParams;
99 double matchDistance;
100 const GeometryFactory* geomFactory;
101
102 // Methods
103
104 std::unique_ptr<Geometry> computePolygonCurve(
105 const Polygon& polyGeom, double distance);
106
107 std::unique_ptr<Geometry> computeCurve(
108 const LineString& lineGeom, double distance);
109
110 std::vector<std::unique_ptr<OffsetCurveSection>> computeSections(
111 const LineString& lineGeom, double distance);
112
113 std::unique_ptr<LineString> offsetSegment(
114 const CoordinateSequence* pts, double distance);
115
116 static std::unique_ptr<Polygon> getBufferOriented(
117 const LineString& geom, double distance,
118 BufferParameters& bufParams);
119
128 static const Polygon* extractMaxAreaPolygon(const Geometry* geom);
129
130 void computeCurveSections(
131 const CoordinateSequence* bufferRingPts,
132 const CoordinateSequence& rawCurve,
133 std::vector<std::unique_ptr<OffsetCurveSection>>& sections);
134
147 std::size_t matchSegments(
148 const Coordinate& raw0, const Coordinate& raw1,
149 std::size_t rawCurveIndex,
150 SegmentMCIndex& bufferSegIndex,
151 const CoordinateSequence* bufferPts,
152 std::vector<double>& rawCurvePos);
153
154 static double segmentMatchFrac(
155 const Coordinate& p0, const Coordinate& p1,
156 const Coordinate& seg0, const Coordinate& seg1,
157 double matchDistance);
158
170 void extractSections(
171 const CoordinateSequence* ringPts,
172 std::vector<double>& rawCurveLoc,
173 std::size_t startIndex,
174 std::vector<std::unique_ptr<OffsetCurveSection>>& sections);
175
176 std::size_t findSectionStart(
177 const std::vector<double>& loc,
178 std::size_t end);
179
180 std::size_t findSectionEnd(
181 const std::vector<double>& loc,
182 std::size_t start,
183 std::size_t firstStartIndex);
184
185 static std::size_t nextIndex(std::size_t i, std::size_t size);
186 static std::size_t prevIndex(std::size_t i, std::size_t size);
187
188
189public:
190
191 // Constants
192 static constexpr int MATCH_DISTANCE_FACTOR = 10000;
193
198 static constexpr int MIN_QUADRANT_SEGMENTS = 8;
199
210 OffsetCurve(const Geometry& geom, double dist)
211 : inputGeom(geom)
212 , distance(dist)
213 , matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
214 , geomFactory(geom.getFactory())
215 {
216 if (!std::isfinite(dist)) {
217 throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
218 }
219 };
220
230 OffsetCurve(const Geometry& geom, double dist, BufferParameters& bp)
231 : inputGeom(geom)
232 , distance(dist)
233 , matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
234 , geomFactory(geom.getFactory())
235 {
236 if (!std::isfinite(dist)) {
237 throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
238 }
239 //-- set buffer params, leaving cap style as the default CAP_ROUND
240
245 int quadSegs = bp.getQuadrantSegments();
246 if (quadSegs < MIN_QUADRANT_SEGMENTS) {
247 quadSegs = MIN_QUADRANT_SEGMENTS;
248 }
249 bufferParams.setQuadrantSegments(quadSegs);
250
251 bufferParams.setJoinStyle( bp.getJoinStyle());
252 bufferParams.setMitreLimit( bp.getMitreLimit());
253 };
254
262 void setJoined(bool pIsJoined);
263
264 static std::unique_ptr<Geometry> getCurve(
265 const Geometry& geom,
266 double dist,
267 int quadSegs,
269 double mitreLimit);
270
271 static std::unique_ptr<Geometry> getCurve(
272 const Geometry& geom, double dist);
273
282 static std::unique_ptr<Geometry> getCurveJoined(
283 const Geometry& geom, double dist);
284
290 std::unique_ptr<Geometry> getCurve();
291
305 static std::unique_ptr<CoordinateSequence> rawOffsetCurve(
306 const LineString& line,
307 double distance,
308 BufferParameters& bufParams);
309
318 static std::unique_ptr<CoordinateSequence> rawOffset(
319 const LineString& line,
320 double distance);
321
322};
323
324} // namespace geos::operation::buffer
325} // namespace geos::operation
326} // namespace geos
327
328
329
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition LineString.h:66
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Contains the parameters which describe how a buffer should be constructed.
Definition BufferParameters.h:56
double getMitreLimit() const
Definition BufferParameters.h:224
void setMitreLimit(double limit)
Definition BufferParameters.h:243
JoinStyle getJoinStyle() const
Definition BufferParameters.h:199
void setJoinStyle(JoinStyle style)
Sets the join style for outside (reflex) corners between line segments.
Definition BufferParameters.h:214
int getQuadrantSegments() const
Definition BufferParameters.h:137
void setQuadrantSegments(int quadSegs)
Sets the number of line segments used to approximate an angle fillet in round joins.
JoinStyle
Join styles.
Definition BufferParameters.h:74
Definition OffsetCurve.h:83
OffsetCurve(const Geometry &geom, double dist, BufferParameters &bp)
Definition OffsetCurve.h:230
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)
static std::unique_ptr< Geometry > getCurveJoined(const Geometry &geom, double dist)
OffsetCurve(const Geometry &geom, double dist)
Definition OffsetCurve.h:210
Indicates one or more illegal arguments.
Definition IllegalArgumentException.h:33
Basic namespace for all GEOS functionalities.
Definition geos.h:39