Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/painting/qpathclipper.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4545#include <private/qdatabuffer_p.h>
    4646#include <qmath.h>
    47 
    48 #include <QImage>
    49 #include <QPainter>
    5047
    5148/**
     
    6966QT_BEGIN_NAMESPACE
    7067
     68static inline bool fuzzyIsNull(qreal d)
     69{
     70    if (sizeof(qreal) == sizeof(double))
     71        return qAbs(d) <= 1e-12;
     72    else
     73        return qAbs(d) <= 1e-5f;
     74}
     75
     76static inline bool comparePoints(const QPointF &a, const QPointF &b)
     77{
     78    return fuzzyIsNull(a.x() - b.x())
     79           && fuzzyIsNull(a.y() - b.y());
     80}
     81
    7182//#define QDEBUG_CLIPPER
    7283static qreal dot(const QPointF &a, const QPointF &b)
     
    106117bool QIntersectionFinder::beziersIntersect(const QBezier &one, const QBezier &two) const
    107118{
    108     return (one.pt1() == two.pt1() && one.pt2() == two.pt2() && one.pt3() == two.pt3() && one.pt4() == two.pt4())
    109            || (one.pt1() == two.pt4() && one.pt2() == two.pt3() && one.pt3() == two.pt2() && one.pt4() == two.pt1())
     119    return (comparePoints(one.pt1(), two.pt1()) && comparePoints(one.pt2(), two.pt2())
     120            && comparePoints(one.pt3(), two.pt3()) && comparePoints(one.pt4(), two.pt4()))
     121           || (comparePoints(one.pt1(), two.pt4()) && comparePoints(one.pt2(), two.pt3())
     122               && comparePoints(one.pt3(), two.pt2()) && comparePoints(one.pt4(), two.pt1()))
    110123           || QBezier::findIntersections(one, two, 0);
    111124}
     
    119132    const QPointF q2 = b.p2();
    120133
    121     if (p1 == p2 || q1 == q2)
     134    if (comparePoints(p1, p2) || comparePoints(q1, q2))
    122135        return false;
    123136
    124     const bool p1_equals_q1 = (p1 == q1);
    125     const bool p2_equals_q2 = (p2 == q2);
     137    const bool p1_equals_q1 = comparePoints(p1, q1);
     138    const bool p2_equals_q2 = comparePoints(p2, q2);
    126139
    127140    if (p1_equals_q1 && p2_equals_q2)
    128141        return true;
    129142
    130     const bool p1_equals_q2 = (p1 == q2);
    131     const bool p2_equals_q1 = (p2 == q1);
     143    const bool p1_equals_q2 = comparePoints(p1, q2);
     144    const bool p2_equals_q1 = comparePoints(p2, q1);
    132145
    133146    if (p1_equals_q2 && p2_equals_q1)
     
    139152    const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x();
    140153
    141     if (qFuzzyCompare(par + 1, 1)) {
     154    if (qFuzzyIsNull(par)) {
    142155        const QPointF normal(-pDelta.y(), pDelta.x());
    143156
    144157        // coinciding?
    145         if (qFuzzyCompare(dot(normal, q1 - p1) + 1, 1)) {
     158        if (qFuzzyIsNull(dot(normal, q1 - p1))) {
    146159            const qreal dp = dot(pDelta, pDelta);
    147160
     
    185198void QIntersectionFinder::intersectBeziers(const QBezier &one, const QBezier &two, QVector<QPair<qreal, qreal> > &t, QDataBuffer<QIntersection> &intersections)
    186199{
    187     if ((one.pt1() == two.pt1() && one.pt2() == two.pt2() && one.pt3() == two.pt3() && one.pt4() == two.pt4())
    188         || (one.pt1() == two.pt4() && one.pt2() == two.pt3() && one.pt3() == two.pt2() && one.pt4() == two.pt1())) {
     200    if ((comparePoints(one.pt1(), two.pt1()) && comparePoints(one.pt2(), two.pt2())
     201         && comparePoints(one.pt3(), two.pt3()) && comparePoints(one.pt4(), two.pt4()))
     202        || (comparePoints(one.pt1(), two.pt4()) && comparePoints(one.pt2(), two.pt3())
     203            && comparePoints(one.pt3(), two.pt2()) && comparePoints(one.pt4(), two.pt1()))) {
    189204
    190205        return;
     
    203218
    204219        QPointF pt;
    205         if (qFuzzyCompare(alpha_p + 1, 1)) {
     220        if (qFuzzyIsNull(alpha_p)) {
    206221            pt = one.pt1();
    207         } else if (qFuzzyCompare(alpha_p, 1)) {
     222        } else if (qFuzzyIsNull(alpha_p - 1)) {
    208223            pt = one.pt4();
    209         } else if (qFuzzyCompare(alpha_q + 1, 1)) {
     224        } else if (qFuzzyIsNull(alpha_q)) {
    210225            pt = two.pt1();
    211         } else if (qFuzzyCompare(alpha_q, 1)) {
     226        } else if (qFuzzyIsNull(alpha_q - 1)) {
    212227            pt = two.pt4();
    213228        } else {
     
    231246    const QPointF q2 = b.p2();
    232247
    233     if (p1 == p2 || q1 == q2)
     248    if (comparePoints(p1, p2) || comparePoints(q1, q2))
    234249        return;
    235250
    236     const bool p1_equals_q1 = (p1 == q1);
    237     const bool p2_equals_q2 = (p2 == q2);
     251    const bool p1_equals_q1 = comparePoints(p1, q1);
     252    const bool p2_equals_q2 = comparePoints(p2, q2);
    238253
    239254    if (p1_equals_q1 && p2_equals_q2)
    240255        return;
    241256
    242     const bool p1_equals_q2 = (p1 == q2);
    243     const bool p2_equals_q1 = (p2 == q1);
     257    const bool p1_equals_q2 = comparePoints(p1, q2);
     258    const bool p2_equals_q1 = comparePoints(p2, q1);
    244259
    245260    if (p1_equals_q2 && p2_equals_q1)
     
    251266    const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x();
    252267
    253     if (qFuzzyCompare(par + 1, 1)) {
     268    if (qFuzzyIsNull(par)) {
    254269        const QPointF normal(-pDelta.y(), pDelta.x());
    255270
    256271        // coinciding?
    257         if (qFuzzyCompare(dot(normal, q1 - p1) + 1, 1)) {
     272        if (qFuzzyIsNull(dot(normal, q1 - p1))) {
    258273            const qreal invDp = 1 / dot(pDelta, pDelta);
    259274
     
    316331        return;
    317332
    318     const bool p_zero = qFuzzyCompare(tp + 1, 1);
    319     const bool p_one = qFuzzyCompare(tp, 1);
    320 
    321     const bool q_zero = qFuzzyCompare(tq + 1, 1);
    322     const bool q_one = qFuzzyCompare(tq, 1);
     333    const bool p_zero = qFuzzyIsNull(tp);
     334    const bool p_one = qFuzzyIsNull(tp - 1);
     335
     336    const bool q_zero = qFuzzyIsNull(tq);
     337    const bool q_one = qFuzzyIsNull(tq - 1);
    323338
    324339    if ((q_zero || q_one) && (p_zero || p_one))
     
    625640        const qreal value = pointComponents[depth & 1];
    626641
    627         if (qFuzzyCompare(pivot, value)) {
     642        if (fuzzyIsNull(pivot - value)) {
    628643            const qreal pivot2 = pivotComponents[(depth + 1) & 1];
    629644            const qreal value2 = pointComponents[(depth + 1) & 1];
    630645
    631             if (qFuzzyCompare(pivot2, value2)) {
     646            if (fuzzyIsNull(pivot2 - value2)) {
    632647                if (node.id < 0)
    633648                    node.id = m_tree->nextId();
     
    803818static bool isLine(const QBezier &bezier)
    804819{
    805     const bool equal_1_2 = bezier.pt1() == bezier.pt2();
    806     const bool equal_2_3 = bezier.pt2() == bezier.pt3();
    807     const bool equal_3_4 = bezier.pt3() == bezier.pt4();
     820    const bool equal_1_2 = comparePoints(bezier.pt1(), bezier.pt2());
     821    const bool equal_2_3 = comparePoints(bezier.pt2(), bezier.pt3());
     822    const bool equal_3_4 = comparePoints(bezier.pt3(), bezier.pt4());
    808823
    809824    // point?
     
    811826        return true;
    812827
    813     if (bezier.pt1() == bezier.pt4())
     828    if (comparePoints(bezier.pt1(), bezier.pt4()))
    814829        return equal_1_2 || equal_3_4;
    815830
     
    845860            currentPoint = path.elementAt(i);
    846861
    847         if (i > 0 && m_points.at(lastMoveTo) == currentPoint)
     862        if (i > 0 && comparePoints(m_points.at(lastMoveTo), currentPoint))
    848863            current = lastMoveTo;
    849864        else
     
    852867        switch (path.elementAt(i).type) {
    853868        case QPainterPath::MoveToElement:
    854             if (hasMoveTo && last != lastMoveTo && m_points.at(last) != m_points.at(lastMoveTo))
     869            if (hasMoveTo && last != lastMoveTo && !comparePoints(m_points.at(last), m_points.at(lastMoveTo)))
    855870                m_segments << Segment(m_pathId, last, lastMoveTo);
    856871            hasMoveTo = true;
     
    880895    }
    881896
    882     if (hasMoveTo && last != lastMoveTo && m_points.at(last) != m_points.at(lastMoveTo))
     897    if (hasMoveTo && last != lastMoveTo && !comparePoints(m_points.at(last), m_points.at(lastMoveTo)))
    883898        m_segments << Segment(m_pathId, last, lastMoveTo);
    884899
     
    923938    qreal result = b_angle - a_angle;
    924939
    925     if (qFuzzyCompare(result + 1, 1) || qFuzzyCompare(result, 128))
     940    if (qFuzzyIsNull(result) || qFuzzyCompare(result, 128))
    926941        return 0;
    927942
     
    952967        normal = ep->bezier->derivedAt(t);
    953968
    954         if (qFuzzyCompare(normal.x() + 1, 1) && qFuzzyCompare(normal.y() + 1, 1))
     969        if (qFuzzyIsNull(normal.x()) && qFuzzyIsNull(normal.y()))
    955970            normal = ep->bezier->secondDerivedAt(t);
    956971    } else {
     
    10811096#endif
    10821097
    1083         if (!(qFuzzyCompare(d2 + 1, 1) && isLeftOf(*this, vi, status.edge, ei))
     1098        if (!(qFuzzyIsNull(d2) && isLeftOf(*this, vi, status.edge, ei))
    10841099            && (d2 < d || (qFuzzyCompare(d2, d) && isLeftOf(*this, vi, status.edge, position)))) {
    10851100            position = status.edge;
     
    11951210#else
    11961211    // doesn't seem to be robust enough
    1197     return atan2(v.x(), v.y()) + Q_PI;
     1212    return qAtan2(v.x(), v.y()) + Q_PI;
    11981213#endif
    11991214}
     
    12331248        QPointF bTangent = -bezier->derivedAt(t1);
    12341249
    1235         if (qFuzzyCompare(aTangent.x() + 1, 1) && qFuzzyCompare(aTangent.y() + 1, 1))
     1250        if (qFuzzyIsNull(aTangent.x()) && qFuzzyIsNull(aTangent.y()))
    12361251            aTangent = bezier->secondDerivedAt(t0);
    12371252
    1238         if (qFuzzyCompare(bTangent.x() + 1, 1) && qFuzzyCompare(bTangent.y() + 1, 1))
     1253        if (qFuzzyIsNull(bTangent.x()) && qFuzzyIsNull(bTangent.y()))
    12391254            bTangent = bezier->secondDerivedAt(t1);
    12401255
     
    13581373        return;
    13591374
    1360     if (a == b) {
     1375    if (comparePoints(a, b)) {
    13611376        int v = insert(a);
    13621377
     
    14011416            const QPointF p(-d1.y(), d1.x());
    14021417
    1403             if (qFuzzyCompare(dot(p, d2) + 1, 1)) {
     1418            if (qFuzzyIsNull(dot(p, d2))) {
    14041419                path.setElementPositionAt(elementCount - 1, point.x(), point.y());
    14051420                return;
     
    16361651InputIterator qFuzzyFind(InputIterator first, InputIterator last, qreal val)
    16371652{
    1638     while (first != last && !qFuzzyCompare(qreal(*first), qreal(val)))
     1653    while (first != last && !QT_PREPEND_NAMESPACE(qFuzzyCompare)(qreal(*first), qreal(val)))
    16391654        ++first;
    16401655    return first;
Note: See TracChangeset for help on using the changeset viewer.