# LineIntersector.h

    00001 /**********************************************************************
    00002  * $Id: LineIntersector.h 1938 2006-12-07 10:45:16Z 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.35
    00018  *
    00019  **********************************************************************/
    00020
    00021 #ifndef GEOS_ALGORITHM_LINEINTERSECTOR_H
    00022 #define GEOS_ALGORITHM_LINEINTERSECTOR_H
    00023
    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 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         {}
    00085
    00086         ~LineIntersector() {}
    00087
    00095         bool isInteriorIntersection();
    00096
    00104         bool isInteriorIntersection(int inputLineIndex);
    00105
    00107         //
    00112         void setPrecisionModel(const geom::PrecisionModel *newPM) {
    00113                 precisionModel=newPM;
    00114         }
    00115
    00117         //
    00122         void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
    00123
    00125         static bool hasIntersection(const geom::Coordinate& p,const geom::Coordinate& p1,const geom::Coordinate& p2);
    00126
    00127         enum {
    00128                 DONT_INTERSECT,
    00129                 DO_INTERSECT,
    00130                 COLLINEAR
    00131         };
    00132
    00134         void computeIntersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
    00135                         const geom::Coordinate& p3, const geom::Coordinate& p4);
    00136
    00137         std::string toString() const;
    00138
    00144         bool hasIntersection() const { return result!=DONT_INTERSECT; }
    00145
    00147         //
    00150         int getIntersectionNum() const { return result; }
    00151
    00152
    00154         //
    00159         const geom::Coordinate& getIntersection(int intIndex) const {
    00160                 return intPt[intIndex];
    00161         }
    00162
    00164         //
    00167         static bool isSameSignAndNonZero(double a,double b);
    00168
    00179         bool isIntersection(const geom::Coordinate& pt) const;
    00180
    00195         bool isProper() const {
    00196                 return hasIntersection()&&isProperVar;
    00197         }
    00198
    00209         const geom::Coordinate& getIntersectionAlongSegment(int segmentIndex,int intIndex);
    00210
    00220         int getIndexAlongSegment(int segmentIndex,int intIndex);
    00221
    00231         double getEdgeDistance(int geomIndex,int intIndex) const;
    00232
    00233 private:
    00234
    00239         const geom::PrecisionModel *precisionModel;
    00240
    00241         int result;
    00242
    00243         const geom::Coordinate *inputLines[2][2];
    00244
    00249         geom::Coordinate intPt[2];
    00250
    00255         int intLineIndex[2][2];
    00256
    00257         bool isProperVar;
    00258         //Coordinate &pa;
    00259         //Coordinate &pb;
    00260
    00261         bool isCollinear() const { return result==COLLINEAR; }
    00262
    00263         int computeIntersect(const geom::Coordinate& p1,const geom::Coordinate& p2,const geom::Coordinate& q1,const geom::Coordinate& q2);
    00264
    00265         bool isEndPoint() const {
    00266                 return hasIntersection()&&!isProperVar;
    00267         }
    00268
    00269         void computeIntLineIndex();
    00270
    00271         void computeIntLineIndex(int segmentIndex);
    00272
    00273         int computeCollinearIntersection(const geom::Coordinate& p1,
    00274                 const geom::Coordinate& p2, const geom::Coordinate& q1,
    00275                 const geom::Coordinate& q2);
    00276
    00286         void intersection(const geom::Coordinate& p1,
    00287                 const geom::Coordinate& p2,
    00288                 const geom::Coordinate& q1,
    00289                 const geom::Coordinate& q2,
    00290                 geom::Coordinate &ret) const;
    00291
    00292         double smallestInAbsValue(double x1, double x2,
    00293                 double x3, double x4) const;
    00294
    00305         bool isInSegmentEnvelopes(const geom::Coordinate& intPt) const;
    00306
    00318         void normalizeToEnvCentre(geom::Coordinate &n00, geom::Coordinate &n01,
    00319                 geom::Coordinate &n10, geom::Coordinate &n11,
    00320                 geom::Coordinate &normPt) const;
    00321
    00334          void safeHCoordinateIntersection(const geom::Coordinate& p1,
    00335                          const geom::Coordinate& p2,
    00336                          const geom::Coordinate& q1,
    00337                          const geom::Coordinate& q2,
    00338                          geom::Coordinate& intPt) const;
    00339
    00340 };
    00341
    00342 } // namespace geos::algorithm
    00343 } // namespace geos
    00344
    00345
    00346 #endif // GEOS_ALGORITHM_LINEINTERSECTOR_H
    00347
    00348 /**********************************************************************
    00349  * $Log$
    00350  * Revision 1.3  2006/04/20 14:16:25  strk
    00351  * Added some more doxygen comments
    00352  *
    00353  * Revision 1.2  2006/04/06 21:31:40  strk
    00354  * Const correctness for debugging function
    00355  *
    00356  * Revision 1.1  2006/03/09 16:46:48  strk
    00357  * geos::geom namespace definition, first pass at headers split
    00358  *
    00359  **********************************************************************/
    00360