Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

qwt_dimap.cpp

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #include "qwt_dimap.h" 00011 00012 QT_STATIC_CONST_IMPL double QwtDiMap::LogMin = 1.0e-150; 00013 QT_STATIC_CONST_IMPL double QwtDiMap::LogMax = 1.0e150; 00014 00020 QwtDiMap::QwtDiMap(): 00021 d_x1(0.0), 00022 d_x2(1.0), 00023 d_y1(0), 00024 d_y2(1), 00025 d_cnv(1.0), 00026 d_log(FALSE) 00027 { 00028 } 00029 00030 00043 QwtDiMap::QwtDiMap(int i1, int i2, double d1, double d2, bool logarithmic) 00044 { 00045 // setIntRange(i1, i2) calls newFactor() with uninitialized memory 00046 d_y1 = i1; 00047 d_y2 = i2; 00048 setDblRange(d1, d2, logarithmic); 00049 } 00050 00054 QwtDiMap::~QwtDiMap() 00055 { 00056 } 00057 00063 bool QwtDiMap::contains(double x) const 00064 { 00065 return ( (x >= QMIN(d_x1, d_x2)) && (x <= QMAX(d_x1, d_x2))); 00066 } 00067 00073 bool QwtDiMap::contains(int x) const 00074 { 00075 return ( (x >= QMIN(d_y1, d_y2)) && (x <= QMAX(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 00132 double QwtDiMap::invTransform(int y) const 00133 { 00134 if (d_cnv == 0.0) 00135 return 0.0; 00136 else 00137 { 00138 if(d_log) 00139 return exp(d_x1 + double(y - d_y1) / d_cnv ); 00140 else 00141 return ( d_x1 + double(y - d_y1) / d_cnv ); 00142 } 00143 } 00144 00155 int QwtDiMap::limTransform(double x) const 00156 { 00157 if (d_log) { 00158 if (x > LogMax) 00159 x = LogMax; 00160 else if (x < LogMin) 00161 x = LogMin; 00162 x = log(x); 00163 } 00164 00165 if ( x > qwtMax(d_x1, d_x2) ) 00166 x = qwtMax(d_x1, d_x2); 00167 else if ( x < qwtMin(d_x1, d_x2)) 00168 x = qwtMin(d_x1, d_x2); 00169 00170 return d_log ? transform(exp(x)) : transform(x); 00171 } 00172 00185 double QwtDiMap::xTransform(double x) const 00186 { 00187 double rv; 00188 00189 if (d_log) 00190 rv = double(d_y1) + (log(x) - d_x1) * d_cnv; 00191 else 00192 rv = double(d_y1) + (x - d_x1) * d_cnv; 00193 00194 return rv; 00195 } 00196 00197 00201 void QwtDiMap::newFactor() 00202 { 00203 if (d_x2 != d_x1) 00204 d_cnv = double(d_y2 - d_y1) / (d_x2 - d_x1); 00205 else 00206 d_cnv = 0.0; 00207 }

Generated on Tue Nov 16 21:12:20 2004 for Qwt User's Guide by doxygen 1.3.8