GEOS: PointPairDistance.h Source File

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

- File List

# PointPairDistance.h

    00001 /**********************************************************************
    00002  * $Id: PointPairDistance.h 2809 2009-12-06 01:05:24Z mloskot $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2009  Sandro Santilli <strk@keybit.net>
    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/distance/PointPairDistance.java 1.1 (JTS-1.9)
    00017  *
    00018  **********************************************************************/
    00019
    00020 #ifndef GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
    00021 #define GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
    00022
    00023 //#include <geos/geom/LineSegment.h> // for composition
    00024 #include <geos/platform.h> // for DoubleNotANumber
    00025 #include <geos/geom/Coordinate.h> // for inlines
    00026
    00027 #include <vector> // for composition
    00028 #include <cassert>
    00029
    00030 namespace geos {
    00031         namespace algorithm {
    00032                 namespace distance {
    00033                         //class PointPairDistance;
    00034                 }
    00035         }
    00036         namespace geom {
    00037                 //class Geometry;
    00038                 class Coordinate;
    00039                 //class LineString;
    00040                 //class Polygon;
    00041         }
    00042 }
    00043
    00044 namespace geos {
    00045 namespace algorithm { // geos::algorithm
    00046 namespace distance { // geos::algorithm::distance
    00047
    00053 class PointPairDistance
    00054 {
    00055 public:
    00056
    00057         PointPairDistance()
    00058                 :
    00059                 pt(2),
    00060                 distance(DoubleNotANumber),
    00061                 isNull(true)
    00062         {
    00063                 assert(pt.size() == 2);
    00064         }
    00065
    00066         void initialize()
    00067         {
    00068                 isNull = true;
    00069         }
    00070
    00071         void initialize(const geom::Coordinate& p0, const geom::Coordinate& p1)
    00072         {
    00073                 pt[0] = p0;
    00074                 pt[1] = p1;
    00075                 distance = p0.distance(p1);
    00076                 isNull = false;
    00077         }
    00078
    00079         double getDistance() const
    00080         {
    00081                 return distance;
    00082         }
    00083
    00084         const std::vector<geom::Coordinate>& getCoordinates() const
    00085         {
    00086                 return pt;
    00087         }
    00088
    00089         const geom::Coordinate& getCoordinate(unsigned int i) const
    00090         {
    00091                 assert(i<pt.size());
    00092                 return pt[i];
    00093         }
    00094
    00095         void setMaximum(const PointPairDistance& ptDist)
    00096         {
    00097                 setMaximum(ptDist.pt[0], ptDist.pt[1]);
    00098         }
    00099
    00100         void setMaximum(const geom::Coordinate& p0, const geom::Coordinate& p1)
    00101         {
    00102                 if (isNull) {
    00103                         initialize(p0, p1);
    00104                         return;
    00105                 }
    00106                 double dist = p0.distance(p1);
    00107                 if (dist > distance)
    00108                         initialize(p0, p1, dist);
    00109         }
    00110
    00111         void setMinimum(const PointPairDistance& ptDist)
    00112         {
    00113                 setMinimum(ptDist.pt[0], ptDist.pt[1]);
    00114         }
    00115
    00116         void setMinimum(const geom::Coordinate& p0, const geom::Coordinate& p1)
    00117         {
    00118                 if (isNull) {
    00119                         initialize(p0, p1);
    00120                         return;
    00121                 }
    00122                 double dist = p0.distance(p1);
    00123                 if (dist < distance)
    00124                         initialize(p0, p1, dist);
    00125         }
    00126
    00127 private:
    00128
    00135         void initialize(const geom::Coordinate& p0, const geom::Coordinate& p1,
    00136                         double dist)
    00137         {
    00138                 pt[0] = p0;
    00139                 pt[1] = p1;
    00140                 distance = dist;
    00141                 isNull = false;
    00142         }
    00143
    00144         std::vector<geom::Coordinate> pt;
    00145
    00146         double distance;
    00147
    00148         bool isNull;
    00149 };
    00150
    00151 } // geos::algorithm::distance
    00152 } // geos::algorithm
    00153 } // geos
    00154
    00155 #endif // GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
    00156
    00157 /**********************************************************************
    00158  * $Log$
    00159  **********************************************************************/
    00160