00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H
00021 #define GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H
00022
00023 #include <geos/geom/Coordinate.h>
00024 #include <geos/geom/CoordinateSequence.h>
00025 #include <geos/geom/CoordinateArraySequence.h>
00026 #include <geos/geom/PrecisionModel.h>
00027
00028 #include <vector>
00029 #include <memory>
00030
00031
00032 namespace geos {
00033 namespace geom {
00034
00035
00036 }
00037 }
00038
00039 namespace geos {
00040 namespace operation {
00041 namespace buffer {
00042
00043
00044
00045
00046
00048
00051 class OffsetCurveVertexList
00052 {
00053
00054 private:
00055
00056 geom::CoordinateSequence* ptList;
00057
00058 const geom::PrecisionModel* precisionModel;
00059
00066 double minimumVertexDistance;
00067
00075 bool isDuplicate(const geom::Coordinate& pt)
00076 {
00077 if (ptList->size() < 1)
00078 return false;
00079 const geom::Coordinate& lastPt = ptList->back();
00080 double ptDist = pt.distance(lastPt);
00081 if (ptDist < minimumVertexDistance)
00082 return true;
00083 return false;
00084 }
00085
00086
00087 public:
00088
00089 friend std::ostream& operator<< (std::ostream& os, const OffsetCurveVertexList& node);
00090
00091 OffsetCurveVertexList()
00092 :
00093 ptList(new geom::CoordinateArraySequence()),
00094 precisionModel(NULL),
00095 minimumVertexDistance (0.0)
00096 {
00097 }
00098
00099 ~OffsetCurveVertexList()
00100 {
00101 delete ptList;
00102 }
00103
00104 void setPrecisionModel(const geom::PrecisionModel* nPrecisionModel)
00105 {
00106 precisionModel = nPrecisionModel;
00107 }
00108
00109 void setMinimumVertexDistance(double nMinVertexDistance)
00110 {
00111 minimumVertexDistance = nMinVertexDistance;
00112 }
00113
00114 void addPt(const geom::Coordinate& pt)
00115 {
00116 assert(precisionModel);
00117
00118 geom::Coordinate bufPt = pt;
00119 precisionModel->makePrecise(bufPt);
00120
00121 if (isDuplicate(bufPt))
00122 {
00123 return;
00124 }
00125
00126
00127
00128 ptList->add(bufPt, true);
00129 }
00130
00132
00134 void closeRing()
00135 {
00136 if (ptList->size() < 1) return;
00137 const geom::Coordinate& startPt = ptList->front();
00138 const geom::Coordinate& lastPt = ptList->back();
00139 if (startPt.equals(lastPt)) return;
00140
00141 ptList->add(startPt, true);
00142 }
00143
00145
00152 geom::CoordinateSequence* getCoordinates()
00153 {
00154 closeRing();
00155 geom::CoordinateSequence* ret = ptList;
00156 ptList = 0;
00157 return ret;
00158 }
00159
00160 inline int size() const { return ptList ? ptList->size() : 0 ; }
00161
00162 };
00163
00164 std::ostream& operator<< (std::ostream& os, const OffsetCurveVertexList& lst)
00165 {
00166 if ( lst.ptList )
00167 {
00168 os << *(lst.ptList);
00169 }
00170 else
00171 {
00172 os << "empty (consumed?)";
00173 }
00174 return os;
00175 }
00176
00177 }
00178 }
00179 }
00180
00181
00182 #endif // ndef GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H
00183
00184
00185
00186
00187