1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the painting module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
36
// This file is not part of the Qt API. It exists purely as an
37
// implementation detail. This header file may change from version to
38
// version without notice, or even be removed.
45
/*****************************************************************************
46
Trigonometric function for QPainter
48
We have implemented simple sine and cosine function that are called from
49
QPainter::drawPie() and QPainter::drawChord() when drawing the outline of
51
These functions are slower and less accurate than math.h sin() and cos(),
52
but with still around 1/70000th sec. execution time (on a 486DX2-66) and
53
8 digits accuracy, it should not be the bottleneck in drawing these shapes.
54
The advantage is that you don't have to link in the math library.
55
*****************************************************************************/
57
static const double Q_PI = 3.14159265358979323846; // pi
58
static const double Q_2PI = 6.28318530717958647693; // 2*pi
59
static const double Q_PI2 = 1.57079632679489661923; // pi/2
62
#if defined(Q_CC_GNU) && defined(Q_OS_AIX)
63
// AIX 4.2 gcc 2.7.2.3 gets internal error.
64
inline int qRoundAIX(double d)
68
#define qRound qRoundAIX
72
#if defined(Q_CC_GNU) && defined(__i386__)
74
inline double qCos_x86(double a)
79
: "=t" (r) : "0" (a));
84
inline double qSin_x86(double a)
89
: "=t" (r) : "0" (a));
94
#else //GNU_CC && I386
96
inline double qSinCos(double a, bool calcCos=false)
98
if (calcCos) // calculate cosine
100
if (a >= Q_2PI || a <= -Q_2PI) { // fix range: -2*pi < a < 2*pi
101
int m = (int)(a/Q_2PI);
104
if (a < 0.0) // 0 <= a < 2*pi
106
int sign = a > Q_PI ? -1 : 1;
113
double a2 = a*a; // here: 0 <= a < pi/4
114
double a3 = a2*a; // make taylor sin sum
119
return (a-a3/6+a5/120-a7/5040+a9/362880-a11/39916800)*sign;
121
#define qSin(a) qSinCos(a, false)
122
#define qCos(a) qSinCos(a, true)