~ubuntu-branches/ubuntu/saucy/goldencheetah/saucy

« back to all changes in this revision

Viewing changes to qwt/src/qwt_math.h

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-08-18 07:02:45 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130818070245-zgdvb47e1k3mtgil
Tags: 3.0-3
debian/control: remove needless dependency. (Closes: #719571)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Qwt Widget Library
3
3
 * Copyright (C) 1997   Josef Wilgen
4
4
 * Copyright (C) 2002   Uwe Rathmann
5
 
 * 
 
5
 *
6
6
 * This library is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the Qwt License, Version 1.0
8
8
 *****************************************************************************/
10
10
#ifndef QWT_MATH_H
11
11
#define QWT_MATH_H
12
12
 
13
 
#include <math.h>
 
13
#include "qwt_global.h"
 
14
 
 
15
#if defined(_MSC_VER)
 
16
/*
 
17
  Microsoft says:
 
18
 
 
19
  Define _USE_MATH_DEFINES before including math.h to expose these macro
 
20
  definitions for common math constants.  These are placed under an #ifdef
 
21
  since these commonly-defined names are not part of the C/C++ standards.
 
22
*/
 
23
#define _USE_MATH_DEFINES 1
 
24
#endif
 
25
 
14
26
#include <qpoint.h>
 
27
#include <qmath.h>
15
28
#include "qwt_global.h"
16
 
#include "qwt_double_rect.h"
17
 
 
18
 
#if QT_VERSION < 0x040000
19
 
 
20
 
#define qwtMax QMAX
21
 
#define qwtMin QMIN
22
 
#define qwtAbs QABS
23
 
 
24
 
#else // QT_VERSION >= 0x040000
25
 
 
26
 
#define qwtMax qMax
27
 
#define qwtMin qMin
28
 
#define qwtAbs qAbs
29
 
 
30
 
#endif
31
29
 
32
30
#ifndef LOG10_2
33
31
#define LOG10_2     0.30102999566398119802  /* log10(2) */
107
105
#define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */
108
106
#endif
109
107
 
110
 
QWT_EXPORT double qwtGetMin(const double *array, int size);
111
 
QWT_EXPORT double qwtGetMax(const double *array, int size);
112
 
 
113
 
 
114
 
//! Return the sign 
115
 
inline int qwtSign(double x)
116
 
{
117
 
    if (x > 0.0)
118
 
       return 1;
119
 
    else if (x < 0.0)
120
 
       return (-1);
 
108
QWT_EXPORT double qwtGetMin( const double *array, int size );
 
109
QWT_EXPORT double qwtGetMax( const double *array, int size );
 
110
 
 
111
/*!
 
112
  \brief Compare 2 values, relative to an interval
 
113
 
 
114
  Values are "equal", when :
 
115
  \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$
 
116
 
 
117
  \param value1 First value to compare
 
118
  \param value2 Second value to compare
 
119
  \param intervalSize interval size
 
120
 
 
121
  \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2
 
122
*/
 
123
inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
 
124
{
 
125
    const double eps = qAbs( 1.0e-6 * intervalSize );
 
126
 
 
127
    if ( value2 - value1 > eps )
 
128
        return -1;
 
129
 
 
130
    if ( value1 - value2 > eps )
 
131
        return 1;
 
132
 
 
133
    return 0;
 
134
}
 
135
 
 
136
 
 
137
inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
 
138
{
 
139
    return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
 
140
}
 
141
 
 
142
inline bool qwtFuzzyLessOrEqual( double d1, double d2 )
 
143
{
 
144
    return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );
 
145
}
 
146
 
 
147
//! Return the sign
 
148
inline int qwtSign( double x )
 
149
{
 
150
    if ( x > 0.0 )
 
151
        return 1;
 
152
    else if ( x < 0.0 )
 
153
        return ( -1 );
121
154
    else
122
 
       return 0;
123
 
}            
 
155
        return 0;
 
156
}
124
157
 
125
158
//! Return the square of a number
126
 
inline double qwtSqr(const double x)
127
 
{
128
 
    return x*x;
129
 
}
130
 
 
131
 
/*!
132
 
  \brief Limit a value to fit into a specified interval
133
 
  \param x Input value
134
 
  \param x1 First interval boundary
135
 
  \param x2 Second interval boundary  
136
 
*/
137
 
template <class T>
138
 
T qwtLim(const T& x, const T& x1, const T& x2)
139
 
{
140
 
    T rv;
141
 
    T xmin, xmax;
142
 
    
143
 
    xmin = qwtMin(x1, x2);
144
 
    xmax = qwtMax(x1, x2);
145
 
 
146
 
    if ( x < xmin )
147
 
       rv = xmin;
148
 
    else if ( x > xmax )
149
 
       rv = xmax;
150
 
    else
151
 
       rv = x;
152
 
 
153
 
    return rv;
154
 
}
155
 
 
156
 
inline QPoint qwtPolar2Pos(const QPoint &pole,
157
 
    double radius, double angle)
158
 
{
159
 
    const double x = pole.x() + radius * ::cos(angle);
160
 
    const double y = pole.y() - radius * ::sin(angle);
161
 
 
162
 
    return QPoint(qRound(x), qRound(y));
163
 
}
164
 
 
165
 
inline QPoint qwtDegree2Pos(const QPoint &pole,
166
 
    double radius, double angle)
167
 
{
168
 
    return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI);
169
 
}
170
 
 
171
 
inline QwtDoublePoint qwtPolar2Pos(const QwtDoublePoint &pole,
172
 
    double radius, double angle)
173
 
{
174
 
    const double x = pole.x() + radius * ::cos(angle);
175
 
    const double y = pole.y() - radius * ::sin(angle);
176
 
 
177
 
    return QPoint(qRound(x), qRound(y));
178
 
}
179
 
 
180
 
inline QwtDoublePoint qwtDegree2Pos(const QwtDoublePoint &pole,
181
 
    double radius, double angle)
182
 
{
183
 
    return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI);
184
 
}
185
 
 
186
 
//! Rounding of doubles, like qRound for integers
187
 
inline double qwtRound(double value)
188
 
{
189
 
    return ::floor(value + 0.5); // MSVC has no ::round().
 
159
inline double qwtSqr( double x )
 
160
{
 
161
    return x * x;
 
162
}
 
163
 
 
164
//! Like qRound, but without converting the result to an int
 
165
inline double qwtRoundF(double d)
 
166
{
 
167
    return ::floor( d + 0.5 );
 
168
}
 
169
 
 
170
//! Like qFloor, but without converting the result to an int
 
171
inline double qwtFloorF(double d)
 
172
{
 
173
    return ::floor( d );
 
174
}
 
175
 
 
176
//! Like qCeil, but without converting the result to an int
 
177
inline double qwtCeilF(double d)
 
178
{
 
179
    return ::ceil( d );
190
180
}
191
181
 
192
182
#endif