GEOS  3.8.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 #ifndef GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H
20 #define GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H
21 
22 #include <geos/export.h>
23 
24 #include <vector>
25 
26 #include <geos/algorithm/LineIntersector.h> // for composition
27 #include <geos/geom/Coordinate.h> // for composition
28 #include <geos/geom/LineSegment.h> // for composition
29 #include <geos/operation/buffer/BufferParameters.h> // for composition
30 #include <geos/operation/buffer/OffsetSegmentString.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
38 namespace geos {
39 namespace geom {
40 class CoordinateSequence;
41 class PrecisionModel;
42 }
43 }
44 
45 namespace geos {
46 namespace operation { // geos.operation
47 namespace buffer { // geos.operation.buffer
48 
61 class GEOS_DLL OffsetSegmentGenerator {
62 
63 public:
64 
65  /*
66  * @param nBufParams buffer parameters, this object will
67  * keep a reference to the passed parameters
68  * so caller must make sure the object is
69  * kept alive for the whole lifetime of
70  * the buffer builder.
71  */
72  OffsetSegmentGenerator(const geom::PrecisionModel* newPrecisionModel,
73  const BufferParameters& bufParams, double distance);
74 
87  bool
89  {
90  return _hasNarrowConcaveAngle;
91  }
92 
93  void initSideSegments(const geom::Coordinate& nS1,
94  const geom::Coordinate& nS2, int nSide);
95 
97  //
104  void
105  getCoordinates(std::vector<geom::CoordinateSequence*>& to)
106  {
107  to.push_back(segList.getCoordinates());
108  }
109 
110  void
111  closeRing()
112  {
113  segList.closeRing();
114  }
115 
117  void createCircle(const geom::Coordinate& p, double distance);
118 
120  void createSquare(const geom::Coordinate& p, double distance);
121 
123  void
125  {
126  segList.addPt(offset1.p0);
127  }
128 
130  void
132  {
133  segList.addPt(offset1.p1);
134  }
135 
136  void addNextSegment(const geom::Coordinate& p, bool addStartPoint);
137 
141  void addLineEndCap(const geom::Coordinate& p0,
142  const geom::Coordinate& p1);
143 
144  void
145  addSegments(const geom::CoordinateSequence& pts, bool isForward)
146  {
147  segList.addPts(pts, isForward);
148  }
149 
150 private:
151 
156  static const double OFFSET_SEGMENT_SEPARATION_FACTOR; // 1.0E-3;
157 
162  static const double INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-3;
163 
167  static const double CURVE_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-6;
168 
172  static const int MAX_CLOSING_SEG_LEN_FACTOR = 80;
173 
178  double maxCurveSegmentError; // 0.0
179 
184  double filletAngleQuantum;
185 
203  int closingSegLengthFactor; // 1;
204 
206  //
213  OffsetSegmentString segList;
214 
215  double distance;
216 
217  const geom::PrecisionModel* precisionModel;
218 
219  const BufferParameters& bufParams;
220 
222 
223  geom::Coordinate s0, s1, s2;
224 
225  geom::LineSegment seg0;
226 
227  geom::LineSegment seg1;
228 
229  geom::LineSegment offset0;
230 
231  geom::LineSegment offset1;
232 
233  int side;
234 
235  bool _hasNarrowConcaveAngle; // =false
236 
237  void addCollinear(bool addStartPoint);
238 
240  //
245  void addMitreJoin(const geom::Coordinate& p,
246  const geom::LineSegment& offset0,
247  const geom::LineSegment& offset1,
248  double distance);
249 
251  //
260  void addLimitedMitreJoin(
261  const geom::LineSegment& offset0,
262  const geom::LineSegment& offset1,
263  double distance, double mitreLimit);
264 
268  //
272  void addBevelJoin(const geom::LineSegment& offset0,
273  const geom::LineSegment& offset1);
274 
275  static const double PI; // 3.14159265358979
276 
277  // Not in JTS, used for single-sided buffers
278  int endCapIndex;
279 
280  void init(double newDistance);
281 
289  static const double SIMPLIFY_FACTOR; // 100.0;
290 
292  //
296  void addOutsideTurn(int orientation, bool addStartPoint);
297 
299  //
303  void addInsideTurn(int orientation, bool addStartPoint);
304 
317  void computeOffsetSegment(const geom::LineSegment& seg,
318  int side, double distance,
319  geom::LineSegment& offset);
320 
332  void addFillet(const geom::Coordinate& p, const geom::Coordinate& p0,
333  const geom::Coordinate& p1,
334  int direction, double radius);
335 
345  void addFillet(const geom::Coordinate& p, double startAngle,
346  double endAngle, int direction, double radius);
347 private:
348  // An OffsetSegmentGenerator cannot be copied because of member "const BufferParameters& bufParams"
349  // Not declaring these functions triggers MSVC warning C4512: "assignment operator could not be generated"
350  OffsetSegmentGenerator(const OffsetSegmentGenerator&);
351  void operator=(const OffsetSegmentGenerator&);
352 
353 };
354 
355 } // namespace geos::operation::buffer
356 } // namespace geos::operation
357 } // namespace geos
358 
359 #ifdef _MSC_VER
360 #pragma warning(pop)
361 #endif
362 
363 #endif // ndef GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H
364 
Definition: LineSegment.h:57
Definition: OffsetSegmentGenerator.h:61
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:87
void getCoordinates(std::vector< geom::CoordinateSequence * > &to)
Get coordinates by taking ownership of them.
Definition: OffsetSegmentGenerator.h:105
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:49
void addLastSegment()
Add last offset point.
Definition: OffsetSegmentGenerator.h:131
bool hasNarrowConcaveAngle() const
Definition: OffsetSegmentGenerator.h:88
void addFirstSegment()
Add first offset point.
Definition: OffsetSegmentGenerator.h:124
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
Contains the parameters which describe how a buffer should be constructed.
Definition: BufferParameters.h:57
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58