GEOS 3.2.1
|
00001 /********************************************************************** 00002 * $Id: OffsetCurveVertexList.h 2628 2009-09-27 20:43:03Z strk $ 00003 * 00004 * GEOS - Geometry Engine Open Source 00005 * http://geos.refractions.net 00006 * 00007 * Copyright (C) 2007 Refractions Research Inc. 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: operation/buffer/OffsetCurveVertexList.java rev. 1.2 (JTS-1.10) 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H 00021 #define GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H 00022 00023 #include <geos/geom/Coordinate.h> // for inlines 00024 #include <geos/geom/CoordinateSequence.h> // for inlines 00025 #include <geos/geom/CoordinateArraySequence.h> // for composition 00026 #include <geos/geom/PrecisionModel.h> // for inlines 00027 00028 #include <vector> 00029 #include <memory> 00030 00031 // Forward declarations 00032 namespace geos { 00033 namespace geom { 00034 //class CoordinateSequence; 00035 //class PrecisionModel; 00036 } 00037 } 00038 00039 namespace geos { 00040 namespace operation { // geos.operation 00041 namespace buffer { // geos.operation.buffer 00042 00043 // --------------------------------------------- 00044 // OffsetCurveVertexList 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 // don't add duplicate (or near-duplicate) points 00121 if (isDuplicate(bufPt)) 00122 { 00123 return; 00124 } 00125 // we ask to allow repeated as we checked this ourself 00126 // (JTS uses a vector for ptList, not a CoordinateSequence, 00127 // we should do the same) 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 // we ask to allow repeated as we checked this ourself 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 } // namespace geos.operation.buffer 00178 } // namespace geos.operation 00179 } // namespace geos 00180 00181 00182 #endif // ndef GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H 00183 00184 /********************************************************************** 00185 * $Log$ 00186 **********************************************************************/ 00187