LineIntersector.h

00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2005-2006 Refractions Research Inc.
00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************
00015  *
00016  * Last port: algorithm/RobustLineIntersector.java r785 (JTS-1.13+)
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef GEOS_ALGORITHM_LINEINTERSECTOR_H
00021 #define GEOS_ALGORITHM_LINEINTERSECTOR_H
00022 
00023 #include <geos/export.h>
00024 #include <string>
00025 
00026 #include <geos/geom/Coordinate.h>
00027 
00028 // Forward declarations
00029 namespace geos {
00030         namespace geom {
00031                 class PrecisionModel;
00032         }
00033 }
00034 
00035 namespace geos {
00036 namespace algorithm { // geos::algorithm
00037 
00049 class GEOS_DLL LineIntersector {
00050 public: 
00051 
00055         static double interpolateZ(const geom::Coordinate &p, const geom::Coordinate &p0, const geom::Coordinate &p1);
00056 
00057 
00059         //
00076         static double computeEdgeDistance(const geom::Coordinate& p, const geom::Coordinate& p0, const geom::Coordinate& p1);
00077 
00078         static double nonRobustComputeEdgeDistance(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
00079 
00080         LineIntersector(const geom::PrecisionModel* initialPrecisionModel=NULL)
00081                 :
00082                 precisionModel(initialPrecisionModel),
00083                 result(0),
00084                 isProperVar(false)
00085         {}
00086 
00087         ~LineIntersector() {}
00088 
00096         bool isInteriorIntersection();
00097 
00105         bool isInteriorIntersection(int inputLineIndex);
00106 
00108         //
00113         void setPrecisionModel(const geom::PrecisionModel *newPM) {
00114                 precisionModel=newPM;
00115         }
00116 
00118         //
00123         void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
00124 
00126         static bool hasIntersection(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
00127 
00128         // These are deprecated, due to ambiguous naming
00129         enum {
00130                 DONT_INTERSECT=0,
00131                 DO_INTERSECT=1,
00132                 COLLINEAR=2
00133         };
00134 
00135         enum {
00137                 NO_INTERSECTION=0,
00138 
00140                 POINT_INTERSECTION=1,
00141 
00143                 COLLINEAR_INTERSECTION=2
00144         };
00145 
00147         void computeIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
00148                         const geom::Coordinate& p3, const geom::Coordinate& p4);
00149 
00150         std::string toString() const;
00151 
00157         bool hasIntersection() const { return result!=NO_INTERSECTION; }
00158 
00160         //
00163         int getIntersectionNum() const { return result; }
00164 
00165         
00167         //
00172         const geom::Coordinate& getIntersection(int intIndex) const {
00173                 return intPt[intIndex];
00174         }
00175 
00177         //
00180         static bool isSameSignAndNonZero(double a,double b);
00181 
00192         bool isIntersection(const geom::Coordinate& pt) const;
00193 
00208         bool isProper() const {
00209                 return hasIntersection()&&isProperVar;
00210         }
00211 
00222         const geom::Coordinate& getIntersectionAlongSegment(int segmentIndex,int intIndex);
00223 
00233         int getIndexAlongSegment(int segmentIndex,int intIndex);
00234 
00244         double getEdgeDistance(int geomIndex,int intIndex) const;
00245 
00246 private:
00247 
00248         void intersectionWithNormalization(const geom::Coordinate& p1,
00249                 const geom::Coordinate& p2,
00250                 const geom::Coordinate& q1,
00251                 const geom::Coordinate& q2,
00252                 geom::Coordinate &ret) const;
00253 
00258         const geom::PrecisionModel *precisionModel;
00259 
00260         int result;
00261 
00262         const geom::Coordinate *inputLines[2][2];
00263 
00268         geom::Coordinate intPt[2];
00269 
00274         int intLineIndex[2][2];
00275 
00276         bool isProperVar;
00277         //Coordinate &pa;
00278         //Coordinate &pb;
00279 
00280         bool isCollinear() const { return result==COLLINEAR_INTERSECTION; }
00281 
00282         int computeIntersect(const geom::Coordinate& p1,const geom::Coordinate& p2,const geom::Coordinate& q1,const geom::Coordinate& q2);
00283 
00284         bool isEndPoint() const {
00285                 return hasIntersection()&&!isProperVar;
00286         }
00287 
00288         void computeIntLineIndex();
00289 
00290         void computeIntLineIndex(int segmentIndex);
00291 
00292         int computeCollinearIntersection(const geom::Coordinate& p1,
00293                 const geom::Coordinate& p2, const geom::Coordinate& q1,
00294                 const geom::Coordinate& q2);
00295 
00305         void intersection(const geom::Coordinate& p1,
00306                 const geom::Coordinate& p2,
00307                 const geom::Coordinate& q1,
00308                 const geom::Coordinate& q2,
00309                 geom::Coordinate &ret) const;
00310 
00311         double smallestInAbsValue(double x1, double x2,
00312                 double x3, double x4) const;
00313 
00324         bool isInSegmentEnvelopes(const geom::Coordinate& intPt) const;
00325 
00337         void normalizeToEnvCentre(geom::Coordinate &n00, geom::Coordinate &n01,
00338                 geom::Coordinate &n10, geom::Coordinate &n11,
00339                 geom::Coordinate &normPt) const;
00340 
00353          void safeHCoordinateIntersection(const geom::Coordinate& p1,
00354                          const geom::Coordinate& p2,
00355                          const geom::Coordinate& q1,
00356                          const geom::Coordinate& q2,
00357                          geom::Coordinate& intPt) const;
00358                    
00359 };
00360 
00361 } // namespace geos::algorithm
00362 } // namespace geos
00363 
00364 
00365 #endif // GEOS_ALGORITHM_LINEINTERSECTOR_H
00366 

Generated on 23 Sep 2013 for GEOS by  doxygen 1.4.7