Qwt User's Guide
|
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 "qwt_global.h" 00014 00015 #if defined(_MSC_VER) 00016 /* 00017 Microsoft says: 00018 00019 Define _USE_MATH_DEFINES before including math.h to expose these macro 00020 definitions for common math constants. These are placed under an #ifdef 00021 since these commonly-defined names are not part of the C/C++ standards. 00022 */ 00023 #define _USE_MATH_DEFINES 1 00024 #endif 00025 00026 #include <qmath.h> 00027 #include "qwt_global.h" 00028 00029 #ifndef M_PI_2 00030 // For Qt <= 4.8.4 M_PI_2 is not known by MinGW-w64 00031 // when compiling with -std=c++11 00032 #define M_PI_2 (1.57079632679489661923) 00033 #endif 00034 00035 #ifndef LOG_MIN 00036 00037 #define LOG_MIN 1.0e-100 00038 #endif 00039 00040 #ifndef LOG_MAX 00041 00042 #define LOG_MAX 1.0e100 00043 #endif 00044 00045 QWT_EXPORT double qwtGetMin( const double *array, int size ); 00046 QWT_EXPORT double qwtGetMax( const double *array, int size ); 00047 00048 QWT_EXPORT double qwtNormalizeRadians( double radians ); 00049 QWT_EXPORT double qwtNormalizeDegrees( double degrees ); 00050 00063 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize ) 00064 { 00065 const double eps = qAbs( 1.0e-6 * intervalSize ); 00066 00067 if ( value2 - value1 > eps ) 00068 return -1; 00069 00070 if ( value1 - value2 > eps ) 00071 return 1; 00072 00073 return 0; 00074 } 00075 00076 00077 inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 ) 00078 { 00079 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 ); 00080 } 00081 00082 inline bool qwtFuzzyLessOrEqual( double d1, double d2 ) 00083 { 00084 return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 ); 00085 } 00086 00088 inline int qwtSign( double x ) 00089 { 00090 if ( x > 0.0 ) 00091 return 1; 00092 else if ( x < 0.0 ) 00093 return ( -1 ); 00094 else 00095 return 0; 00096 } 00097 00099 inline double qwtSqr( double x ) 00100 { 00101 return x * x; 00102 } 00103 00105 inline double qwtFastAtan( double x ) 00106 { 00107 if ( x < -1.0 ) 00108 return -M_PI_2 - x / ( x * x + 0.28 ); 00109 00110 if ( x > 1.0 ) 00111 return M_PI_2 - x / ( x * x + 0.28 ); 00112 00113 return x / ( 1.0 + x * x * 0.28 ); 00114 } 00115 00117 inline double qwtFastAtan2( double y, double x ) 00118 { 00119 if ( x > 0 ) 00120 return qwtFastAtan( y / x ); 00121 00122 if ( x < 0 ) 00123 { 00124 const double d = qwtFastAtan( y / x ); 00125 return ( y >= 0 ) ? d + M_PI : d - M_PI; 00126 } 00127 00128 if ( y < 0.0 ) 00129 return -M_PI_2; 00130 00131 if ( y > 0.0 ) 00132 return M_PI_2; 00133 00134 return 0.0; 00135 } 00136 00138 inline double qwtRadians( double degrees ) 00139 { 00140 return degrees * M_PI / 180.0; 00141 } 00142 00144 inline double qwtDegrees( double degrees ) 00145 { 00146 return degrees * 180.0 / M_PI; 00147 } 00148 00149 #endif