00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_dimap.h"
00011 #include "qwt_math.h"
00012
00013 QT_STATIC_CONST_IMPL double QwtDiMap::LogMin = 1.0e-150;
00014 QT_STATIC_CONST_IMPL double QwtDiMap::LogMax = 1.0e150;
00015
00016
00022 QwtDiMap::QwtDiMap()
00023 {
00024 d_x1 = 0.0;
00025 d_x2 = 1.0;
00026 d_y1 = 0;
00027 d_y2 = 1;
00028 d_cnv = 1.0;
00029 }
00030
00031
00044 QwtDiMap::QwtDiMap(int i1, int i2, double d1, double d2, bool logarithmic)
00045 {
00046 d_log = logarithmic;
00047 setIntRange(i1,i2);
00048 setDblRange(d1, d2);
00049 }
00050
00054 QwtDiMap::~QwtDiMap()
00055 {
00056 }
00057
00063 bool QwtDiMap::contains(double x) const
00064 {
00065 return ( (x >= qwtMin(d_x1, d_x1)) && (x <= qwtMax(d_x1, d_x2)));
00066 }
00067
00073 bool QwtDiMap::contains(int x) const
00074 {
00075 return ( (x >= qwtMin(d_y1, d_y1)) && (x <= qwtMax(d_y1, d_y2)));
00076 }
00077
00084 void QwtDiMap::setDblRange(double d1, double d2, bool lg)
00085 {
00086 if (lg)
00087 {
00088 d_log = TRUE;
00089 if (d1 < LogMin)
00090 d1 = LogMin;
00091 else if (d1 > LogMax)
00092 d1 = LogMax;
00093
00094 if (d2 < LogMin)
00095 d2 = LogMin;
00096 else if (d2 > LogMax)
00097 d2 = LogMax;
00098
00099 d_x1 = log(d1);
00100 d_x2 = log(d2);
00101 }
00102 else
00103 {
00104 d_log = FALSE;
00105 d_x1 = d1;
00106 d_x2 = d2;
00107 }
00108 newFactor();
00109 }
00110
00116 void QwtDiMap::setIntRange(int i1, int i2)
00117 {
00118 d_y1 = i1;
00119 d_y2 = i2;
00120 newFactor();
00121 }
00122
00123
00124
00138 int QwtDiMap::transform(double x) const
00139 {
00140 if (d_log)
00141 return (d_y1 + int(floor ( (log(x) - d_x1) * d_cnv + 0.5)));
00142 else
00143 return (d_y1 + int(floor ( (x - d_x1) * d_cnv + 0.5)));
00144 }
00145
00155 double QwtDiMap::invTransform(int y) const
00156 {
00157 if (d_cnv == 0.0)
00158 return 0.0;
00159 else
00160 {
00161 if(d_log)
00162 return exp(d_x1 + double(y - d_y1) / d_cnv );
00163 else
00164 return ( d_x1 + double(y - d_y1) / d_cnv );
00165 }
00166 }
00167
00168
00179 int QwtDiMap::limTransform(double x) const
00180 {
00181 if ( x > qwtMax(d_x1, d_x2) )
00182 x = qwtMax(d_x1, d_x2);
00183 else if ( x < qwtMin(d_x1, d_x2))
00184 x = qwtMin(d_x1, d_x2);
00185 return transform(x);
00186 }
00187
00200 double QwtDiMap::xTransform(double x) const
00201 {
00202 double rv;
00203
00204 if (d_log)
00205 rv = double(d_y1) + (log(x) - d_x1) * d_cnv;
00206 else
00207 rv = double(d_y1) + (x - d_x1) * d_cnv;
00208
00209 return rv;
00210 }
00211
00212
00216 void QwtDiMap::newFactor()
00217 {
00218 if (d_x2 != d_x1)
00219 d_cnv = double(d_y2 - d_y1) / (d_x2 - d_x1);
00220 else
00221 d_cnv = 0.0;
00222 }