37#include "qwt_global.h"
46#ifndef _USE_MATH_DEFINES
47#define _USE_MATH_DEFINES
48#define undef_USE_MATH_DEFINES
53#ifdef undef_USE_MATH_DEFINES
54#undef _USE_MATH_DEFINES
55#undef undef_USE_MATH_DEFINES
59#define M_E (2.7182818284590452354)
63#define M_LOG2E (1.4426950408889634074)
67#define M_LOG10E (0.43429448190325182765)
71#define M_LN2 (0.69314718055994530942)
75#define M_LN10 (2.30258509299404568402)
79#define M_PI (3.14159265358979323846)
83#define M_PI_2 (1.57079632679489661923)
87#define M_PI_4 (0.78539816339744830962)
91#define M_1_PI (0.31830988618379067154)
95#define M_2_PI (0.63661977236758134308)
99#define M_2_SQRTPI (1.12837916709551257390)
103#define M_SQRT2 (1.41421356237309504880)
107#define M_SQRT1_2 (0.70710678118654752440)
110#if defined(QT_WARNING_PUSH)
116QT_WARNING_DISABLE_CLANG(
"-Wdouble-promotion")
117QT_WARNING_DISABLE_GCC("-Wdouble-promotion")
126QWT_CONSTEXPR
inline float qwtMinF(
float a,
float b)
128 return (a < b) ? a : b;
132QWT_CONSTEXPR
inline double qwtMinF(
double a,
double b)
134 return (a < b) ? a : b;
138QWT_CONSTEXPR
inline qreal qwtMinF(
float a,
double b)
140 return (a < b) ? a : b;
144QWT_CONSTEXPR
inline qreal qwtMinF(
double a,
float b)
146 return (a < b) ? a : b;
150QWT_CONSTEXPR
inline float qwtMaxF(
float a,
float b)
152 return (a < b) ? b : a;
156QWT_CONSTEXPR
inline double qwtMaxF(
double a,
double b)
158 return (a < b) ? b : a;
162QWT_CONSTEXPR
inline qreal qwtMaxF(
float a,
double b)
164 return (a < b) ? b : a;
168QWT_CONSTEXPR
inline qreal qwtMaxF(
double a,
float b)
170 return (a < b) ? b : a;
173#if defined(QT_WARNING_POP)
177QWT_EXPORT
double qwtNormalizeRadians(
double radians);
178QWT_EXPORT
double qwtNormalizeDegrees(
double degrees);
179QWT_EXPORT quint32 qwtRand();
193inline int qwtFuzzyCompare(
double value1,
double value2,
double intervalSize)
195 const double eps = qAbs(1.0e-6 * intervalSize);
197 if (value2 - value1 > eps)
200 if (value1 - value2 > eps)
207inline int qwtSign(
double x)
218inline double qwtSqr(
double x)
224inline double qwtFastAtan(
double x)
227 return -M_PI_2 - x / (x * x + 0.28);
230 return M_PI_2 - x / (x * x + 0.28);
232 return x / (1.0 + x * x * 0.28);
236inline double qwtFastAtan2(
double y,
double x)
239 return qwtFastAtan(y / x);
242 const double d = qwtFastAtan(y / x);
243 return (y >= 0) ? d + M_PI : d - M_PI;
266inline double qwtCubicPolynomial(
double x,
double a,
double b,
double c,
double d)
268 return (((a * x) + b) * x + c) * x + d;
272inline double qwtRadians(
double degrees)
274 return degrees * M_PI / 180.0;
278inline double qwtDegrees(
double degrees)
280 return degrees * 180.0 / M_PI;
287inline int qwtCeil(qreal value)
290 return int(ceil(value));
296inline int qwtFloor(qreal value)
299 return int(floor(value));
322inline int qwtVerifyRange(
int size,
int& i1,
int& i2)
327 i1 = qBound(0, i1, size - 1);
328 i2 = qBound(0, i2, size - 1);
333 return (i2 - i1 + 1);
342inline double qwtDistance(
const QPointF& p1,
const QPointF& p2)
344 double dx = p2.x() - p1.x();
345 double dy = p2.y() - p1.y();
346 return qSqrt(dx * dx + dy * dy);
377template<
typename T >
378inline typename std::enable_if< std::is_floating_point< T >::value,
bool >::type qwt_is_nan_or_inf(
const T& value)
380 return !std::isfinite(value);
406inline bool qwt_is_nan_or_inf(
const QPointF& point)
408 return !std::isfinite(point.x()) || !std::isfinite(point.y());
412template<
typename T >
413typename std::enable_if< !std::is_floating_point< T >::value && !std::is_same< T, QPointF >::value,
414 bool >::type
inline qwt_is_nan_or_inf(
const T& )
442template<
typename InputIt >
443inline bool qwtContainsNanOrInf(InputIt first, InputIt last)
446 for (InputIt it = first; it != last; ++it) {
447 if (qwt_is_nan_or_inf(*it)) {
470template<
typename Container >
471inline std::size_t qwtRemoveNanOrInf(Container& container)
474 auto new_end = std::remove_if(container.begin(), container.end(), [](
const typename Container::value_type& value) {
475 return qwt_is_nan_or_inf(value);
479 std::size_t removed_count = std::distance(new_end, container.end());
482 if (removed_count > 0) {
483 container.erase(new_end, container.end());
486 return removed_count;
495template<
typename Container >
496inline Container qwtRemoveNanOrInfCopy(
const Container& container)
499 result.reserve(container.size());
502 std::copy_if(container.begin(),
504 std::back_inserter(result),
505 [](
const typename Container::value_type& value) { return !qwt_is_nan_or_inf(value); });
569template<
typename It1,
typename It2 >
570bool fuzzyRangeEqual(It1 first1, It1 last1, It2 first2, It2 last2)
573 if (std::distance(first1, last1) != std::distance(first2, last2))
577 for (; first1 != last1; ++first1, ++first2) {
578 if (!qFuzzyCompare(*first1, *first2))