GEOS: LineIntersector.h Source File

GEOS 3.3.8

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

LineIntersector.h
1 /**********************************************************************
2 * $Id: LineIntersector.h 3406 2011-07-05 09:44:10Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2005-2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: algorithm/RobustLineIntersector.java rev. 1.38 (JTS-1.10)
18 *
19 **********************************************************************/
20
21 #ifndef GEOS_ALGORITHM_LINEINTERSECTOR_H
22 #define GEOS_ALGORITHM_LINEINTERSECTOR_H
23
24 #include <geos/export.h>
25 #include <string>
26
27 #include <geos/geom/Coordinate.h>
28
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32 class PrecisionModel;
33 }
34 }
35
36 namespace geos {
37 namespace algorithm { // geos::algorithm
38
50 class GEOS_DLL LineIntersector {
51 public:
52
56 static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0, const geom::Coordinate &p1);
57
58
60 //
77 static double computeEdgeDistance(const geom::Coordinate& p, const geom::Coordinate& p0, const geom::Coordinate& p1);
78
79 static double nonRobustComputeEdgeDistance(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
80
81 LineIntersector(const geom::PrecisionModel* initialPrecisionModel=NULL)
82 :
83 precisionModel(initialPrecisionModel),
84 result(0),
85 isProperVar(false)
86 {}
87
88 ~LineIntersector() {}
89
97 bool isInteriorIntersection();
98
106 bool isInteriorIntersection(int inputLineIndex);
107
109 //
114 void setPrecisionModel(const geom::PrecisionModel *newPM) {
115 precisionModel=newPM;
116 }
117
119 //
124 void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
125
127 static bool hasIntersection(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
128
129 // These are deprecated, due to ambiguous naming
130 enum {
131 DONT_INTERSECT=0,
132 DO_INTERSECT=1,
133 COLLINEAR=2
134 };
135
136 enum {
138 NO_INTERSECTION=0,
139
141 POINT_INTERSECTION=1,
142
144 COLLINEAR_INTERSECTION=2
145 };
146
148 void computeIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
149 const geom::Coordinate& p3, const geom::Coordinate& p4);
150
151 std::string toString() const;
152
158 bool hasIntersection() const { return result!=NO_INTERSECTION; }
159
161 //
164 int getIntersectionNum() const { return result; }
165
166
168 //
173 const geom::Coordinate& getIntersection(int intIndex) const {
174 return intPt[intIndex];
175 }
176
178 //
181 static bool isSameSignAndNonZero(double a,double b);
182
193 bool isIntersection(const geom::Coordinate& pt) const;
194
209 bool isProper() const {
210 return hasIntersection()&&isProperVar;
211 }
212
223 const geom::Coordinate& getIntersectionAlongSegment(int segmentIndex,int intIndex);
224
234 int getIndexAlongSegment(int segmentIndex,int intIndex);
235
245 double getEdgeDistance(int geomIndex,int intIndex) const;
246
247 private:
248
249 void intersectionWithNormalization(const geom::Coordinate& p1,
250 const geom::Coordinate& p2,
251 const geom::Coordinate& q1,
252 const geom::Coordinate& q2,
253 geom::Coordinate &ret) const;
254
259 const geom::PrecisionModel *precisionModel;
260
261 int result;
262
263 const geom::Coordinate *inputLines[2][2];
264
269 geom::Coordinate intPt[2];
270
275 int intLineIndex[2][2];
276
277 bool isProperVar;
278 //Coordinate &pa;
279 //Coordinate &pb;
280
281 bool isCollinear() const { return result==COLLINEAR_INTERSECTION; }
282
283 int computeIntersect(const geom::Coordinate& p1,const geom::Coordinate& p2,const geom::Coordinate& q1,const geom::Coordinate& q2);
284
285 bool isEndPoint() const {
286 return hasIntersection()&&!isProperVar;
287 }
288
289 void computeIntLineIndex();
290
291 void computeIntLineIndex(int segmentIndex);
292
293 int computeCollinearIntersection(const geom::Coordinate& p1,
294 const geom::Coordinate& p2, const geom::Coordinate& q1,
295 const geom::Coordinate& q2);
296
306 void intersection(const geom::Coordinate& p1,
307 const geom::Coordinate& p2,
308 const geom::Coordinate& q1,
309 const geom::Coordinate& q2,
310 geom::Coordinate &ret) const;
311
312 double smallestInAbsValue(double x1, double x2,
313 double x3, double x4) const;
314
325 bool isInSegmentEnvelopes(const geom::Coordinate& intPt) const;
326
338 void normalizeToEnvCentre(geom::Coordinate &n00, geom::Coordinate &n01,
339 geom::Coordinate &n10, geom::Coordinate &n11,
340 geom::Coordinate &normPt) const;
341
354 void safeHCoordinateIntersection(const geom::Coordinate& p1,
355 const geom::Coordinate& p2,
356 const geom::Coordinate& q1,
357 const geom::Coordinate& q2,
358 geom::Coordinate& intPt) const;
359
360 };
361
362 } // namespace geos::algorithm
363 } // namespace geos
364
365
366 #endif // GEOS_ALGORITHM_LINEINTERSECTOR_H
367
368 /**********************************************************************
369 * $Log$
370 * Revision 1.3 2006/04/20 14:16:25 strk
371 * Added some more doxygen comments
372 *
373 * Revision 1.2 2006/04/06 21:31:40 strk
374 * Const correctness for debugging function
375 *
376 * Revision 1.1 2006/03/09 16:46:48 strk
377 * geos::geom namespace definition, first pass at headers split
378 *
379 **********************************************************************/
380