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

« back to all changes in this revision

Viewing changes to src/gui/painting/qbezier.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the QtGui module of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22
23
**
23
 
** In addition, as a special exception, Nokia gives you certain
24
 
** additional rights. These rights are described in the Nokia Qt LGPL
25
 
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26
 
** package.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
127
127
        qreal dy = bez.y2 - bez.y1;
128
128
 
129
129
        qreal normalized = qSqrt(dx * dx + dy * dy);
130
 
        if (qFuzzyCompare(normalized + 1, 1))
 
130
        if (qFuzzyIsNull(normalized))
131
131
           break;
132
132
 
133
133
        qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2));
134
134
 
135
135
        qreal t = qSqrt(4. / 3. * normalized * flatness / d);
136
 
        if (t > 1 || qFuzzyCompare(t, (qreal)1.))
 
136
        if (t > 1 || qFuzzyIsNull(t - (qreal)1.))
137
137
            break;
138
138
        bez.parameterSplitLeft(t, &left);
139
139
        p->append(bez.pt1());
144
144
static inline int quadraticRoots(qreal a, qreal b, qreal c,
145
145
                                 qreal *x1, qreal *x2)
146
146
{
147
 
    if (qFuzzyCompare(a + 1, 1)) {
148
 
        if (qFuzzyCompare(b + 1, 1))
 
147
    if (qFuzzyIsNull(a)) {
 
148
        if (qFuzzyIsNull(b))
149
149
            return 0;
150
150
        *x1 = *x2 = (-c / b);
151
151
        return 1;
152
152
    } else {
153
153
        const qreal det = b * b - 4 * a * c;
154
 
        if (qFuzzyCompare(det + 1, 1)) {
 
154
        if (qFuzzyIsNull(det)) {
155
155
            *x1 = *x2 = -b / (2 * a);
156
156
            return 1;
157
157
        }
158
158
        if (det > 0) {
159
 
            if (qFuzzyCompare(b + 1, 1)) {
 
159
            if (qFuzzyIsNull(b)) {
160
160
                *x2 = qSqrt(-c / a);
161
161
                *x1 = -(*x2);
162
162
                return 2;
187
187
            *t1 = r2;
188
188
            *t2 = r1;
189
189
        }
190
 
        if (!qFuzzyCompare(a + 1, 1))
 
190
        if (!qFuzzyIsNull(a))
191
191
            *tCups = 0.5 * (-b / a);
192
192
        else
193
193
            *tCups = 2;
243
243
    qreal b = 6 * (ay * cx - ax * cy);
244
244
    qreal c = 2 * (by * cx - bx * cy);
245
245
 
246
 
    if ((qFuzzyCompare(a + 1, 1) && qFuzzyCompare(b + 1, 1)) ||
 
246
    if ((qFuzzyIsNull(a) && qFuzzyIsNull(b)) ||
247
247
        (b * b - 4 * a *c) < 0) {
248
248
        QBezier bez(*this);
249
249
        flattenBezierWithoutInflections(bez, polygon);
447
447
        qreal r = 1.0 + prev_normal.x() * next_normal.x()
448
448
                  + prev_normal.y() * next_normal.y();
449
449
 
450
 
        if (qFuzzyCompare(r + 1, 1)) {
 
450
        if (qFuzzyIsNull(r)) {
451
451
            points_shifted[i] = points[i] + offset * prev_normal;
452
452
        } else {
453
453
            qreal k = offset / r;
477
477
 
478
478
    normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2);
479
479
    qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());
480
 
    if (qFuzzyCompare(dist + 1, 1))
 
480
    if (qFuzzyIsNull(dist))
481
481
        return false;
482
482
    normals[0] /= dist;
483
483
    normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4);
484
484
    dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());
485
 
    if (qFuzzyCompare(dist + 1, 1))
 
485
    if (qFuzzyIsNull(dist))
486
486
        return false;
487
487
    normals[2] /= dist;
488
488
 
673
673
#ifdef QDEBUG_BEZIER
674
674
static QDebug operator<<(QDebug dbg, const QBezier &bz)
675
675
{
676
 
    dbg <<"["<<bz.x1<<", "<<bz.y1<<"], "
677
 
        <<"["<<bz.x2<<", "<<bz.y2<<"], "
678
 
        <<"["<<bz.x3<<", "<<bz.y3<<"], "
679
 
        <<"["<<bz.x4<<", "<<bz.y4<<"]";
 
676
    dbg << '[' << bz.x1<< ", " << bz.y1 << "], "
 
677
        << '[' << bz.x2 <<", " << bz.y2 << "], "
 
678
        << '[' << bz.x3 <<", " << bz.y3 << "], "
 
679
        << '[' << bz.x4 <<", " << bz.y4 << ']';
680
680
    return dbg;
681
681
}
682
682
#endif
1022
1022
 
1023
1023
    QList<qreal> result;
1024
1024
 
1025
 
    if (qFuzzyCompare(reciprocal + 1, 1)) {
 
1025
    if (qFuzzyIsNull(reciprocal)) {
1026
1026
        t0 = -b / (2 * a);
1027
1027
        return 1;
1028
1028
    } else if (reciprocal > 0) {