GEOS  3.9.1dev
LineIntersector.h
Go to the documentation of this file.
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 
50 public:
51 
55  static double interpolateZ(const geom::Coordinate& p, const geom::Coordinate& p0, const geom::Coordinate& p1);
56 
57 
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,
79  const geom::Coordinate& p2);
80 
81  LineIntersector(const geom::PrecisionModel* initialPrecisionModel = nullptr)
82  :
83  precisionModel(initialPrecisionModel),
84  result(0),
85  isProperVar(false)
86  {}
87 
89 
97  bool isInteriorIntersection();
98 
106  bool isInteriorIntersection(size_t inputLineIndex);
107 
114  void
116  {
117  precisionModel = newPM;
118  }
119 
126  void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
127 
129  static bool hasIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
130 
131  enum intersection_type : uint8_t {
133  NO_INTERSECTION = 0,
134 
136  POINT_INTERSECTION = 1,
137 
139  COLLINEAR_INTERSECTION = 2
140  };
141 
143  void computeIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
144  const geom::Coordinate& p3, const geom::Coordinate& p4);
145 
146  std::string toString() const;
147 
153  bool
155  {
156  return result != NO_INTERSECTION;
157  }
158 
163  size_t
165  {
166  return result;
167  }
168 
169 
176  const geom::Coordinate&
177  getIntersection(size_t intIndex) const
178  {
179  return intPt[intIndex];
180  }
181 
186  static bool isSameSignAndNonZero(double a, double b);
187 
198  bool isIntersection(const geom::Coordinate& pt) const;
199 
214  bool
215  isProper() const
216  {
217  return hasIntersection() && isProperVar;
218  }
219 
230  const geom::Coordinate& getIntersectionAlongSegment(size_t segmentIndex, size_t intIndex);
231 
241  size_t getIndexAlongSegment(size_t segmentIndex, size_t intIndex);
242 
252  double getEdgeDistance(size_t geomIndex, size_t intIndex) const;
253 
254 private:
255 
261 
262  size_t result;
263 
264  const geom::Coordinate* inputLines[2][2];
265 
271 
276  size_t intLineIndex[2][2];
277 
279  //Coordinate &pa;
280  //Coordinate &pb;
281 
282  bool
283  isCollinear() const
284  {
285  return result == COLLINEAR_INTERSECTION;
286  }
287 
288  uint8_t computeIntersect(const geom::Coordinate& p1, const geom::Coordinate& p2,
289  const geom::Coordinate& q1, const geom::Coordinate& q2);
290 
291  bool
292  isEndPoint() const
293  {
294  return hasIntersection() && !isProperVar;
295  }
296 
297  void computeIntLineIndex();
298 
299  void computeIntLineIndex(size_t segmentIndex);
300 
301  uint8_t computeCollinearIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
302  const geom::Coordinate& q1, const geom::Coordinate& q2);
303 
313  geom::Coordinate intersection(const geom::Coordinate& p1,
314  const geom::Coordinate& p2,
315  const geom::Coordinate& q1,
316  const geom::Coordinate& q2) const;
317 
328  bool isInSegmentEnvelopes(const geom::Coordinate& intPt) const;
329 
330 
343  geom::Coordinate intersectionSafe(const geom::Coordinate& p1, const geom::Coordinate& p2,
344  const geom::Coordinate& q1, const geom::Coordinate& q2) const;
345 
365  static geom::Coordinate nearestEndpoint(const geom::Coordinate& p1,
366  const geom::Coordinate& p2,
367  const geom::Coordinate& q1,
368  const geom::Coordinate& q2);
369 
370  static double zGet(const geom::Coordinate& p, const geom::Coordinate& q);
371 
372  static double zGetOrInterpolate(const geom::Coordinate& p,
373  const geom::Coordinate& p0,
374  const geom::Coordinate& p1);
375 
376  static geom::Coordinate zGetOrInterpolateCopy(const geom::Coordinate& p,
377  const geom::Coordinate& p0,
378  const geom::Coordinate& p1);
379 
383  static double zInterpolate(const geom::Coordinate& p,
384  const geom::Coordinate& p0,
385  const geom::Coordinate& p1);
386 
387  static double zInterpolate(const geom::Coordinate& p,
388  const geom::Coordinate& p1,
389  const geom::Coordinate& p2,
390  const geom::Coordinate& q1,
391  const geom::Coordinate& q2);
392 
393 };
394 
395 
396 } // namespace geos::algorithm
397 } // namespace geos
398 
399 
400 #endif // GEOS_ALGORITHM_LINEINTERSECTOR_H
401 
#define GEOS_DLL
Definition: export.h:28
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Specifies the precision model of the Coordinate in a Geometry.
bool isProper() const
Tests whether an intersection is proper.
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
const geom::PrecisionModel * precisionModel
Basic namespace for all GEOS functionalities.
const geom::Coordinate & getIntersection(size_t intIndex) const
void setPrecisionModel(const geom::PrecisionModel *newPM)
LineIntersector(const geom::PrecisionModel *initialPrecisionModel=nullptr)