GEOS 3.15.0dev
OffsetSegmentGenerator.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 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/OffsetSegmentGenerator.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#include <geos/operation/buffer/BufferParameters.h> // for composition
29#include <geos/operation/buffer/OffsetSegmentString.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 CoordinateSequence;
40class PrecisionModel;
41}
42}
43
44namespace geos {
45namespace operation { // geos.operation
46namespace buffer { // geos.operation.buffer
47
60class GEOS_DLL OffsetSegmentGenerator {
61
62public:
63
64 /*
65 * @param nBufParams buffer parameters, this object will
66 * keep a reference to the passed parameters
67 * so caller must make sure the object is
68 * kept alive for the whole lifetime of
69 * the buffer builder.
70 */
71 OffsetSegmentGenerator(const geom::PrecisionModel* newPrecisionModel,
72 const BufferParameters& bufParams, double distance);
73
86 bool
88 {
89 return _hasNarrowConcaveAngle;
90 }
91
92 void initSideSegments(const geom::Coordinate& nS1,
93 const geom::Coordinate& nS2, int nSide);
94
103 void
104 getCoordinates(std::vector<std::unique_ptr<geom::CoordinateSequence>>& to)
105 {
106 to.emplace_back(segList.getCoordinates());
107 }
108
109 std::unique_ptr<geom::CoordinateSequence>
110 getCoordinates()
111 {
112 return std::unique_ptr<geom::CoordinateSequence>(segList.getCoordinates());
113 }
114
115 void
116 closeRing()
117 {
118 segList.closeRing();
119 }
120
122 void createCircle(const geom::Coordinate& p, double distance);
123
125 void createSquare(const geom::Coordinate& p, double distance);
126
128 void
130 {
131 segList.addPt(offset1.p0);
132 }
133
135 void
137 {
138 segList.addPt(offset1.p1);
139 }
140
141 void addNextSegment(const geom::Coordinate& p, bool addStartPoint);
142
147 const geom::Coordinate& p1,
148 const geom::Coordinate& p2);
149
150 void
151 addSegments(const geom::CoordinateSequence& pts, bool isForward)
152 {
153 segList.addPts(pts, isForward);
154 }
155
169 int side, double distance,
170 geom::LineSegment& offset);
171
172private:
173
178 static const double OFFSET_SEGMENT_SEPARATION_FACTOR; // 1.0E-3;
179
184 static const double INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-3;
185
189 static const double CURVE_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-6;
190
194 static const int MAX_CLOSING_SEG_LEN_FACTOR = 80;
195
200 double maxCurveSegmentError; // 0.0
201
206 double filletAngleQuantum;
207
225 int closingSegLengthFactor; // 1;
226
235 OffsetSegmentString segList;
236
237 double distance;
238
239 const geom::PrecisionModel* precisionModel;
240
241 const BufferParameters& bufParams;
242
244
245 geom::Coordinate s0, s1, s2;
246
248
250
251 geom::LineSegment offset0;
252
253 geom::LineSegment offset1;
254
255 int side;
256
257 bool _hasNarrowConcaveAngle; // =false
258
259 void addCollinear(bool addStartPoint);
260
267 void addMitreJoin(const geom::Coordinate& cornerPt,
268 const geom::LineSegment& offset0,
269 const geom::LineSegment& offset1,
270 double distance);
271
272
283 void addLimitedMitreJoin(
284 const geom::LineSegment& offset0,
285 const geom::LineSegment& offset1,
286 double distance,
287 double mitreLimitDistance);
288
296 static geom::LineSegment extend(const geom::LineSegment& seg, double dist);
297
308 static geom::Coordinate project(const geom::Coordinate& pt, double d, double dir);
309
317 void addBevelJoin(const geom::LineSegment& offset0,
318 const geom::LineSegment& offset1);
319
320 static const double PI; // 3.14159265358979
321
322 // Not in JTS, used for single-sided buffers
323 int endCapIndex;
324
325 void init(double newDistance);
326
334 static const double SIMPLIFY_FACTOR; // 100.0;
335
341 void addOutsideTurn(int orientation, bool addStartPoint);
342
348 void addInsideTurn(int orientation, bool addStartPoint);
349
361 void addDirectedFillet(const geom::Coordinate& p, const geom::Coordinate& p0,
362 const geom::Coordinate& p1,
363 int direction, double radius);
364
374 void addDirectedFillet(const geom::Coordinate& p, double startAngle,
375 double endAngle, int direction, double radius);
376private:
377 // An OffsetSegmentGenerator cannot be copied because of member "const BufferParameters& bufParams"
378 // Not declaring these functions triggers MSVC warning C4512: "assignment operator could not be generated"
380 void operator=(const OffsetSegmentGenerator&);
381
382};
383
384} // namespace geos::operation::buffer
385} // namespace geos::operation
386} // namespace geos
387
388#ifdef _MSC_VER
389#pragma warning(pop)
390#endif
391
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:53
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:220
Definition LineSegment.h:61
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
Contains the parameters which describe how a buffer should be constructed.
Definition BufferParameters.h:56
Definition OffsetSegmentGenerator.h:60
void addFirstSegment()
Add first offset point.
Definition OffsetSegmentGenerator.h:129
bool hasNarrowConcaveAngle() const
Definition OffsetSegmentGenerator.h:87
void addLineEndCap(const geom::Coordinate &p0, const geom::Coordinate &p1, const geom::Coordinate &p2)
Add an end cap around point p1, terminating a line segment coming from p0.
void addLastSegment()
Add last offset point.
Definition OffsetSegmentGenerator.h:136
static void computeOffsetSegment(const geom::LineSegment &seg, int side, double distance, geom::LineSegment &offset)
Compute an offset segment for an input segment on a given side and at a given distance.
void getCoordinates(std::vector< std::unique_ptr< geom::CoordinateSequence > > &to)
Definition OffsetSegmentGenerator.h:104
void createSquare(const geom::Coordinate &p, double distance)
Adds a CW square around a point.
void createCircle(const geom::Coordinate &p, double distance)
Adds a CW circle around a point.
Definition OffsetSegmentString.h:41
Basic namespace for all GEOS functionalities.
Definition geos.h:38