GEOS  3.6.1
LineIntersector.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2005-2006 Refractions Research Inc.
7  * Copyright (C) 2001-2002 Vivid Solutions Inc.
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: algorithm/RobustLineIntersector.java r785 (JTS-1.13+)
17  *
18  **********************************************************************/
19 
20 #ifndef GEOS_ALGORITHM_LINEINTERSECTOR_H
21 #define GEOS_ALGORITHM_LINEINTERSECTOR_H
22 
23 #include <geos/export.h>
24 #include <string>
25 
26 #include <geos/geom/Coordinate.h>
27 
28 // Forward declarations
29 namespace geos {
30  namespace geom {
31  class PrecisionModel;
32  }
33 }
34 
35 namespace geos {
36 namespace algorithm { // geos::algorithm
37 
49 class GEOS_DLL LineIntersector {
50 public:
51 
55  static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0, const geom::Coordinate &p1);
56 
57 
59  //
76  static double computeEdgeDistance(const geom::Coordinate& p, const geom::Coordinate& p0, const geom::Coordinate& p1);
77 
78  static double nonRobustComputeEdgeDistance(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
79 
80  LineIntersector(const geom::PrecisionModel* initialPrecisionModel=NULL)
81  :
82  precisionModel(initialPrecisionModel),
83  result(0),
84  isProperVar(false)
85  {}
86 
87  ~LineIntersector() {}
88 
96  bool isInteriorIntersection();
97 
105  bool isInteriorIntersection(int inputLineIndex);
106 
108  //
114  precisionModel=newPM;
115  }
116 
118  //
123  void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
124 
126  static bool hasIntersection(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
127 
128  // These are deprecated, due to ambiguous naming
129  enum {
130  DONT_INTERSECT=0,
131  DO_INTERSECT=1,
132  COLLINEAR=2
133  };
134 
135  enum {
137  NO_INTERSECTION=0,
138 
140  POINT_INTERSECTION=1,
141 
143  COLLINEAR_INTERSECTION=2
144  };
145 
147  void computeIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
148  const geom::Coordinate& p3, const geom::Coordinate& p4);
149 
150  std::string toString() const;
151 
157  bool hasIntersection() const { return result!=NO_INTERSECTION; }
158 
160  //
163  int getIntersectionNum() const { return result; }
164 
165 
167  //
172  const geom::Coordinate& getIntersection(int intIndex) const {
173  return intPt[intIndex];
174  }
175 
177  //
180  static bool isSameSignAndNonZero(double a,double b);
181 
192  bool isIntersection(const geom::Coordinate& pt) const;
193 
208  bool isProper() const {
209  return hasIntersection()&&isProperVar;
210  }
211 
222  const geom::Coordinate& getIntersectionAlongSegment(int segmentIndex,int intIndex);
223 
233  int getIndexAlongSegment(int segmentIndex,int intIndex);
234 
244  double getEdgeDistance(int geomIndex,int intIndex) const;
245 
246 private:
247 
248  void intersectionWithNormalization(const geom::Coordinate& p1,
249  const geom::Coordinate& p2,
250  const geom::Coordinate& q1,
251  const geom::Coordinate& q2,
252  geom::Coordinate &ret) const;
253 
258  const geom::PrecisionModel *precisionModel;
259 
260  int result;
261 
262  const geom::Coordinate *inputLines[2][2];
263 
268  geom::Coordinate intPt[2];
269 
274  int intLineIndex[2][2];
275 
276  bool isProperVar;
277  //Coordinate &pa;
278  //Coordinate &pb;
279 
280  bool isCollinear() const { return result==COLLINEAR_INTERSECTION; }
281 
282  int computeIntersect(const geom::Coordinate& p1,const geom::Coordinate& p2,const geom::Coordinate& q1,const geom::Coordinate& q2);
283 
284  bool isEndPoint() const {
285  return hasIntersection()&&!isProperVar;
286  }
287 
288  void computeIntLineIndex();
289 
290  void computeIntLineIndex(int segmentIndex);
291 
292  int computeCollinearIntersection(const geom::Coordinate& p1,
293  const geom::Coordinate& p2, const geom::Coordinate& q1,
294  const geom::Coordinate& q2);
295 
305  void intersection(const geom::Coordinate& p1,
306  const geom::Coordinate& p2,
307  const geom::Coordinate& q1,
308  const geom::Coordinate& q2,
309  geom::Coordinate &ret) const;
310 
311  double smallestInAbsValue(double x1, double x2,
312  double x3, double x4) const;
313 
324  bool isInSegmentEnvelopes(const geom::Coordinate& intPt) const;
325 
337  void normalizeToEnvCentre(geom::Coordinate &n00, geom::Coordinate &n01,
338  geom::Coordinate &n10, geom::Coordinate &n11,
339  geom::Coordinate &normPt) const;
340 
353  void safeHCoordinateIntersection(const geom::Coordinate& p1,
354  const geom::Coordinate& p2,
355  const geom::Coordinate& q1,
356  const geom::Coordinate& q2,
357  geom::Coordinate& intPt) const;
358 
359 };
360 
361 } // namespace geos::algorithm
362 } // namespace geos
363 
364 
365 #endif // GEOS_ALGORITHM_LINEINTERSECTOR_H
366 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
const geom::Coordinate & getIntersection(int intIndex) const
Returns the intIndex&#39;th intersection point.
Definition: LineIntersector.h:172
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:87
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:49
int getIntersectionNum() const
Returns the number of intersection points found.
Definition: LineIntersector.h:163
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
bool isProper() const
Tests whether an intersection is proper.
Definition: LineIntersector.h:208
bool hasIntersection() const
Definition: LineIntersector.h:157
void setPrecisionModel(const geom::PrecisionModel *newPM)
Force computed intersection to be rounded to a given precision model.
Definition: LineIntersector.h:113