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

- File List

# LineIntersector.h

    00001 /**********************************************************************
    00002  * $Id: LineIntersector.h 2556 2009-06-06 22:22:28Z strk $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2005-2006 Refractions Research Inc.
    00008  * Copyright (C) 2001-2002 Vivid Solutions Inc.
    00009  *
    00010  * This is free software; you can redistribute and/or modify it under
    00011  * the terms of the GNU Lesser General Public Licence as published
    00012  * by the Free Software Foundation.
    00013  * See the COPYING file for more information.
    00014  *
    00015  **********************************************************************
    00016  *
    00017  * Last port: algorithm/RobustLineIntersector.java rev. 1.38 (JTS-1.10)
    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 // Forward declarations
    00030 namespace geos {
    00031         namespace geom {
    00032                 class PrecisionModel;
    00033         }
    00034 }
    00035
    00036 namespace geos {
    00037 namespace algorithm { // geos::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         {}
    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
    00367 /**********************************************************************
    00368  * $Log$
    00369  * Revision 1.3  2006/04/20 14:16:25  strk
    00370  * Added some more doxygen comments
    00371  *
    00372  * Revision 1.2  2006/04/06 21:31:40  strk
    00373  * Const correctness for debugging function
    00374  *
    00375  * Revision 1.1  2006/03/09 16:46:48  strk
    00376  * geos::geom namespace definition, first pass at headers split
    00377  *
    00378  **********************************************************************/
    00379