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

qwt_math.h

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

Generated on Sun Nov 21 11:12:43 2004 for Qwt User's Guide by doxygen 1.3.5