00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #ifndef QWT_MATH_H
00016 #define QWT_MATH_H
00017
00018 #include <math.h>
00019 #include <qpoint.h>
00020 #include "qwt_global.h"
00021
00022
00023 #ifndef LOG10_2
00024 #define LOG10_2 0.30102999566398119802
00025 #endif
00026
00027 #ifndef LOG10_3
00028 #define LOG10_3 0.47712125471966243540
00029 #endif
00030
00031 #ifndef LOG10_5
00032 #define LOG10_5 0.69897000433601885749
00033 #endif
00034
00035 #ifndef M_2PI
00036 #define M_2PI 6.28318530717958623200
00037 #endif
00038
00039 #ifndef LOG_MIN
00040 #define LOG_MIN 1.0e-100
00041 #endif
00042
00043 #ifndef LOG_MAX
00044 #define LOG_MAX 1.0e100
00045 #endif
00046
00047 #ifndef M_E
00048 #define M_E 2.7182818284590452354
00049 #endif
00050
00051 #ifndef M_LOG2E
00052 #define M_LOG2E 1.4426950408889634074
00053 #endif
00054
00055 #ifndef M_LOG2E
00056 #define M_LOG10E 0.43429448190325182765
00057 #endif
00058
00059 #ifndef M_LN2
00060 #define M_LN2 0.69314718055994530942
00061 #endif
00062
00063 #ifndef M_LN10
00064 #define M_LN10 2.30258509299404568402
00065 #endif
00066
00067 #ifndef M_PI
00068 #define M_PI 3.14159265358979323846
00069 #endif
00070
00071 #ifndef M_PI_2
00072 #define M_PI_2 1.57079632679489661923
00073 #endif
00074
00075 #ifndef M_PI_4
00076 #define M_PI_4 0.78539816339744830962
00077 #endif
00078
00079 #ifndef M_1_PI
00080 #define M_1_PI 0.31830988618379067154
00081 #endif
00082
00083 #ifndef M_2_PI
00084 #define M_2_PI 0.63661977236758134308
00085 #endif
00086
00087 #ifndef M_2_SQRTPI
00088 #define M_2_SQRTPI 1.12837916709551257390
00089 #endif
00090
00091 #ifndef M_SQRT2
00092 #define M_SQRT2 1.41421356237309504880
00093 #endif
00094
00095 #ifndef M_SQRT1_2
00096 #define M_SQRT1_2 0.70710678118654752440
00097 #endif
00098
00099 QWT_EXPORT double qwtCeil125(double x);
00100 QWT_EXPORT double qwtFloor125(double x);
00101 QWT_EXPORT double qwtGetMin (double *array, int size);
00102 QWT_EXPORT double qwtGetMax( double *array, int size);
00103 QWT_EXPORT void qwtTwistArray(double *array, int size);
00104 QWT_EXPORT int qwtChkMono(double *array, int size);
00105 QWT_EXPORT void qwtLinSpace(double *array, int size, double xmin, double xmax);
00106 QWT_EXPORT void qwtLogSpace(double *array, int size, double xmin, double xmax);
00107
00108
00109 #define qwtMax QMAX
00110 #define qwtMin QMIN
00111 #define qwtAbs QABS
00112 #define qwtInt qRound
00113
00115 template <class T>
00116 inline int qwtSign(const T& x)
00117 {
00118 if (x > T(0))
00119 return 1;
00120 else if (x < T(0))
00121 return (-1);
00122 else
00123 return 0;
00124 }
00125
00127 template <class T>
00128 inline T qwtSqr(const T&x)
00129 {
00130 return x*x;
00131 }
00132
00139 template <class T>
00140 void qwtCopyArray(T *dest, T *src, int n)
00141 {
00142 int i;
00143 for (i=0; i<n;i++ )
00144 dest[i] = src[i];
00145 }
00146
00154 template <class T>
00155 void qwtShiftArray(T *arr, int size, int di)
00156 {
00157 int i, delta;
00158 T* buffer = 0;
00159
00160 delta = qwtAbs(di);
00161
00162 if ((delta > 0) && (delta < size))
00163 {
00164 if ((buffer = new T[delta]))
00165 {
00166 if (di < 0)
00167 {
00168 qwtCopyArray(buffer, arr, delta);
00169 qwtCopyArray(&arr[0], &arr[delta], size - delta);
00170 qwtCopyArray(&arr[size - delta], buffer, delta);
00171
00172 }
00173 else
00174 {
00175 qwtCopyArray(buffer, &arr[size - delta], delta);
00176 for ( i = size-delta-1; i >= 0; i-- )
00177 arr[i + delta] = arr[i];
00178 qwtCopyArray(arr, buffer, delta);
00179 }
00180 }
00181 }
00182
00183 if (buffer != 0) delete[] buffer;
00184 }
00185
00187 template <class T>
00188 void qwtSwap( T &x1, T& x2)
00189 {
00190 T tmp;
00191 tmp = x1;
00192 x1 = x2;
00193 x2 = tmp;
00194 }
00195
00196
00204 template <class T>
00205 void qwtSort(const T& x1, const T& x2, T& xmin, T& xmax)
00206 {
00207 T buffer;
00208
00209 if (x2 < x1)
00210 {
00211 buffer = x1;
00212 xmin = x2;
00213 xmax = buffer;
00214 }
00215 else
00216 {
00217 xmin = x1;
00218 xmax = x2;
00219 }
00220 }
00221
00223 template <class T>
00224 void qwtSort(T& x1, T& x2)
00225 {
00226 T buffer;
00227
00228 if (x2 < x1)
00229 {
00230 buffer = x1;
00231 x1 = x2;
00232 x2 = buffer;
00233 }
00234 }
00235
00242 template <class T>
00243 T qwtLim(const T& x, const T& x1, const T& x2)
00244 {
00245 T rv;
00246 T xmin, xmax;
00247
00248 xmin = qwtMin(x1, x2);
00249 xmax = qwtMax(x1, x2);
00250
00251 if ( x < xmin )
00252 rv = xmin;
00253 else if ( x > xmax )
00254 rv = xmax;
00255 else
00256 rv = x;
00257
00258 return rv;
00259 }
00260
00261 inline QPoint qwtPolar2Pos(const QPoint ¢er,
00262 double radius, double angle)
00263 {
00264 const double x = center.x() + radius * cos(angle);
00265 const double y = center.y() - radius * sin(angle);
00266
00267 return QPoint(qRound(x), qRound(y));
00268 }
00269
00270 inline QPoint qwtDegree2Pos(const QPoint ¢er,
00271 double radius, double angle)
00272 {
00273 return qwtPolar2Pos(center, radius, angle / 180.0 * M_PI);
00274 }
00275
00276 #endif