00001 #pragma ident "$Id: Splitter.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002
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 VPLOT_SPLITTER_H
00029 #define VPLOT_SPLITTER_H
00030
00031 #include <vector>
00032 #include <list>
00033 #include <map>
00034 #include <memory>
00035
00036 #include "Path.hpp"
00037
00038 namespace vplot
00039 {
00044 class Splitter
00045 {
00046 public:
00057 static std::pair<std::list<vdraw::Path*>*,std::list<vdraw::Path*>*>
00058 splith(double splitter, vdraw::Path* p, bool top, bool bottom, bool continuous=false);
00059
00067 static std::list<vdraw::Path*>* splitvgap(double gap, vdraw::Path* p);
00068
00071 inline static bool inBox(const std::pair<double,double>& p,
00072 double minX, double maxX, double minY, double maxY)
00073 {
00074 return !((p.first<minX || p.first>maxX) || (p.second<minY || p.second>maxY));
00075 }
00076
00109 static std::pair<double,double> intersectBox(
00110 const std::pair<double,double> inside, const std::pair<double,double> outside,
00111 double minX, double maxX, double minY, double maxY);
00112
00124 static std::auto_ptr< std::list< vdraw::Path > > interpToBox(double minX, double maxX, double minY, double maxY, const vdraw::Path& p);
00125
00136 static std::auto_ptr< vdraw::Path > cropToBox(double minX, double maxX, double minY, double maxY, const vdraw::Path& p);
00137
00138 private:
00141 static inline double intersecth(double y, const std::pair<double,double>& p1, const std::pair<double,double>& p2)
00142 {
00143 double ratio = (y - p1.second) / (p2.second - p1.second);
00144 double xdist = p2.first - p1.first;
00145 return p1.first + xdist*ratio;
00146 }
00147
00150 static inline double intersectv(double x, const std::pair<double,double>& p1, const std::pair<double,double>& p2)
00151 {
00152 double ratio = (x - p1.first) / (p2.first - p1.first);
00153 double ydist = p2.second - p1.second;
00154 return p1.second + ydist*ratio;
00155 }
00156 };
00157 }
00158
00159 #endif