Eneboo - Documentación para desarrolladores
|
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 00010 #ifndef QWT_MATH_H 00011 #define QWT_MATH_H 00012 00013 #include <math.h> 00014 #include <qpoint.h> 00015 #include "qwt_global.h" 00016 #include "qwt_double_rect.h" 00017 00018 #if QT_VERSION < 0x040000 00019 00020 #define qwtMax QMAX 00021 #define qwtMin QMIN 00022 #define qwtAbs QABS 00023 00024 #else // QT_VERSION >= 0x040000 00025 00026 #define qwtMax qMax 00027 #define qwtMin qMin 00028 #define qwtAbs qAbs 00029 00030 #endif 00031 00032 #ifndef LOG10_2 00033 #define LOG10_2 0.30102999566398119802 /* log10(2) */ 00034 #endif 00035 00036 #ifndef LOG10_3 00037 #define LOG10_3 0.47712125471966243540 /* log10(3) */ 00038 #endif 00039 00040 #ifndef LOG10_5 00041 #define LOG10_5 0.69897000433601885749 /* log10(5) */ 00042 #endif 00043 00044 #ifndef M_2PI 00045 #define M_2PI 6.28318530717958623200 /* 2 pi */ 00046 #endif 00047 00048 #ifndef LOG_MIN 00049 00050 #define LOG_MIN 1.0e-100 00051 #endif 00052 00053 #ifndef LOG_MAX 00054 00055 #define LOG_MAX 1.0e100 00056 #endif 00057 00058 #ifndef M_E 00059 #define M_E 2.7182818284590452354 /* e */ 00060 #endif 00061 00062 #ifndef M_LOG2E 00063 #define M_LOG2E 1.4426950408889634074 /* log_2 e */ 00064 #endif 00065 00066 #ifndef M_LOG10E 00067 #define M_LOG10E 0.43429448190325182765 /* log_10 e */ 00068 #endif 00069 00070 #ifndef M_LN2 00071 #define M_LN2 0.69314718055994530942 /* log_e 2 */ 00072 #endif 00073 00074 #ifndef M_LN10 00075 #define M_LN10 2.30258509299404568402 /* log_e 10 */ 00076 #endif 00077 00078 #ifndef M_PI 00079 #define M_PI 3.14159265358979323846 /* pi */ 00080 #endif 00081 00082 #ifndef M_PI_2 00083 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 00084 #endif 00085 00086 #ifndef M_PI_4 00087 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 00088 #endif 00089 00090 #ifndef M_1_PI 00091 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 00092 #endif 00093 00094 #ifndef M_2_PI 00095 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 00096 #endif 00097 00098 #ifndef M_2_SQRTPI 00099 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 00100 #endif 00101 00102 #ifndef M_SQRT2 00103 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 00104 #endif 00105 00106 #ifndef M_SQRT1_2 00107 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 00108 #endif 00109 00110 QWT_EXPORT double qwtGetMin(const double *array, int size); 00111 QWT_EXPORT double qwtGetMax(const double *array, int size); 00112 00113 00115 inline int qwtSign(double x) 00116 { 00117 if (x > 0.0) 00118 return 1; 00119 else if (x < 0.0) 00120 return (-1); 00121 else 00122 return 0; 00123 } 00124 00126 inline double qwtSqr(const double x) 00127 { 00128 return x*x; 00129 } 00130 00137 template <class T> 00138 T qwtLim(const T& x, const T& x1, const T& x2) 00139 { 00140 T rv; 00141 T xmin, xmax; 00142 00143 xmin = qwtMin(x1, x2); 00144 xmax = qwtMax(x1, x2); 00145 00146 if ( x < xmin ) 00147 rv = xmin; 00148 else if ( x > xmax ) 00149 rv = xmax; 00150 else 00151 rv = x; 00152 00153 return rv; 00154 } 00155 00156 inline QPoint qwtPolar2Pos(const QPoint &pole, 00157 double radius, double angle) 00158 { 00159 const double x = pole.x() + radius * ::cos(angle); 00160 const double y = pole.y() - radius * ::sin(angle); 00161 00162 return QPoint(qRound(x), qRound(y)); 00163 } 00164 00165 inline QPoint qwtDegree2Pos(const QPoint &pole, 00166 double radius, double angle) 00167 { 00168 return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI); 00169 } 00170 00171 inline QwtDoublePoint qwtPolar2Pos(const QwtDoublePoint &pole, 00172 double radius, double angle) 00173 { 00174 const double x = pole.x() + radius * ::cos(angle); 00175 const double y = pole.y() - radius * ::sin(angle); 00176 00177 return QPoint(qRound(x), qRound(y)); 00178 } 00179 00180 inline QwtDoublePoint qwtDegree2Pos(const QwtDoublePoint &pole, 00181 double radius, double angle) 00182 { 00183 return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI); 00184 } 00185 00187 inline double qwtRound(double value) 00188 { 00189 return ::floor(value + 0.5); // MSVC has no ::round(). 00190 } 00191 00192 #endif