地面站终端 App
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.1 KiB

15 years ago
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
15 years ago
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_MATH_H
#define QWT_MATH_H
#include <math.h>
15 years ago
#include <qpoint.h>
#include "qwt_global.h"
#include "qwt_double_rect.h"
#if QT_VERSION < 0x040000
#define qwtMax QMAX
#define qwtMin QMIN
#define qwtAbs QABS
#else // QT_VERSION >= 0x040000
fix qmin/qmax types qreal is a double on some platforms (x86) and a float on others (e.g. ARM), cast it to fix build errors like these: src/ui/designer/QGCXYPlot.cc: In member function 'int XYPlotCurve::appendData(const QPointF&)': src/ui/designer/QGCXYPlot.cc:41:39: error: no matching function for call to 'qMin(double&, qreal)' xmin = qMin(xmin, data.x()); ^ src/ui/designer/QGCXYPlot.cc:41:39: note: candidate is: In file included from /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtCore/qnamespace.h:45:0, from /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtCore/qobjectdefs.h:45, from /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtGui/qwindowdefs.h:45, from /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtGui/qwidget.h:46, from /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtGui/qdockwidget.h:45, from /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtGui/QDockWidget:1, from src/ui/designer/QGCXYPlot.cc:1: /build/v2013.12/build/tmp-angstrom_v2013_12-eglibc/sysroots/sama5d3_xplained/usr/include/qt4/QtCore/qglobal.h:1213:34: note: template<class T> const T& qMin(const T&, const T&) Q_DECL_CONSTEXPR inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; } ^ See http://www.qtcentre.org/archive/index.php/t-45475.html for some background. This fixes #625 Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
11 years ago
#define qwtMax(x,y) qMax(qreal(x),qreal(y))
#define qwtMin(x,y) qMin(qreal(x),qreal(y))
15 years ago
#define qwtAbs qAbs
#endif
#ifndef LOG10_2
#define LOG10_2 0.30102999566398119802 /* log10(2) */
#endif
#ifndef LOG10_3
#define LOG10_3 0.47712125471966243540 /* log10(3) */
#endif
#ifndef LOG10_5
#define LOG10_5 0.69897000433601885749 /* log10(5) */
#endif
#ifndef M_2PI
#define M_2PI 6.28318530717958623200 /* 2 pi */
#endif
#ifndef LOG_MIN
//! Mininum value for logarithmic scales
#define LOG_MIN 1.0e-100
#endif
#ifndef LOG_MAX
//! Maximum value for logarithmic scales
#define LOG_MAX 1.0e100
#endif
#ifndef M_E
#define M_E 2.7182818284590452354 /* e */
#endif
#ifndef M_LOG2E
#define M_LOG2E 1.4426950408889634074 /* log_2 e */
#endif
#ifndef M_LOG10E
#define M_LOG10E 0.43429448190325182765 /* log_10 e */
#endif
#ifndef M_LN2
#define M_LN2 0.69314718055994530942 /* log_e 2 */
#endif
#ifndef M_LN10
#define M_LN10 2.30258509299404568402 /* log_e 10 */
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
#ifndef M_PI_4
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#endif
#ifndef M_1_PI
#define M_1_PI 0.31830988618379067154 /* 1/pi */
#endif
#ifndef M_2_PI
#define M_2_PI 0.63661977236758134308 /* 2/pi */
#endif
#ifndef M_2_SQRTPI
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
#endif
#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#endif
#ifndef M_SQRT1_2
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#endif
QWT_EXPORT double qwtGetMin(const double *array, int size);
QWT_EXPORT double qwtGetMax(const double *array, int size);
//! Return the sign
15 years ago
inline int qwtSign(double x)
{
if (x > 0.0)
return 1;
15 years ago
else if (x < 0.0)
return (-1);
15 years ago
else
return 0;
}
15 years ago
//! Return the square of a number
inline double qwtSqr(const double x)
{
return x*x;
}
/*!
\brief Limit a value to fit into a specified interval
\param x Input value
\param x1 First interval boundary
\param x2 Second interval boundary
15 years ago
*/
template <class T>
T qwtLim(const T& x, const T& x1, const T& x2)
{
T rv;
T xmin, xmax;
15 years ago
xmin = qwtMin(x1, x2);
xmax = qwtMax(x1, x2);
if ( x < xmin )
rv = xmin;
15 years ago
else if ( x > xmax )
rv = xmax;
15 years ago
else
rv = x;
15 years ago
return rv;
}
inline QPoint qwtPolar2Pos(const QPoint &pole,
double radius, double angle)
15 years ago
{
const double x = pole.x() + radius * ::cos(angle);
const double y = pole.y() - radius * ::sin(angle);
return QPoint(qRound(x), qRound(y));
}
inline QPoint qwtDegree2Pos(const QPoint &pole,
double radius, double angle)
15 years ago
{
return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI);
}
inline QwtDoublePoint qwtPolar2Pos(const QwtDoublePoint &pole,
double radius, double angle)
15 years ago
{
const double x = pole.x() + radius * ::cos(angle);
const double y = pole.y() - radius * ::sin(angle);
return QPoint(qRound(x), qRound(y));
}
inline QwtDoublePoint qwtDegree2Pos(const QwtDoublePoint &pole,
double radius, double angle)
15 years ago
{
return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI);
}
//! Rounding of doubles, like qRound for integers
inline double qwtRound(double value)
{
return ::floor(value + 0.5); // MSVC has no ::round().
}
#endif