00001 #pragma ident "$Id: Path.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef VDRAW_PATH_H
00029 #define VDRAW_PATH_H
00030
00031 #include<string>
00032 #include<vector>
00033 #include<utility>
00034 #include<memory>
00035
00036
00037
00038
00039
00040 #include "GraphicsConstants.hpp"
00041 #include "VDrawException.hpp"
00042
00043 namespace vdraw
00044 {
00047
00054 struct Point : public std::pair<double, double>
00055 {
00057 Point(double ix=0.0, double iy=0.0)
00058 : std::pair<double,double>(ix,iy)
00059 {
00060 }
00061
00063 Point(const Point& p)
00064 : std::pair<double,double>(p.x(),p.y())
00065 {
00066 }
00067
00069 Point(const std::pair<double,double>& o)
00070 : std::pair<double,double>(o)
00071 {
00072 }
00073
00075 double& x() { return first; }
00076
00078 const double& x() const { return first; }
00079
00081 double& y() { return second; }
00082
00084 const double& y() const { return second; }
00085
00086 };
00087
00107 class Path: public std::vector< Point >
00108 {
00109 public:
00110
00116 Path(unsigned int estimated_size=0)
00117 : originX(0.0), originY(0.0)
00118 {
00119 if(estimated_size)
00120 reserve(estimated_size);
00121 }
00122
00130 Path(double iOriginX, double iOriginY, unsigned int estimated_size=0)
00131 : originX(iOriginX), originY(iOriginY)
00132 {
00133 if(estimated_size)
00134 reserve(estimated_size);
00135 }
00136
00141 Path(const std::vector< std::pair<double,double> >& v, double iOriginX=0, double iOriginY=0)
00142 {
00143 originX = iOriginX;
00144 originY = iOriginY;
00145 reserve(v.size());
00146 std::vector< std::pair<double,double> >::const_iterator i;
00147 for(i=v.begin(); i!=v.end(); i++)
00148 {
00149 if(size()==0
00150 || (i->first != (*this)[size()-1].x())
00151 || (i->second != (*this)[size()-1].y()))
00152 push_back(Point(*i));
00153 }
00154 tighten();
00155 }
00156
00162 inline void tighten()
00163 {
00164 resize(size());
00165 }
00166
00172 inline void setOrigin(double X, double Y)
00173 {
00174 originX = X;
00175 originY = Y;
00176 return;
00177 }
00178
00184 inline void getOrigin(double& X, double& Y) const
00185 {
00186 X = originX;
00187 Y = originY;
00188 return;
00189 }
00190
00196 void addPointAbsolute(double X, double Y);
00197
00206 void addPointRelative(double X, double Y);
00207
00213 void addPointDelta(double DX, double DY) throw (VDrawException);
00214
00221 void rotate(double angleDegrees, double rx, double ry);
00222
00227 void rotate(double angleDegrees);
00228
00234 void translate(double deltaX, double deltaY);
00235
00242 void scale(double factor, double sx, double sy);
00243
00255 std::auto_ptr<Path> asAbsolute(void) const;
00256
00257 protected:
00258
00259 private:
00261 double originX;
00263 double originY;
00264
00265 };
00266
00268
00269 }
00270
00271 #endif //VDRAW_PLOT_PATH_H
00272