GEOS 3.9.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
29namespace geos {
30namespace geom {
31class PrecisionModel;
32}
33}
34
35namespace geos {
36namespace algorithm { // geos::algorithm
37
49class GEOS_DLL LineIntersector {
50public:
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
98
106 bool isInteriorIntersection(size_t inputLineIndex);
107
114 void
116 {
117 precisionModel = newPM;
118 }
119
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
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
254private:
255
260 const geom::PrecisionModel* precisionModel;
261
262 size_t result;
263
264 const geom::Coordinate* inputLines[2][2];
265
270 geom::Coordinate intPt[2];
271
276 size_t intLineIndex[2][2];
277
278 bool isProperVar;
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
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:49
intersection_type
Definition LineIntersector.h:131
void computeIntersection(const geom::Coordinate &p1, const geom::Coordinate &p2, const geom::Coordinate &p3, const geom::Coordinate &p4)
Computes the intersection of the lines p1-p2 and p3-p4.
static bool hasIntersection(const geom::Coordinate &p, const geom::Coordinate &p1, const geom::Coordinate &p2)
Same as above but doesn't compute intersection point. Faster.
size_t getIndexAlongSegment(size_t segmentIndex, size_t intIndex)
Computes the index of the intIndex'th intersection point in the direction of a specified input line s...
void setPrecisionModel(const geom::PrecisionModel *newPM)
Definition LineIntersector.h:115
bool isInteriorIntersection()
Tests whether either intersection point is an interior point of one of the input segments.
const geom::Coordinate & getIntersectionAlongSegment(size_t segmentIndex, size_t intIndex)
Computes the intIndex'th intersection point in the direction of a specified input line segment.
bool isInteriorIntersection(size_t inputLineIndex)
Tests whether either intersection point is an interior point of the specified input segment.
bool hasIntersection() const
Definition LineIntersector.h:154
double getEdgeDistance(size_t geomIndex, size_t intIndex) const
Computes the "edge distance" of an intersection point along the specified input line segment.
static bool isSameSignAndNonZero(double a, double b)
void computeIntersection(const geom::Coordinate &p, const geom::Coordinate &p1, const geom::Coordinate &p2)
bool isProper() const
Tests whether an intersection is proper.
Definition LineIntersector.h:215
static double computeEdgeDistance(const geom::Coordinate &p, const geom::Coordinate &p0, const geom::Coordinate &p1)
const geom::Coordinate & getIntersection(size_t intIndex) const
Definition LineIntersector.h:177
static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0, const geom::Coordinate &p1)
Return a Z value being the interpolation of Z from p0 and p1 at the given point p.
size_t getIntersectionNum() const
Definition LineIntersector.h:164
bool isIntersection(const geom::Coordinate &pt) const
Test whether a point is a intersection point of two line segments.
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
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:26