GEOS 3.10.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#ifndef GEOS_OP_BUFFER_BUFFEROP_H
22#define GEOS_OP_BUFFER_BUFFEROP_H
23
24#include <memory> // for unique_ptr
25#include <vector> // for vector
26
27#include <geos/export.h>
28#include <geos/operation/buffer/BufferParameters.h> // for enum values
29
30#include <geos/util/TopologyException.h> // for composition
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37// Forward declarations
38namespace geos {
39namespace geom {
40class PrecisionModel;
41class Geometry;
42}
43}
44
45namespace geos {
46namespace operation { // geos.operation
47namespace buffer { // geos.operation.buffer
48
81class GEOS_DLL BufferOp {
82
83
84private:
85
92 static constexpr int MAX_PRECISION_DIGITS = 12;
93
94 const geom::Geometry* argGeom;
95
96 util::TopologyException saveException;
97
98 double distance;
99
100 BufferParameters bufParams;
101
102 std::unique_ptr<geom::Geometry> resultGeometry;
103
104 bool isInvertOrientation = false;
105
122 static double precisionScaleFactor(const geom::Geometry* g,
123 double distance, int maxPrecisionDigits);
124
125
126 void computeGeometry();
127
128 void bufferOriginalPrecision();
129
130 void bufferReducedPrecision(int precisionDigits);
131
132 void bufferReducedPrecision();
133
134 void bufferFixedPrecision(const geom::PrecisionModel& fixedPM);
135
136 static void extractPolygons(
137 geom::Geometry* poly0,
138 std::vector<std::unique_ptr<geom::Geometry>>& polys);
139
140public:
141
142 enum {
145 CAP_ROUND = BufferParameters::CAP_ROUND,
146
149 CAP_BUTT = BufferParameters::CAP_FLAT,
150
153 CAP_SQUARE = BufferParameters::CAP_SQUARE
154 };
155
168 static std::unique_ptr<geom::Geometry> bufferOp(
169 const geom::Geometry* g,
170 double distance,
171 int quadrantSegments = BufferParameters::DEFAULT_QUADRANT_SEGMENTS,
172 int endCapStyle = BufferParameters::CAP_ROUND);
173
180 :
181 argGeom(g),
182 bufParams(),
183 resultGeometry(nullptr),
184 isInvertOrientation(false)
185 {
186 }
187
196 BufferOp(const geom::Geometry* g, const BufferParameters& params)
197 :
198 argGeom(g),
199 bufParams(params),
200 resultGeometry(nullptr),
201 isInvertOrientation(false)
202 {
203 }
204
213 inline void setEndCapStyle(int nEndCapStyle);
214
220 inline void setQuadrantSegments(int nQuadrantSegments);
221
242 inline void setSingleSided(bool isSingleSided);
243
251 std::unique_ptr<geom::Geometry> getResultGeometry(double nDistance);
252
270 static std::unique_ptr<geom::Geometry> bufferByZero(
271 const geom::Geometry* geom,
272 bool isBothOrientations);
273
274};
275
276// BufferOp inlines
277void
279{
280 bufParams.setQuadrantSegments(q);
281}
282
283void
285{
287}
288
289void
290BufferOp::setSingleSided(bool isSingleSided)
291{
292 bufParams.setSingleSided(isSingleSided);
293}
294
295} // namespace geos::operation::buffer
296} // namespace geos::operation
297} // namespace geos
298
299#ifdef _MSC_VER
300#pragma warning(pop)
301#endif
302
303#endif // ndef GEOS_OP_BUFFER_BUFFEROP_H
304
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:87
Computes the buffer of a geometry, for both positive and negative buffer distances.
Definition: BufferOp.h:81
void setQuadrantSegments(int nQuadrantSegments)
Sets the number of segments used to approximate a angle fillet.
Definition: BufferOp.h:278
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:284
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:290
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:196
BufferOp(const geom::Geometry *g)
Initializes a buffer computation for the given geometry.
Definition: BufferOp.h:179
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:57
void setEndCapStyle(EndCapStyle style)
Definition: BufferParameters.h:202
EndCapStyle
End cap styles.
Definition: BufferParameters.h:62
void setQuadrantSegments(int quadSegs)
Sets the number of line segments used to approximate an angle fillet.
void setSingleSided(bool p_isSingleSided)
Definition: BufferParameters.h:279
Indicates an invalid or inconsistent topological situation encountered during processing.
Definition: TopologyException.h:35
Basic namespace for all GEOS functionalities.
Definition: geos.h:40