GEOS 3.3.4

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

- File List

PointPairDistance.h
1 /**********************************************************************
2 * $Id: PointPairDistance.h 2809 2009-12-06 01:05:24Z mloskot $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2009 Sandro Santilli <strk@keybit.net>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: algorithm/distance/PointPairDistance.java 1.1 (JTS-1.9)
17 *
18 **********************************************************************/
19
20 #ifndef GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
21 #define GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
22
23 //#include <geos/geom/LineSegment.h> // for composition
24 #include <geos/platform.h> // for DoubleNotANumber
25 #include <geos/geom/Coordinate.h> // for inlines
26
27 #include <vector> // for composition
28 #include <cassert>
29
30 namespace geos {
31 namespace algorithm {
32 namespace distance {
33 //class PointPairDistance;
34 }
35 }
36 namespace geom {
37 //class Geometry;
38 class Coordinate;
39 //class LineString;
40 //class Polygon;
41 }
42 }
43
44 namespace geos {
45 namespace algorithm { // geos::algorithm
46 namespace distance { // geos::algorithm::distance
47
53 class PointPairDistance
54 {
55 public:
56
57 PointPairDistance()
58 :
59 pt(2),
60 distance(DoubleNotANumber),
61 isNull(true)
62 {
63 assert(pt.size() == 2);
64 }
65
66 void initialize()
67 {
68 isNull = true;
69 }
70
71 void initialize(const geom::Coordinate& p0, const geom::Coordinate& p1)
72 {
73 pt[0] = p0;
74 pt[1] = p1;
75 distance = p0.distance(p1);
76 isNull = false;
77 }
78
79 double getDistance() const
80 {
81 return distance;
82 }
83
84 const std::vector<geom::Coordinate>& getCoordinates() const
85 {
86 return pt;
87 }
88
89 const geom::Coordinate& getCoordinate(unsigned int i) const
90 {
91 assert(i<pt.size());
92 return pt[i];
93 }
94
95 void setMaximum(const PointPairDistance& ptDist)
96 {
97 setMaximum(ptDist.pt[0], ptDist.pt[1]);
98 }
99
100 void setMaximum(const geom::Coordinate& p0, const geom::Coordinate& p1)
101 {
102 if (isNull) {
103 initialize(p0, p1);
104 return;
105 }
106 double dist = p0.distance(p1);
107 if (dist > distance)
108 initialize(p0, p1, dist);
109 }
110
111 void setMinimum(const PointPairDistance& ptDist)
112 {
113 setMinimum(ptDist.pt[0], ptDist.pt[1]);
114 }
115
116 void setMinimum(const geom::Coordinate& p0, const geom::Coordinate& p1)
117 {
118 if (isNull) {
119 initialize(p0, p1);
120 return;
121 }
122 double dist = p0.distance(p1);
123 if (dist < distance)
124 initialize(p0, p1, dist);
125 }
126
127 private:
128
135 void initialize(const geom::Coordinate& p0, const geom::Coordinate& p1,
136 double dist)
137 {
138 pt[0] = p0;
139 pt[1] = p1;
140 distance = dist;
141 isNull = false;
142 }
143
144 std::vector<geom::Coordinate> pt;
145
146 double distance;
147
148 bool isNull;
149 };
150
151 } // geos::algorithm::distance
152 } // geos::algorithm
153 } // geos
154
155 #endif // GEOS_ALGORITHM_DISTANCE_POINTPAIRDISTANCE_H
156
157 /**********************************************************************
158 * $Log$
159 **********************************************************************/
160