00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_MATH_H
00011 #define QWT_MATH_H
00012
00013 #include "qwt_global.h"
00014
00015 #if defined(_MSC_VER)
00016
00017
00018
00019
00020
00021
00022
00023 #define _USE_MATH_DEFINES 1
00024 #endif
00025
00026 #include <qpoint.h>
00027 #include <qmath.h>
00028 #include "qwt_global.h"
00029
00030 #ifndef LOG10_2
00031 #define LOG10_2 0.30102999566398119802
00032 #endif
00033
00034 #ifndef LOG10_3
00035 #define LOG10_3 0.47712125471966243540
00036 #endif
00037
00038 #ifndef LOG10_5
00039 #define LOG10_5 0.69897000433601885749
00040 #endif
00041
00042 #ifndef M_2PI
00043 #define M_2PI 6.28318530717958623200
00044 #endif
00045
00046 #ifndef LOG_MIN
00047
00048 #define LOG_MIN 1.0e-100
00049 #endif
00050
00051 #ifndef LOG_MAX
00052
00053 #define LOG_MAX 1.0e100
00054 #endif
00055
00056 #ifndef M_E
00057 #define M_E 2.7182818284590452354
00058 #endif
00059
00060 #ifndef M_LOG2E
00061 #define M_LOG2E 1.4426950408889634074
00062 #endif
00063
00064 #ifndef M_LOG10E
00065 #define M_LOG10E 0.43429448190325182765
00066 #endif
00067
00068 #ifndef M_LN2
00069 #define M_LN2 0.69314718055994530942
00070 #endif
00071
00072 #ifndef M_LN10
00073 #define M_LN10 2.30258509299404568402
00074 #endif
00075
00076 #ifndef M_PI
00077 #define M_PI 3.14159265358979323846
00078 #endif
00079
00080 #ifndef M_PI_2
00081 #define M_PI_2 1.57079632679489661923
00082 #endif
00083
00084 #ifndef M_PI_4
00085 #define M_PI_4 0.78539816339744830962
00086 #endif
00087
00088 #ifndef M_1_PI
00089 #define M_1_PI 0.31830988618379067154
00090 #endif
00091
00092 #ifndef M_2_PI
00093 #define M_2_PI 0.63661977236758134308
00094 #endif
00095
00096 #ifndef M_2_SQRTPI
00097 #define M_2_SQRTPI 1.12837916709551257390
00098 #endif
00099
00100 #ifndef M_SQRT2
00101 #define M_SQRT2 1.41421356237309504880
00102 #endif
00103
00104 #ifndef M_SQRT1_2
00105 #define M_SQRT1_2 0.70710678118654752440
00106 #endif
00107
00108 QWT_EXPORT double qwtGetMin( const double *array, int size );
00109 QWT_EXPORT double qwtGetMax( const double *array, int size );
00110
00123 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
00124 {
00125 const double eps = qAbs( 1.0e-6 * intervalSize );
00126
00127 if ( value2 - value1 > eps )
00128 return -1;
00129
00130 if ( value1 - value2 > eps )
00131 return 1;
00132
00133 return 0;
00134 }
00135
00136
00137 inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
00138 {
00139 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
00140 }
00141
00142 inline bool qwtFuzzyLessOrEqual( double d1, double d2 )
00143 {
00144 return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );
00145 }
00146
00148 inline int qwtSign( double x )
00149 {
00150 if ( x > 0.0 )
00151 return 1;
00152 else if ( x < 0.0 )
00153 return ( -1 );
00154 else
00155 return 0;
00156 }
00157
00159 inline double qwtSqr( const double x )
00160 {
00161 return x * x;
00162 }
00163
00170 template <class T>
00171 T qwtLim( const T& x, const T& x1, const T& x2 )
00172 {
00173 T rv;
00174 T xmin, xmax;
00175
00176 xmin = qMin( x1, x2 );
00177 xmax = qMax( x1, x2 );
00178
00179 if ( x < xmin )
00180 rv = xmin;
00181 else if ( x > xmax )
00182 rv = xmax;
00183 else
00184 rv = x;
00185
00186 return rv;
00187 }
00188
00189 inline QPoint qwtPolar2Pos( const QPoint &pole,
00190 double radius, double angle )
00191 {
00192 const double x = pole.x() + radius * qCos( angle );
00193 const double y = pole.y() - radius * qSin( angle );
00194
00195 return QPoint( qRound( x ), qRound( y ) );
00196 }
00197
00198 inline QPoint qwtDegree2Pos( const QPoint &pole,
00199 double radius, double angle )
00200 {
00201 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
00202 }
00203
00204 inline QPointF qwtPolar2Pos( const QPointF &pole,
00205 double radius, double angle )
00206 {
00207 const double x = pole.x() + radius * qCos( angle );
00208 const double y = pole.y() - radius * qSin( angle );
00209
00210 return QPoint( qRound( x ), qRound( y ) );
00211 }
00212
00213 inline QPointF qwtDegree2Pos( const QPointF &pole,
00214 double radius, double angle )
00215 {
00216 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
00217 }
00218
00219 #endif