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> computeCurve(
105 const LineString& lineGeom, double distance);
106
107 std::vector<std::unique_ptr<OffsetCurveSection>> computeSections(
108 const LineString& lineGeom, double distance);
109
110 std::unique_ptr<LineString> offsetSegment(
111 const CoordinateSequence* pts, double distance);
112
113 static std::unique_ptr<Polygon> getBufferOriented(
114 const LineString& geom, double distance,
115 BufferParameters& bufParams);
116
125 static const Polygon* extractMaxAreaPolygon(const Geometry* geom);
126
127 void computeCurveSections(
128 const CoordinateSequence* bufferRingPts,
129 const CoordinateSequence& rawCurve,
130 std::vector<std::unique_ptr<OffsetCurveSection>>& sections);
131
144 std::size_t matchSegments(
145 const Coordinate& raw0, const Coordinate& raw1,
146 std::size_t rawCurveIndex,
147 SegmentMCIndex& bufferSegIndex,
148 const CoordinateSequence* bufferPts,
149 std::vector<double>& rawCurvePos);
150
151 static double segmentMatchFrac(
152 const Coordinate& p0, const Coordinate& p1,
153 const Coordinate& seg0, const Coordinate& seg1,
154 double matchDistance);
155
167 void extractSections(
168 const CoordinateSequence* ringPts,
169 std::vector<double>& rawCurveLoc,
170 std::size_t startIndex,
171 std::vector<std::unique_ptr<OffsetCurveSection>>& sections);
172
173 std::size_t findSectionStart(
174 const std::vector<double>& loc,
175 std::size_t end);
176
177 std::size_t findSectionEnd(
178 const std::vector<double>& loc,
179 std::size_t start,
180 std::size_t firstStartIndex);
181
182 static std::size_t nextIndex(std::size_t i, std::size_t size);
183 static std::size_t prevIndex(std::size_t i, std::size_t size);
184
185
186public:
187
188 // Constants
189 static constexpr int MATCH_DISTANCE_FACTOR = 10000;
190
195 static constexpr int MIN_QUADRANT_SEGMENTS = 8;
196
207 OffsetCurve(const Geometry& geom, double dist)
208 : inputGeom(geom)
209 , distance(dist)
210 , matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
211 , geomFactory(geom.getFactory())
212 {
213 if (!std::isfinite(dist)) {
214 throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
215 }
216 };
217
227 OffsetCurve(const Geometry& geom, double dist, BufferParameters& bp)
228 : inputGeom(geom)
229 , distance(dist)
230 , matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
231 , geomFactory(geom.getFactory())
232 {
233 if (!std::isfinite(dist)) {
234 throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
235 }
236 //-- set buffer params, leaving cap style as the default CAP_ROUND
237
242 int quadSegs = bp.getQuadrantSegments();
243 if (quadSegs < MIN_QUADRANT_SEGMENTS) {
244 quadSegs = MIN_QUADRANT_SEGMENTS;
245 }
246 bufferParams.setQuadrantSegments(quadSegs);
247
248 bufferParams.setJoinStyle( bp.getJoinStyle());
249 bufferParams.setMitreLimit( bp.getMitreLimit());
250 };
251
259 void setJoined(bool pIsJoined);
260
261 static std::unique_ptr<Geometry> getCurve(
262 const Geometry& geom,
263 double dist,
264 int quadSegs,
266 double mitreLimit);
267
268 static std::unique_ptr<Geometry> getCurve(
269 const Geometry& geom, double dist);
270
279 static std::unique_ptr<Geometry> getCurveJoined(
280 const Geometry& geom, double dist);
281
287 std::unique_ptr<Geometry> getCurve();
288
302 static std::unique_ptr<CoordinateSequence> rawOffsetCurve(
303 const LineString& line,
304 double distance,
305 BufferParameters& bufParams);
306
315 static std::unique_ptr<CoordinateSequence> rawOffset(
316 const LineString& line,
317 double distance);
318
319};
320
321} // namespace geos::operation::buffer
322} // namespace geos::operation
323} // namespace geos
324
325
326
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:227
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:207
Indicates one or more illegal arguments.
Definition IllegalArgumentException.h:33
Basic namespace for all GEOS functionalities.
Definition geos.h:39