Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | 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 #if QT_VERSION < 0x040000
00023 
00024 #define qwtMax QMAX
00025 #define qwtMin QMIN
00026 #define qwtAbs QABS
00027 
00028 #else // QT_VERSION >= 0x040000
00029 
00030 #define qwtMax qMax
00031 #define qwtMin qMin
00032 #define qwtAbs qAbs
00033 
00034 #endif
00035 
00036 #ifndef LOG10_2
00037 #define LOG10_2     0.30102999566398119802  /* log10(2) */
00038 #endif
00039 
00040 #ifndef LOG10_3
00041 #define LOG10_3     0.47712125471966243540  /* log10(3) */
00042 #endif
00043 
00044 #ifndef LOG10_5
00045 #define LOG10_5     0.69897000433601885749  /* log10(5) */
00046 #endif
00047 
00048 #ifndef M_2PI
00049 #define M_2PI       6.28318530717958623200  /* 2 pi */
00050 #endif
00051 
00052 #ifndef LOG_MIN
00053 
00054 #define LOG_MIN 1.0e-100
00055 #endif
00056 
00057 #ifndef LOG_MAX
00058 
00059 #define LOG_MAX 1.0e100
00060 #endif
00061 
00062 #ifndef M_E
00063 #define M_E            2.7182818284590452354   /* e */
00064 #endif
00065 
00066 #ifndef M_LOG2E
00067 #define M_LOG2E 1.4426950408889634074   /* log_2 e */
00068 #endif
00069 
00070 #ifndef M_LOG2E
00071 #define M_LOG10E    0.43429448190325182765  /* log_10 e */
00072 #endif
00073 
00074 #ifndef M_LN2
00075 #define M_LN2       0.69314718055994530942  /* log_e 2 */
00076 #endif
00077 
00078 #ifndef M_LN10
00079 #define M_LN10         2.30258509299404568402  /* log_e 10 */
00080 #endif
00081 
00082 #ifndef M_PI
00083 #define M_PI        3.14159265358979323846  /* pi */
00084 #endif
00085 
00086 #ifndef M_PI_2
00087 #define M_PI_2      1.57079632679489661923  /* pi/2 */
00088 #endif
00089 
00090 #ifndef M_PI_4
00091 #define M_PI_4      0.78539816339744830962  /* pi/4 */
00092 #endif
00093 
00094 #ifndef M_1_PI
00095 #define M_1_PI      0.31830988618379067154  /* 1/pi */
00096 #endif
00097 
00098 #ifndef M_2_PI
00099 #define M_2_PI      0.63661977236758134308  /* 2/pi */
00100 #endif
00101 
00102 #ifndef M_2_SQRTPI
00103 #define M_2_SQRTPI  1.12837916709551257390  /* 2/sqrt(pi) */
00104 #endif
00105 
00106 #ifndef M_SQRT2
00107 #define M_SQRT2 1.41421356237309504880  /* sqrt(2) */
00108 #endif
00109 
00110 #ifndef M_SQRT1_2
00111 #define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */
00112 #endif
00113 
00114 QWT_EXPORT double qwtGetMin(const double *array, int size);
00115 QWT_EXPORT double qwtGetMax(const double *array, int size);
00116 
00117 
00119 inline int qwtSign(double x)
00120 {
00121     if (x > 0.0)
00122        return 1;
00123     else if (x < 0.0)
00124        return (-1);
00125     else
00126        return 0;
00127 }            
00128 
00130 inline double qwtSqr(const double x)
00131 {
00132     return x*x;
00133 }
00134 
00141 template <class T>
00142 T qwtLim(const T& x, const T& x1, const T& x2)
00143 {
00144     T rv;
00145     T xmin, xmax;
00146     
00147     xmin = qwtMin(x1, x2);
00148     xmax = qwtMax(x1, x2);
00149 
00150     if ( x < xmin )
00151        rv = xmin;
00152     else if ( x > xmax )
00153        rv = xmax;
00154     else
00155        rv = x;
00156 
00157     return rv;
00158 }
00159 
00160 inline QPoint qwtPolar2Pos(const QPoint &center,
00161     double radius, double angle)
00162 {
00163     const double x = center.x() + radius * cos(angle);
00164     const double y = center.y() - radius * sin(angle);
00165 
00166     return QPoint(qRound(x), qRound(y));
00167 }
00168 
00169 inline QPoint qwtDegree2Pos(const QPoint &center,
00170     double radius, double angle)
00171 {
00172     return qwtPolar2Pos(center, radius, angle / 180.0 * M_PI);
00173 }
00174 
00175 #endif

Generated on Mon Jan 30 22:16:25 2006 for Qwt User's Guide by  doxygen 1.4.4