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 <math.h>
00027 #include <qpoint.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
00048 #define LOG_MIN 1.0e-100
00049 #endif
00050
00051 #ifndef LOG_MAX
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
00111
00112 inline bool qwtFuzzyGreaterOrEqual(double d1, double d2)
00113 {
00114 return (d1 >= d2) || qFuzzyCompare(d1, d2);
00115 }
00116
00117 inline bool qwtFuzzyLessOrEqual(double d1, double d2)
00118 {
00119 return (d1 <= d2) || qFuzzyCompare(d1, d2);
00120 }
00121
00123 inline int qwtSign(double x)
00124 {
00125 if (x > 0.0)
00126 return 1;
00127 else if (x < 0.0)
00128 return (-1);
00129 else
00130 return 0;
00131 }
00132
00134 inline double qwtSqr(const double x)
00135 {
00136 return x*x;
00137 }
00138
00145 template <class T>
00146 T qwtLim(const T& x, const T& x1, const T& x2)
00147 {
00148 T rv;
00149 T xmin, xmax;
00150
00151 xmin = qMin(x1, x2);
00152 xmax = qMax(x1, x2);
00153
00154 if ( x < xmin )
00155 rv = xmin;
00156 else if ( x > xmax )
00157 rv = xmax;
00158 else
00159 rv = x;
00160
00161 return rv;
00162 }
00163
00164 inline QPoint qwtPolar2Pos(const QPoint &pole,
00165 double radius, double angle)
00166 {
00167 const double x = pole.x() + radius * ::cos(angle);
00168 const double y = pole.y() - radius * ::sin(angle);
00169
00170 return QPoint(qRound(x), qRound(y));
00171 }
00172
00173 inline QPoint qwtDegree2Pos(const QPoint &pole,
00174 double radius, double angle)
00175 {
00176 return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI);
00177 }
00178
00179 inline QPointF qwtPolar2Pos(const QPointF &pole,
00180 double radius, double angle)
00181 {
00182 const double x = pole.x() + radius * ::cos(angle);
00183 const double y = pole.y() - radius * ::sin(angle);
00184
00185 return QPoint(qRound(x), qRound(y));
00186 }
00187
00188 inline QPointF qwtDegree2Pos(const QPointF &pole,
00189 double radius, double angle)
00190 {
00191 return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI);
00192 }
00193
00194 #endif