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 bool ptListConsumed;
00058
00059 const geom::PrecisionModel* precisionModel;
00060
00067 double minimumVertexDistance;
00068
00076 bool isDuplicate(const geom::Coordinate& pt)
00077 {
00078 if (ptList->size() < 1)
00079 return false;
00080 const geom::Coordinate& lastPt = ptList->back();
00081 double ptDist = pt.distance(lastPt);
00082 if (ptDist < minimumVertexDistance)
00083 return true;
00084 return false;
00085 }
00086
00087
00088 public:
00089
00090 OffsetCurveVertexList()
00091 :
00092 ptList(new geom::CoordinateArraySequence()),
00093 ptListConsumed(false),
00094 precisionModel(NULL),
00095 minimumVertexDistance (0.0)
00096 {
00097 }
00098
00099 ~OffsetCurveVertexList()
00100 {
00101 if (!ptListConsumed)
00102 delete ptList;
00103 }
00104
00105 void setPrecisionModel(const geom::PrecisionModel* nPrecisionModel)
00106 {
00107 precisionModel = nPrecisionModel;
00108 }
00109
00110 void setMinimumVertexDistance(double nMinVertexDistance)
00111 {
00112 minimumVertexDistance = nMinVertexDistance;
00113 }
00114
00115 void addPt(const geom::Coordinate& pt)
00116 {
00117 assert(precisionModel);
00118
00119 geom::Coordinate bufPt = pt;
00120 precisionModel->makePrecise(bufPt);
00121
00122 if (isDuplicate(bufPt))
00123 {
00124 return;
00125 }
00126
00127
00128
00129 ptList->add(bufPt, true);
00130
00131 }
00132
00133
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
00144 geom::CoordinateSequence* getCoordinates()
00145 {
00146 closeRing();
00147 ptListConsumed = true;
00148 return ptList;
00149 }
00150
00151 };
00152
00153 }
00154 }
00155 }
00156
00157
00158 #endif // ndef GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H
00159
00160
00161
00162
00163