00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
00021 #define GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
00022
00023
00024 #include <geos/platform.h>
00025 #include <geos/geom/Coordinate.h>
00026
00027 #include <vector>
00028 #include <cassert>
00029
00030 namespace geos {
00031 namespace algorithm {
00032 namespace distance {
00033
00034 }
00035 }
00036 namespace geom {
00037
00038 class Coordinate;
00039
00040
00041 }
00042 }
00043
00044 namespace geos {
00045 namespace algorithm {
00046 namespace 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 }
00152 }
00153 }
00154
00155 #endif // GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
00156
00157
00158
00159
00160