GEOS 3.11.1
BufferOp.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2009-2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2005-2007 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: operation/buffer/BufferOp.java r378 (JTS-1.12)
18 *
19 **********************************************************************/
20
21#pragma once
22
23#include <memory> // for unique_ptr
24#include <vector> // for vector
25
26#include <geos/export.h>
27#include <geos/operation/buffer/BufferParameters.h> // for enum values
28
29#include <geos/util/TopologyException.h> // for composition
30
31#ifdef _MSC_VER
32#pragma warning(push)
33#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34#endif
35
36// Forward declarations
37namespace geos {
38namespace geom {
39class PrecisionModel;
40class Geometry;
41}
42}
43
44namespace geos {
45namespace operation { // geos.operation
46namespace buffer { // geos.operation.buffer
47
80class GEOS_DLL BufferOp {
81
82
83private:
84
91 static constexpr int MAX_PRECISION_DIGITS = 12;
92
93 const geom::Geometry* argGeom;
94
95 util::TopologyException saveException;
96
97 double distance;
98
99 BufferParameters bufParams;
100
101 std::unique_ptr<geom::Geometry> resultGeometry;
102
103 bool isInvertOrientation = false;
104
121 static double precisionScaleFactor(const geom::Geometry* g,
122 double distance, int maxPrecisionDigits);
123
124
125 void computeGeometry();
126
127 void bufferOriginalPrecision();
128
129 void bufferReducedPrecision(int precisionDigits);
130
131 void bufferReducedPrecision();
132
133 void bufferFixedPrecision(const geom::PrecisionModel& fixedPM);
134
135 static void extractPolygons(
136 geom::Geometry* poly0,
137 std::vector<std::unique_ptr<geom::Geometry>>& polys);
138
139public:
140
141 enum {
145
149
153 };
154
167 static std::unique_ptr<geom::Geometry> bufferOp(
168 const geom::Geometry* g,
169 double distance,
170 int quadrantSegments = BufferParameters::DEFAULT_QUADRANT_SEGMENTS,
171 int endCapStyle = BufferParameters::CAP_ROUND);
172
173 static std::unique_ptr<geom::Geometry> bufferOp(
174 const geom::Geometry* g,
175 double distance,
176 BufferParameters& bufParms);
177
184 :
185 argGeom(g),
186 bufParams(),
187 resultGeometry(nullptr),
188 isInvertOrientation(false)
189 {
190 }
191
200 BufferOp(const geom::Geometry* g, const BufferParameters& params)
201 :
202 argGeom(g),
203 bufParams(params),
204 resultGeometry(nullptr),
205 isInvertOrientation(false)
206 {
207 }
208
217 inline void setEndCapStyle(int nEndCapStyle);
218
224 inline void setQuadrantSegments(int nQuadrantSegments);
225
246 inline void setSingleSided(bool isSingleSided);
247
255 std::unique_ptr<geom::Geometry> getResultGeometry(double nDistance);
256
274 static std::unique_ptr<geom::Geometry> bufferByZero(
275 const geom::Geometry* geom,
276 bool isBothOrientations);
277
278};
279
280// BufferOp inlines
281void
283{
284 bufParams.setQuadrantSegments(q);
285}
286
287void
289{
291}
292
293void
294BufferOp::setSingleSided(bool isSingleSided)
295{
296 bufParams.setSingleSided(isSingleSided);
297}
298
299} // namespace geos::operation::buffer
300} // namespace geos::operation
301} // namespace geos
302
303#ifdef _MSC_VER
304#pragma warning(pop)
305#endif
306
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:90
Computes the buffer of a geometry, for both positive and negative buffer distances.
Definition: BufferOp.h:80
void setQuadrantSegments(int nQuadrantSegments)
Sets the number of segments used to approximate a angle fillet.
Definition: BufferOp.h:282
std::unique_ptr< geom::Geometry > getResultGeometry(double nDistance)
Returns the buffer computed for a geometry for a given buffer distance.
void setEndCapStyle(int nEndCapStyle)
Specifies the end cap style of the generated buffer.
Definition: BufferOp.h:288
static std::unique_ptr< geom::Geometry > bufferOp(const geom::Geometry *g, double distance, int quadrantSegments=BufferParameters::DEFAULT_QUADRANT_SEGMENTS, int endCapStyle=BufferParameters::CAP_ROUND)
Computes the buffer for a geometry for a given buffer distance and accuracy of approximation.
void setSingleSided(bool isSingleSided)
Sets whether the computed buffer should be single-sided.
Definition: BufferOp.h:294
BufferOp(const geom::Geometry *g, const BufferParameters &params)
Initializes a buffer computation for the given geometry with the given set of parameters.
Definition: BufferOp.h:200
BufferOp(const geom::Geometry *g)
Initializes a buffer computation for the given geometry.
Definition: BufferOp.h:183
static std::unique_ptr< geom::Geometry > bufferByZero(const geom::Geometry *geom, bool isBothOrientations)
Contains the parameters which describe how a buffer should be constructed.
Definition: BufferParameters.h:56
void setEndCapStyle(EndCapStyle style)
Definition: BufferParameters.h:201
EndCapStyle
End cap styles.
Definition: BufferParameters.h:61
@ CAP_SQUARE
Specifies a square line buffer end cap style.
Definition: BufferParameters.h:70
@ CAP_ROUND
Specifies a round line buffer end cap style.
Definition: BufferParameters.h:64
@ CAP_FLAT
Specifies a flat line buffer end cap style.
Definition: BufferParameters.h:67
static const int DEFAULT_QUADRANT_SEGMENTS
The default number of facets into which to divide a fillet of 90 degrees.
Definition: BufferParameters.h:94
void setQuadrantSegments(int quadSegs)
Sets the number of line segments used to approximate an angle fillet.
void setSingleSided(bool p_isSingleSided)
Definition: BufferParameters.h:278
Indicates an invalid or inconsistent topological situation encountered during processing.
Definition: TopologyException.h:34
Basic namespace for all GEOS functionalities.
Definition: geos.h:39