GEOS  3.3.3
OffsetSegmentGenerator.h
1 /**********************************************************************
2  * $Id$
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
12  * See the COPYING file for more information.
13  *
14  **********************************************************************
15  *
16  * Last port: operation/buffer/OffsetSegmentGenerator.java r378 (JTS-1.12)
17  *
18  **********************************************************************/
19 
20 #ifndef GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H
21 #define GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H
22 
23 #include <geos/export.h>
24 
25 #include <vector>
26 
27 #include <geos/algorithm/LineIntersector.h> // for composition
28 #include <geos/geom/Coordinate.h> // for composition
29 #include <geos/geom/LineSegment.h> // for composition
30 #include <geos/operation/buffer/BufferParameters.h> // for composition
31 #include <geos/operation/buffer/OffsetSegmentString.h> // for composition
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40  namespace geom {
41  class CoordinateSequence;
42  class PrecisionModel;
43  }
44 }
45 
46 namespace geos {
47 namespace operation { // geos.operation
48 namespace buffer { // geos.operation.buffer
49 
62 class GEOS_DLL OffsetSegmentGenerator {
63 
64 public:
65 
66  /*
67  * @param nBufParams buffer parameters, this object will
68  * keep a reference to the passed parameters
69  * so caller must make sure the object is
70  * kept alive for the whole lifetime of
71  * the buffer builder.
72  */
73  OffsetSegmentGenerator(const geom::PrecisionModel *newPrecisionModel,
74  const BufferParameters& bufParams, double distance);
75 
88  bool hasNarrowConcaveAngle() const
89  {
90  return _hasNarrowConcaveAngle;
91  }
92 
93  void initSideSegments(const geom::Coordinate &nS1,
94  const geom::Coordinate &nS2, int nSide);
95 
97  //
104  void getCoordinates(std::vector<geom::CoordinateSequence*>& to) {
105  to.push_back(segList.getCoordinates());
106  }
107 
108  void closeRing() {
109  segList.closeRing();
110  }
111 
113  void createCircle(const geom::Coordinate &p, double distance);
114 
116  void createSquare(const geom::Coordinate &p, double distance);
117 
119  void addFirstSegment()
120  {
121  segList.addPt(offset1.p0);
122  }
123 
125  void addLastSegment()
126  {
127  segList.addPt(offset1.p1);
128  }
129 
130  void addNextSegment(const geom::Coordinate &p, bool addStartPoint);
131 
135  void addLineEndCap(const geom::Coordinate &p0,
136  const geom::Coordinate &p1);
137 
138  void addSegments(const geom::CoordinateSequence& pts, bool isForward)
139  {
140  segList.addPts(pts, isForward);
141  }
142 
143 private:
144 
149  static const double OFFSET_SEGMENT_SEPARATION_FACTOR; // 1.0E-3;
150 
155  static const double INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-3;
156 
160  static const double CURVE_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-6;
161 
165  static const int MAX_CLOSING_SEG_LEN_FACTOR = 80;
166 
171  double maxCurveSegmentError; // 0.0
172 
177  double filletAngleQuantum;
178 
196  int closingSegLengthFactor; // 1;
197 
199  //
206  OffsetSegmentString segList;
207 
208  double distance;
209 
210  const geom::PrecisionModel* precisionModel;
211 
212  const BufferParameters& bufParams;
213 
215 
216  geom::Coordinate s0, s1, s2;
217 
218  geom::LineSegment seg0;
219 
220  geom::LineSegment seg1;
221 
222  geom::LineSegment offset0;
223 
224  geom::LineSegment offset1;
225 
226  int side;
227 
228  bool _hasNarrowConcaveAngle; // =false
229 
230  void addCollinear(bool addStartPoint);
231 
233  //
238  void addMitreJoin(const geom::Coordinate& p,
239  const geom::LineSegment& offset0,
240  const geom::LineSegment& offset1,
241  double distance);
242 
244  //
253  void addLimitedMitreJoin(
254  const geom::LineSegment& offset0,
255  const geom::LineSegment& offset1,
256  double distance, double mitreLimit);
257 
261  //
265  void addBevelJoin(const geom::LineSegment& offset0,
266  const geom::LineSegment& offset1);
267 
268  static const double PI; // 3.14159265358979
269 
270  // Not in JTS, used for single-sided buffers
271  int endCapIndex;
272 
273  void init(double newDistance);
274 
282  static const double SIMPLIFY_FACTOR; // 100.0;
283 
285  //
289  void addOutsideTurn(int orientation, bool addStartPoint);
290 
292  //
296  void addInsideTurn(int orientation, bool addStartPoint);
297 
310  void computeOffsetSegment(const geom::LineSegment& seg,
311  int side, double distance,
312  geom::LineSegment& offset);
313 
325  void addFillet(const geom::Coordinate &p, const geom::Coordinate &p0,
326  const geom::Coordinate &p1,
327  int direction, double radius);
328 
338  void addFillet(const geom::Coordinate &p, double startAngle,
339  double endAngle, int direction, double radius);
340 private:
341  // An OffsetSegmentGenerator cannot be copied because of member "const BufferParameters& bufParams"
342  // Not declaring these functions triggers MSVC warning C4512: "assignment operator could not be generated"
343  OffsetSegmentGenerator(const OffsetSegmentGenerator&);
344  void operator=(const OffsetSegmentGenerator&);
345 
346 };
347 
348 } // namespace geos::operation::buffer
349 } // namespace geos::operation
350 } // namespace geos
351 
352 #ifdef _MSC_VER
353 #pragma warning(pop)
354 #endif
355 
356 #endif // ndef GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H
357