Go to the documentation of this file.00001
00002
00003
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 POINTND_H
00029 #define POINTND_H
00030
00031 #include "Trace.h"
00032 #include "StringSection.h"
00033 #include "QGpCoreToolsDLLExport.h"
00034
00035 namespace QGpCoreTools {
00036
00037 class CurvePointOptions;
00038
00039 class QGPCORETOOLS_EXPORT PointND
00040 {
00041 public:
00042 PointND() {_x=0.0;}
00043 PointND(double x, const QVector<double>& y) {_x=x; _y=y;}
00044 PointND(const PointND& o) {_x=o._x; _y=o._y;}
00045 PointND(const QVector<double>& p);
00046
00047 int count() const {return _y.count();}
00048
00049 bool operator<(const PointND& p) const {return _x<p._x;}
00050 inline bool operator==(const PointND& p) const;
00051 inline void operator=(const PointND& p);
00052
00053 double x() const {return _x;}
00054 void setX(double x) {_x=x;}
00055 double y(const CurvePointOptions * options) const;
00056 void setY(double y, const CurvePointOptions * options);
00057 inline double y(int index) const;
00058 inline void setY(int index, double y);
00059
00060 void setValid(bool) {}
00061 bool isValid() const {return true;}
00062 inline void interpole(double valX, const PointND& p1, const PointND& p2);
00063 inline void average(const PointND&);
00064
00065
00066 bool fromString(const StringSection& str);
00067 QString toString(int precision=6, char format='g') const;
00068 private:
00069 double _x;
00070 QVector<double> _y;
00071 };
00072
00073 inline bool PointND::operator==(const PointND& p) const
00074 {
00075 if(_x!=p._x) return false;
00076 int n=_y.count();
00077 if(n!=p._y.count()) return false;
00078 for(int i=0; i< n; i++) {
00079 if(_y.at(i)!=p._y.at(i)) return false;
00080 }
00081 return true;
00082 }
00083
00084 inline void PointND::operator=(const PointND& p)
00085 {
00086 _x=p._x;
00087 _y=p._y;
00088 }
00089
00090 inline double PointND::y(int index) const
00091 {
00092 TRACE;
00093 if(index >= _y.count()) {
00094 if(_y.isEmpty()) return 0.0; else return _y.last();
00095 } else {
00096 return _y[index];
00097 }
00098 }
00099
00100 inline void PointND::setY(int index, double y)
00101 {
00102 TRACE;
00103 if(index >= _y.count()) {
00104 _y.resize(index+1);
00105 }
00106 _y[index]=y;
00107 }
00108
00109 inline void PointND::interpole(double valX, const PointND& p1, const PointND& p2)
00110 {
00111 TRACE;
00112 double factor=(valX - p1.x())/(p2.x()-p1.x());
00113 setX(valX);
00114 int n=p1.count();
00115 if(n<p2.count()) n=p2.count();
00116 for(int i=0; i< n; i++) {
00117 setY(i, p1.y(i)+ (p2.y(i)-p1.y(i)) * factor);
00118 }
00119 }
00120
00121 inline void PointND::average(const PointND& p)
00122 {
00123 TRACE;
00124 int n=p.count();
00125 if(n<count()) n=count();
00126 for(int i=0; i< n; i++) {
00127 setY(i, 0.5*(y(i) + p.y(i)));
00128 }
00129 }
00130
00131 }
00132
00133 #endif // POINTND_H