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

# OffsetCurveVertexList.h

    00001 /**********************************************************************
    00002  * $Id: OffsetCurveBuilder.h 1820 2006-09-06 16:54:23Z mloskot $
    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.1
    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         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                 // don't add duplicate (or near-duplicate) points
    00122                 if (isDuplicate(bufPt))
    00123                 {
    00124                         return;
    00125                 }
    00126                 // we ask to allow repeated as we checked this ourself
    00127                 // (JTS uses a vector for ptList, not a CoordinateSequence,
    00128                 // we should do the same)
    00129                 ptList->add(bufPt, true);
    00130                 //ptList.push_back(bufPt);
    00131         }
    00132
    00133         // check that points are a ring - add the startpoint again if they are not
    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
    00144         geom::CoordinateSequence* getCoordinates()
    00145         {
    00146                 closeRing();
    00147                 ptListConsumed = true;
    00148                 return ptList;
    00149         }
    00150
    00151 };
    00152
    00153 } // namespace geos.operation.buffer
    00154 } // namespace geos.operation
    00155 } // namespace geos
    00156
    00157
    00158 #endif // ndef GEOS_OP_BUFFER_OFFSETCURVEVERTEXLIST_H
    00159
    00160 /**********************************************************************
    00161  * $Log$
    00162  **********************************************************************/
    00163