Coverage Report

Created: 2026-02-26 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/operation/buffer/BufferParameters.h
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2009  Sandro Santilli <strk@kbt.io>
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
 * Last port: operation/buffer/BufferParameters.java r378 (JTS-1.12)
16
 *
17
 **********************************************************************/
18
19
#pragma once
20
21
#include <geos/export.h>
22
23
//#include <vector>
24
25
//#include <geos/algorithm/LineIntersector.h> // for composition
26
//#include <geos/geom/Coordinate.h> // for composition
27
//#include <geos/geom/LineSegment.h> // for composition
28
29
#ifdef _MSC_VER
30
#pragma warning(push)
31
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32
#endif
33
34
// Forward declarations
35
namespace geos {
36
namespace geom {
37
class CoordinateSequence;
38
class PrecisionModel;
39
}
40
namespace operation {
41
namespace buffer {
42
class OffsetCurveVertexList;
43
}
44
}
45
}
46
47
namespace geos {
48
namespace operation { // geos.operation
49
namespace buffer { // geos.operation.buffer
50
51
/** \brief
52
 * Contains the parameters which
53
 * describe how a buffer should be constructed.
54
 *
55
 */
56
class GEOS_DLL BufferParameters {
57
58
public:
59
60
    /// End cap styles
61
    enum EndCapStyle {
62
63
        /// Specifies a round line buffer end cap style.
64
        CAP_ROUND = 1,
65
66
        /// Specifies a flat line buffer end cap style.
67
        CAP_FLAT = 2,
68
69
        /// Specifies a square line buffer end cap style.
70
        CAP_SQUARE = 3
71
    };
72
73
    /// Join styles
74
    enum JoinStyle {
75
76
        /// Specifies a round join style.
77
        JOIN_ROUND = 1,
78
79
        /// Specifies a mitre join style.
80
        JOIN_MITRE = 2,
81
82
        /// Specifies a bevel join style.
83
        JOIN_BEVEL = 3
84
    };
85
86
    /// \brief
87
    /// The default number of facets into which to divide a fillet
88
    /// of 90 degrees.
89
    ///
90
    /// A value of 8 gives less than 2% max error in the buffer distance.
91
    /// For a max error of < 1%, use QS = 12.
92
    /// For a max error of < 0.1%, use QS = 18.
93
    ///
94
    static const int DEFAULT_QUADRANT_SEGMENTS = 8;
95
96
    /// The default mitre limit
97
    ///
98
    /// Allows fairly pointy mitres.
99
    ///
100
    static const double DEFAULT_MITRE_LIMIT; // 5.0 (in .cpp file)
101
102
    /// Creates a default set of parameters
103
    BufferParameters();
104
105
    /// Creates a set of parameters with the given quadrantSegments value.
106
    ///
107
    /// @param quadrantSegments the number of quadrant segments to use
108
    ///
109
    BufferParameters(int quadrantSegments);
110
111
    /// \brief
112
    /// Creates a set of parameters with the
113
    /// given quadrantSegments and endCapStyle values.
114
    ///
115
    /// @param quadrantSegments the number of quadrant segments to use
116
    /// @param endCapStyle the end cap style to use
117
    ///
118
    BufferParameters(int quadrantSegments, EndCapStyle endCapStyle);
119
120
    /// \brief
121
    /// Creates a set of parameters with the
122
    /// given parameter values.
123
    ///
124
    /// @param quadrantSegments the number of quadrant segments to use
125
    /// @param endCapStyle the end cap style to use
126
    /// @param joinStyle the join style to use
127
    /// @param mitreLimit the mitre limit to use
128
    ///
129
    BufferParameters(int quadrantSegments, EndCapStyle endCapStyle,
130
                     JoinStyle joinStyle, double mitreLimit);
131
132
    /// Gets the number of quadrant segments which will be used
133
    ///
134
    /// @return the number of quadrant segments
135
    ///
136
    int
137
    getQuadrantSegments() const
138
0
    {
139
0
        return quadrantSegments;
140
0
    }
141
142
    /// \brief
143
    /// Sets the number of line segments used to approximate
144
    /// an angle fillet in round joins.
145
    ///
146
    /// <tt>quadSegs</tt> determines the maximum
147
    /// error in the approximation to the true buffer curve.
148
    /// The default value of 8 gives less than 2% max error in the
149
    /// buffer distance.
150
    /// For a max error of < 1%, use QS = 12.
151
    /// For a max error of < 0.1%, use QS = 18.
152
    /// The error is always less than the buffer distance
153
    /// (in other words, the computed buffer curve is always inside
154
    ///  the true curve).
155
    ///
156
    /// @param quadSegs the number of segments in a fillet for a quadrant
157
    void setQuadrantSegments(int quadSegs);
158
159
    /// \brief
160
    /// Computes the maximum distance error due to a given level
161
    /// of approximation to a true arc.
162
    ///
163
    /// @param quadSegs the number of segments used to approximate
164
    ///                 a quarter-circle
165
    /// @return the error of approximation
166
    ///
167
    static double bufferDistanceError(int quadSegs);
168
169
    /// Gets the end cap style.
170
    ///
171
    /// @return the end cap style
172
    ///
173
    EndCapStyle
174
    getEndCapStyle() const
175
0
    {
176
0
        return endCapStyle;
177
0
    }
178
179
    /// Specifies the end cap style of the generated buffer.
180
    ///
181
    /// The styles supported are CAP_ROUND, CAP_BUTT,
182
    /// and CAP_SQUARE.
183
    ///
184
    /// The default is CAP_ROUND.
185
    ///
186
    /// @param style the end cap style to specify
187
    ///
188
    void
189
    setEndCapStyle(EndCapStyle style)
190
0
    {
191
0
        endCapStyle = style;
192
0
    }
193
194
    /// Gets the join style.
195
    ///
196
    /// @return the join style
197
    ///
198
    JoinStyle
199
    getJoinStyle() const
200
0
    {
201
0
        return joinStyle;
202
0
    }
203
204
    /// \brief
205
    /// Sets the join style for outside (reflex) corners between
206
    /// line segments.
207
    ///
208
    /// Allowable values are JOIN_ROUND (which is the default),
209
    /// JOIN_MITRE and JOIN_BEVEL.
210
    ///
211
    /// @param style the code for the join style
212
    ///
213
    void
214
    setJoinStyle(JoinStyle style)
215
0
    {
216
0
        joinStyle = style;
217
0
    }
218
219
    /// Gets the mitre ratio limit.
220
    ///
221
    /// @return the limit value
222
    ///
223
    double
224
    getMitreLimit() const
225
0
    {
226
0
        return mitreLimit;
227
0
    }
228
229
    /// Sets the limit on the mitre ratio used for very sharp corners.
230
    ///
231
    /// The mitre ratio is the ratio of the distance from the corner
232
    /// to the end of the mitred offset corner.
233
    /// When two line segments meet at a sharp angle,
234
    /// a miter join will extend far beyond the original geometry.
235
    /// (and in the extreme case will be infinitely far.)
236
    /// To prevent unreasonable geometry, the mitre limit
237
    /// allows controlling the maximum length of the join corner.
238
    /// Corners with a ratio which exceed the limit will be beveled.
239
    ///
240
    /// @param limit the mitre ratio limit
241
    ///
242
    void
243
    setMitreLimit(double limit)
244
0
    {
245
0
        mitreLimit = limit;
246
0
    }
247
248
    /**
249
     * Sets whether the computed buffer should be single-sided.
250
     * A single-sided buffer is constructed on only one side of each input line.
251
     *
252
     * The side used is determined by the sign of the buffer distance:
253
     * - a positive distance indicates the left-hand side
254
     * - a negative distance indicates the right-hand side
255
     *
256
     * The single-sided buffer of point geometries is
257
     * the same as the regular buffer.
258
     *
259
     * The End Cap Style for single-sided buffers is
260
     * always ignored,
261
     * and forced to the equivalent of <tt>CAP_FLAT</tt>.
262
     *
263
     * @param p_isSingleSided true if a single-sided buffer should be constructed
264
     */
265
    void
266
    setSingleSided(bool p_isSingleSided)
267
0
    {
268
0
        _isSingleSided = p_isSingleSided;
269
0
    }
270
271
    /**
272
     * Tests whether the buffer is to be generated on a single side only.
273
     *
274
     * @return true if the generated buffer is to be single-sided
275
     */
276
    bool
277
    isSingleSided() const
278
0
    {
279
0
        return _isSingleSided;
280
0
    }
281
282
283
private:
284
285
    /// Defaults to DEFAULT_QUADRANT_SEGMENTS;
286
    int quadrantSegments;
287
288
    /// Defaults to CAP_ROUND;
289
    EndCapStyle endCapStyle;
290
291
    /// Defaults to JOIN_ROUND;
292
    JoinStyle joinStyle;
293
294
    /// Defaults to DEFAULT_MITRE_LIMIT;
295
    double mitreLimit;
296
297
    bool _isSingleSided;
298
};
299
300
} // namespace geos::operation::buffer
301
} // namespace geos::operation
302
} // namespace geos
303
304
#ifdef _MSC_VER
305
#pragma warning(pop)
306
#endif
307