00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GEOS_ALGORITHM_LINEINTERSECTOR_H
00022 #define GEOS_ALGORITHM_LINEINTERSECTOR_H
00023
00024 #include <geos/export.h>
00025 #include <string>
00026
00027 #include <geos/geom/Coordinate.h>
00028
00029
00030 namespace geos {
00031 namespace geom {
00032 class PrecisionModel;
00033 }
00034 }
00035
00036 namespace geos {
00037 namespace algorithm {
00038
00050 class GEOS_DLL LineIntersector {
00051 public:
00052
00056 static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0, const geom::Coordinate &p1);
00057
00058
00060
00077 static double computeEdgeDistance(const geom::Coordinate& p, const geom::Coordinate& p0, const geom::Coordinate& p1);
00078
00079 static double nonRobustComputeEdgeDistance(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
00080
00081 LineIntersector(const geom::PrecisionModel* initialPrecisionModel=NULL)
00082 :
00083 precisionModel(initialPrecisionModel),
00084 result(0),
00085 isProperVar(false)
00086 {}
00087
00088 ~LineIntersector() {}
00089
00097 bool isInteriorIntersection();
00098
00106 bool isInteriorIntersection(int inputLineIndex);
00107
00109
00114 void setPrecisionModel(const geom::PrecisionModel *newPM) {
00115 precisionModel=newPM;
00116 }
00117
00119
00124 void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
00125
00127 static bool hasIntersection(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
00128
00129
00130 enum {
00131 DONT_INTERSECT=0,
00132 DO_INTERSECT=1,
00133 COLLINEAR=2
00134 };
00135
00136 enum {
00138 NO_INTERSECTION=0,
00139
00141 POINT_INTERSECTION=1,
00142
00144 COLLINEAR_INTERSECTION=2
00145 };
00146
00148 void computeIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
00149 const geom::Coordinate& p3, const geom::Coordinate& p4);
00150
00151 std::string toString() const;
00152
00158 bool hasIntersection() const { return result!=NO_INTERSECTION; }
00159
00161
00164 int getIntersectionNum() const { return result; }
00165
00166
00168
00173 const geom::Coordinate& getIntersection(int intIndex) const {
00174 return intPt[intIndex];
00175 }
00176
00178
00181 static bool isSameSignAndNonZero(double a,double b);
00182
00193 bool isIntersection(const geom::Coordinate& pt) const;
00194
00209 bool isProper() const {
00210 return hasIntersection()&&isProperVar;
00211 }
00212
00223 const geom::Coordinate& getIntersectionAlongSegment(int segmentIndex,int intIndex);
00224
00234 int getIndexAlongSegment(int segmentIndex,int intIndex);
00235
00245 double getEdgeDistance(int geomIndex,int intIndex) const;
00246
00247 private:
00248
00249 void intersectionWithNormalization(const geom::Coordinate& p1,
00250 const geom::Coordinate& p2,
00251 const geom::Coordinate& q1,
00252 const geom::Coordinate& q2,
00253 geom::Coordinate &ret) const;
00254
00259 const geom::PrecisionModel *precisionModel;
00260
00261 int result;
00262
00263 const geom::Coordinate *inputLines[2][2];
00264
00269 geom::Coordinate intPt[2];
00270
00275 int intLineIndex[2][2];
00276
00277 bool isProperVar;
00278
00279
00280
00281 bool isCollinear() const { return result==COLLINEAR_INTERSECTION; }
00282
00283 int computeIntersect(const geom::Coordinate& p1,const geom::Coordinate& p2,const geom::Coordinate& q1,const geom::Coordinate& q2);
00284
00285 bool isEndPoint() const {
00286 return hasIntersection()&&!isProperVar;
00287 }
00288
00289 void computeIntLineIndex();
00290
00291 void computeIntLineIndex(int segmentIndex);
00292
00293 int computeCollinearIntersection(const geom::Coordinate& p1,
00294 const geom::Coordinate& p2, const geom::Coordinate& q1,
00295 const geom::Coordinate& q2);
00296
00306 void intersection(const geom::Coordinate& p1,
00307 const geom::Coordinate& p2,
00308 const geom::Coordinate& q1,
00309 const geom::Coordinate& q2,
00310 geom::Coordinate &ret) const;
00311
00312 double smallestInAbsValue(double x1, double x2,
00313 double x3, double x4) const;
00314
00325 bool isInSegmentEnvelopes(const geom::Coordinate& intPt) const;
00326
00338 void normalizeToEnvCentre(geom::Coordinate &n00, geom::Coordinate &n01,
00339 geom::Coordinate &n10, geom::Coordinate &n11,
00340 geom::Coordinate &normPt) const;
00341
00354 void safeHCoordinateIntersection(const geom::Coordinate& p1,
00355 const geom::Coordinate& p2,
00356 const geom::Coordinate& q1,
00357 const geom::Coordinate& q2,
00358 geom::Coordinate& intPt) const;
00359
00360 };
00361
00362 }
00363 }
00364
00365
00366 #endif // GEOS_ALGORITHM_LINEINTERSECTOR_H
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380