Changeset 561 for trunk/src/gui/painting/qpathclipper.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/painting/qpathclipper.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 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. 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 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 45 45 #include <private/qdatabuffer_p.h> 46 46 #include <qmath.h> 47 48 #include <QImage>49 #include <QPainter>50 47 51 48 /** … … 69 66 QT_BEGIN_NAMESPACE 70 67 68 static 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 76 static 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 71 82 //#define QDEBUG_CLIPPER 72 83 static qreal dot(const QPointF &a, const QPointF &b) … … 106 117 bool QIntersectionFinder::beziersIntersect(const QBezier &one, const QBezier &two) const 107 118 { 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())) 110 123 || QBezier::findIntersections(one, two, 0); 111 124 } … … 119 132 const QPointF q2 = b.p2(); 120 133 121 if ( p1 == p2 || q1 == q2)134 if (comparePoints(p1, p2) || comparePoints(q1, q2)) 122 135 return false; 123 136 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); 126 139 127 140 if (p1_equals_q1 && p2_equals_q2) 128 141 return true; 129 142 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); 132 145 133 146 if (p1_equals_q2 && p2_equals_q1) … … 139 152 const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); 140 153 141 if (qFuzzy Compare(par + 1, 1)) {154 if (qFuzzyIsNull(par)) { 142 155 const QPointF normal(-pDelta.y(), pDelta.x()); 143 156 144 157 // coinciding? 145 if (qFuzzy Compare(dot(normal, q1 - p1) + 1, 1)) {158 if (qFuzzyIsNull(dot(normal, q1 - p1))) { 146 159 const qreal dp = dot(pDelta, pDelta); 147 160 … … 185 198 void QIntersectionFinder::intersectBeziers(const QBezier &one, const QBezier &two, QVector<QPair<qreal, qreal> > &t, QDataBuffer<QIntersection> &intersections) 186 199 { 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()))) { 189 204 190 205 return; … … 203 218 204 219 QPointF pt; 205 if (qFuzzy Compare(alpha_p + 1, 1)) {220 if (qFuzzyIsNull(alpha_p)) { 206 221 pt = one.pt1(); 207 } else if (qFuzzy Compare(alpha_p,1)) {222 } else if (qFuzzyIsNull(alpha_p - 1)) { 208 223 pt = one.pt4(); 209 } else if (qFuzzy Compare(alpha_q + 1, 1)) {224 } else if (qFuzzyIsNull(alpha_q)) { 210 225 pt = two.pt1(); 211 } else if (qFuzzy Compare(alpha_q,1)) {226 } else if (qFuzzyIsNull(alpha_q - 1)) { 212 227 pt = two.pt4(); 213 228 } else { … … 231 246 const QPointF q2 = b.p2(); 232 247 233 if ( p1 == p2 || q1 == q2)248 if (comparePoints(p1, p2) || comparePoints(q1, q2)) 234 249 return; 235 250 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); 238 253 239 254 if (p1_equals_q1 && p2_equals_q2) 240 255 return; 241 256 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); 244 259 245 260 if (p1_equals_q2 && p2_equals_q1) … … 251 266 const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); 252 267 253 if (qFuzzy Compare(par + 1, 1)) {268 if (qFuzzyIsNull(par)) { 254 269 const QPointF normal(-pDelta.y(), pDelta.x()); 255 270 256 271 // coinciding? 257 if (qFuzzy Compare(dot(normal, q1 - p1) + 1, 1)) {272 if (qFuzzyIsNull(dot(normal, q1 - p1))) { 258 273 const qreal invDp = 1 / dot(pDelta, pDelta); 259 274 … … 316 331 return; 317 332 318 const bool p_zero = qFuzzy Compare(tp + 1, 1);319 const bool p_one = qFuzzy Compare(tp,1);320 321 const bool q_zero = qFuzzy Compare(tq + 1, 1);322 const bool q_one = qFuzzy Compare(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); 323 338 324 339 if ((q_zero || q_one) && (p_zero || p_one)) … … 625 640 const qreal value = pointComponents[depth & 1]; 626 641 627 if ( qFuzzyCompare(pivot,value)) {642 if (fuzzyIsNull(pivot - value)) { 628 643 const qreal pivot2 = pivotComponents[(depth + 1) & 1]; 629 644 const qreal value2 = pointComponents[(depth + 1) & 1]; 630 645 631 if ( qFuzzyCompare(pivot2,value2)) {646 if (fuzzyIsNull(pivot2 - value2)) { 632 647 if (node.id < 0) 633 648 node.id = m_tree->nextId(); … … 803 818 static bool isLine(const QBezier &bezier) 804 819 { 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()); 808 823 809 824 // point? … … 811 826 return true; 812 827 813 if ( bezier.pt1() == bezier.pt4())828 if (comparePoints(bezier.pt1(), bezier.pt4())) 814 829 return equal_1_2 || equal_3_4; 815 830 … … 845 860 currentPoint = path.elementAt(i); 846 861 847 if (i > 0 && m_points.at(lastMoveTo) == currentPoint)862 if (i > 0 && comparePoints(m_points.at(lastMoveTo), currentPoint)) 848 863 current = lastMoveTo; 849 864 else … … 852 867 switch (path.elementAt(i).type) { 853 868 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))) 855 870 m_segments << Segment(m_pathId, last, lastMoveTo); 856 871 hasMoveTo = true; … … 880 895 } 881 896 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))) 883 898 m_segments << Segment(m_pathId, last, lastMoveTo); 884 899 … … 923 938 qreal result = b_angle - a_angle; 924 939 925 if (qFuzzy Compare(result + 1, 1) || qFuzzyCompare(result, 128))940 if (qFuzzyIsNull(result) || qFuzzyCompare(result, 128)) 926 941 return 0; 927 942 … … 952 967 normal = ep->bezier->derivedAt(t); 953 968 954 if (qFuzzy Compare(normal.x() + 1, 1) && qFuzzyCompare(normal.y() + 1, 1))969 if (qFuzzyIsNull(normal.x()) && qFuzzyIsNull(normal.y())) 955 970 normal = ep->bezier->secondDerivedAt(t); 956 971 } else { … … 1081 1096 #endif 1082 1097 1083 if (!(qFuzzy Compare(d2 + 1, 1) && isLeftOf(*this, vi, status.edge, ei))1098 if (!(qFuzzyIsNull(d2) && isLeftOf(*this, vi, status.edge, ei)) 1084 1099 && (d2 < d || (qFuzzyCompare(d2, d) && isLeftOf(*this, vi, status.edge, position)))) { 1085 1100 position = status.edge; … … 1195 1210 #else 1196 1211 // 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; 1198 1213 #endif 1199 1214 } … … 1233 1248 QPointF bTangent = -bezier->derivedAt(t1); 1234 1249 1235 if (qFuzzy Compare(aTangent.x() + 1, 1) && qFuzzyCompare(aTangent.y() + 1, 1))1250 if (qFuzzyIsNull(aTangent.x()) && qFuzzyIsNull(aTangent.y())) 1236 1251 aTangent = bezier->secondDerivedAt(t0); 1237 1252 1238 if (qFuzzy Compare(bTangent.x() + 1, 1) && qFuzzyCompare(bTangent.y() + 1, 1))1253 if (qFuzzyIsNull(bTangent.x()) && qFuzzyIsNull(bTangent.y())) 1239 1254 bTangent = bezier->secondDerivedAt(t1); 1240 1255 … … 1358 1373 return; 1359 1374 1360 if ( a == b) {1375 if (comparePoints(a, b)) { 1361 1376 int v = insert(a); 1362 1377 … … 1401 1416 const QPointF p(-d1.y(), d1.x()); 1402 1417 1403 if (qFuzzy Compare(dot(p, d2) + 1, 1)) {1418 if (qFuzzyIsNull(dot(p, d2))) { 1404 1419 path.setElementPositionAt(elementCount - 1, point.x(), point.y()); 1405 1420 return; … … 1636 1651 InputIterator qFuzzyFind(InputIterator first, InputIterator last, qreal val) 1637 1652 { 1638 while (first != last && ! qFuzzyCompare(qreal(*first), qreal(val)))1653 while (first != last && !QT_PREPEND_NAMESPACE(qFuzzyCompare)(qreal(*first), qreal(val))) 1639 1654 ++first; 1640 1655 return first;
Note:
See TracChangeset
for help on using the changeset viewer.