~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/painting/qmath_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the painting module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QMATH_P_H
 
30
#define QMATH_P_H
 
31
 
 
32
//
 
33
//  W A R N I N G
 
34
//  -------------
 
35
//
 
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.
 
39
//
 
40
// We mean it.
 
41
//
 
42
 
 
43
#include <math.h>
 
44
 
 
45
/*****************************************************************************
 
46
  Trigonometric function for QPainter
 
47
 
 
48
  We have implemented simple sine and cosine function that are called from
 
49
  QPainter::drawPie() and QPainter::drawChord() when drawing the outline of
 
50
  pies and chords.
 
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
 *****************************************************************************/
 
56
 
 
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
 
60
 
 
61
#ifdef Q_WS_X11
 
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)
 
65
{
 
66
    return qRound(d);
 
67
}
 
68
#define qRound qRoundAIX
 
69
#endif
 
70
 
 
71
 
 
72
#if defined(Q_CC_GNU) && defined(__i386__)
 
73
 
 
74
inline double qCos_x86(double a)
 
75
{
 
76
    double r;
 
77
    __asm__ (
 
78
        "fcos"
 
79
        : "=t" (r) : "0" (a));
 
80
    return r;
 
81
}
 
82
#define qCos qCos_x86
 
83
 
 
84
inline double qSin_x86(double a)
 
85
{
 
86
    double r;
 
87
    __asm__ (
 
88
        "fsin"
 
89
        : "=t" (r) : "0" (a));
 
90
    return r;
 
91
}
 
92
#define qSin qSin_x86
 
93
 
 
94
#else //GNU_CC && I386
 
95
 
 
96
inline double qSinCos(double a, bool calcCos=false)
 
97
{
 
98
    if (calcCos)                              // calculate cosine
 
99
        a -= Q_PI2;
 
100
    if (a >= Q_2PI || a <= -Q_2PI) {          // fix range: -2*pi < a < 2*pi
 
101
        int m = (int)(a/Q_2PI);
 
102
        a -= Q_2PI*m;
 
103
    }
 
104
    if (a < 0.0)                              // 0 <= a < 2*pi
 
105
        a += Q_2PI;
 
106
    int sign = a > Q_PI ? -1 : 1;
 
107
    if (a >= Q_PI)
 
108
        a = Q_2PI - a;
 
109
    if (a >= Q_PI2)
 
110
        a = Q_PI - a;
 
111
    if (calcCos)
 
112
        sign = -sign;
 
113
    double a2  = a*a;                           // here: 0 <= a < pi/4
 
114
    double a3  = a2*a;                          // make taylor sin sum
 
115
    double a5  = a3*a2;
 
116
    double a7  = a5*a2;
 
117
    double a9  = a7*a2;
 
118
    double a11 = a9*a2;
 
119
    return (a-a3/6+a5/120-a7/5040+a9/362880-a11/39916800)*sign;
 
120
}
 
121
#define qSin(a) qSinCos(a, false)
 
122
#define qCos(a) qSinCos(a, true)
 
123
 
 
124
#endif
 
125
#endif //WS_X11
 
126
 
 
127
#ifndef qSin
 
128
# define qSin sin
 
129
#endif
 
130
#ifndef qCos
 
131
# define qCos cos
 
132
#endif
 
133
 
 
134
#endif // QMATH_P_H