~l3on/ubuntu/oneiric/qwt/fix-921430

« back to all changes in this revision

Viewing changes to qwt-5.0.2/src/qwt_math.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 * 
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the Qwt License, Version 1.0
 
8
 *****************************************************************************/
 
9
 
 
10
#ifndef QWT_MATH_H
 
11
#define QWT_MATH_H
 
12
 
 
13
#include <math.h>
 
14
#include <qpoint.h>
 
15
#include "qwt_global.h"
 
16
 
 
17
#if QT_VERSION < 0x040000
 
18
 
 
19
#define qwtMax QMAX
 
20
#define qwtMin QMIN
 
21
#define qwtAbs QABS
 
22
 
 
23
#else // QT_VERSION >= 0x040000
 
24
 
 
25
#define qwtMax qMax
 
26
#define qwtMin qMin
 
27
#define qwtAbs qAbs
 
28
 
 
29
#endif
 
30
 
 
31
#ifndef LOG10_2
 
32
#define LOG10_2     0.30102999566398119802  /* log10(2) */
 
33
#endif
 
34
 
 
35
#ifndef LOG10_3
 
36
#define LOG10_3     0.47712125471966243540  /* log10(3) */
 
37
#endif
 
38
 
 
39
#ifndef LOG10_5
 
40
#define LOG10_5     0.69897000433601885749  /* log10(5) */
 
41
#endif
 
42
 
 
43
#ifndef M_2PI
 
44
#define M_2PI       6.28318530717958623200  /* 2 pi */
 
45
#endif
 
46
 
 
47
#ifndef LOG_MIN
 
48
//! Mininum value for logarithmic scales
 
49
#define LOG_MIN 1.0e-100
 
50
#endif
 
51
 
 
52
#ifndef LOG_MAX
 
53
//! Maximum value for logarithmic scales
 
54
#define LOG_MAX 1.0e100
 
55
#endif
 
56
 
 
57
#ifndef M_E
 
58
#define M_E            2.7182818284590452354   /* e */
 
59
#endif
 
60
 
 
61
#ifndef M_LOG2E
 
62
#define M_LOG2E 1.4426950408889634074   /* log_2 e */
 
63
#endif
 
64
 
 
65
#ifndef M_LOG10E
 
66
#define M_LOG10E    0.43429448190325182765  /* log_10 e */
 
67
#endif
 
68
 
 
69
#ifndef M_LN2
 
70
#define M_LN2       0.69314718055994530942  /* log_e 2 */
 
71
#endif
 
72
 
 
73
#ifndef M_LN10
 
74
#define M_LN10         2.30258509299404568402  /* log_e 10 */
 
75
#endif
 
76
 
 
77
#ifndef M_PI
 
78
#define M_PI        3.14159265358979323846  /* pi */
 
79
#endif
 
80
 
 
81
#ifndef M_PI_2
 
82
#define M_PI_2      1.57079632679489661923  /* pi/2 */
 
83
#endif
 
84
 
 
85
#ifndef M_PI_4
 
86
#define M_PI_4      0.78539816339744830962  /* pi/4 */
 
87
#endif
 
88
 
 
89
#ifndef M_1_PI
 
90
#define M_1_PI      0.31830988618379067154  /* 1/pi */
 
91
#endif
 
92
 
 
93
#ifndef M_2_PI
 
94
#define M_2_PI      0.63661977236758134308  /* 2/pi */
 
95
#endif
 
96
 
 
97
#ifndef M_2_SQRTPI
 
98
#define M_2_SQRTPI  1.12837916709551257390  /* 2/sqrt(pi) */
 
99
#endif
 
100
 
 
101
#ifndef M_SQRT2
 
102
#define M_SQRT2 1.41421356237309504880  /* sqrt(2) */
 
103
#endif
 
104
 
 
105
#ifndef M_SQRT1_2
 
106
#define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */
 
107
#endif
 
108
 
 
109
QWT_EXPORT double qwtGetMin(const double *array, int size);
 
110
QWT_EXPORT double qwtGetMax(const double *array, int size);
 
111
 
 
112
 
 
113
//! Return the sign 
 
114
inline int qwtSign(double x)
 
115
{
 
116
    if (x > 0.0)
 
117
       return 1;
 
118
    else if (x < 0.0)
 
119
       return (-1);
 
120
    else
 
121
       return 0;
 
122
}            
 
123
 
 
124
//! Return the square of a number
 
125
inline double qwtSqr(const double x)
 
126
{
 
127
    return x*x;
 
128
}
 
129
 
 
130
/*!
 
131
  \brief Limit a value to fit into a specified interval
 
132
  \param x Input value
 
133
  \param x1 First interval boundary
 
134
  \param x2 Second interval boundary  
 
135
*/
 
136
template <class T>
 
137
T qwtLim(const T& x, const T& x1, const T& x2)
 
138
{
 
139
    T rv;
 
140
    T xmin, xmax;
 
141
    
 
142
    xmin = qwtMin(x1, x2);
 
143
    xmax = qwtMax(x1, x2);
 
144
 
 
145
    if ( x < xmin )
 
146
       rv = xmin;
 
147
    else if ( x > xmax )
 
148
       rv = xmax;
 
149
    else
 
150
       rv = x;
 
151
 
 
152
    return rv;
 
153
}
 
154
 
 
155
inline QPoint qwtPolar2Pos(const QPoint &center,
 
156
    double radius, double angle)
 
157
{
 
158
    const double x = center.x() + radius * cos(angle);
 
159
    const double y = center.y() - radius * sin(angle);
 
160
 
 
161
    return QPoint(qRound(x), qRound(y));
 
162
}
 
163
 
 
164
inline QPoint qwtDegree2Pos(const QPoint &center,
 
165
    double radius, double angle)
 
166
{
 
167
    return qwtPolar2Pos(center, radius, angle / 180.0 * M_PI);
 
168
}
 
169
 
 
170
#endif