| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | static inline bool fuzzyIsNull(qreal d) | - |
| 6 | { | - |
| 7 | if (sizeof(qreal) == sizeof(double)) partially evaluated: sizeof(qreal) == sizeof(double)| yes Evaluation Count:21050 | no Evaluation Count:0 |
| 0-21050 |
| 8 | return qAbs(d) <= 1e-12; executed: return qAbs(d) <= 1e-12;Execution Count:21050 | 21050 |
| 9 | else | - |
| 10 | return qAbs(d) <= 1e-5f; never executed: return qAbs(d) <= 1e-5f; | 0 |
| 11 | } | - |
| 12 | | - |
| 13 | static inline bool comparePoints(const QPointF &a, const QPointF &b) | - |
| 14 | { | - |
| 15 | return fuzzyIsNull(a.x() - b.x()) | 11537 |
| 16 | && fuzzyIsNull(a.y() - b.y()); executed: return fuzzyIsNull(a.x() - b.x()) && fuzzyIsNull(a.y() - b.y());Execution Count:11537 | 11537 |
| 17 | } | - |
| 18 | | - |
| 19 | | - |
| 20 | static qreal dot(const QPointF &a, const QPointF &b) | - |
| 21 | { | - |
| 22 | return a.x() * b.x() + a.y() * b.y(); executed: return a.x() * b.x() + a.y() * b.y();Execution Count:1291 | 1291 |
| 23 | } | - |
| 24 | | - |
| 25 | static void normalize(double &x, double &y) | - |
| 26 | { | - |
| 27 | double reciprocal = 1 / qSqrt(x * x + y * y); | - |
| 28 | x *= reciprocal; | - |
| 29 | y *= reciprocal; | - |
| 30 | } | 0 |
| 31 | | - |
| 32 | struct QIntersection | - |
| 33 | { | - |
| 34 | qreal alphaA; | - |
| 35 | qreal alphaB; | - |
| 36 | | - |
| 37 | QPointF pos; | - |
| 38 | }; | - |
| 39 | | - |
| 40 | class QIntersectionFinder | - |
| 41 | { | - |
| 42 | public: | - |
| 43 | void produceIntersections(QPathSegments &segments); | - |
| 44 | bool hasIntersections(const QPathSegments &a, const QPathSegments &b) const; | - |
| 45 | | - |
| 46 | private: | - |
| 47 | bool linesIntersect(const QLineF &a, const QLineF &b) const; | - |
| 48 | }; | - |
| 49 | | - |
| 50 | bool QIntersectionFinder::linesIntersect(const QLineF &a, const QLineF &b) const | - |
| 51 | { | - |
| 52 | const QPointF p1 = a.p1(); | - |
| 53 | const QPointF p2 = a.p2(); | - |
| 54 | | - |
| 55 | const QPointF q1 = b.p1(); | - |
| 56 | const QPointF q2 = b.p2(); | - |
| 57 | | - |
| 58 | if (comparePoints(p1, p2) || comparePoints(q1, q2)) partially evaluated: comparePoints(p1, p2)| no Evaluation Count:0 | yes Evaluation Count:104 |
partially evaluated: comparePoints(q1, q2)| no Evaluation Count:0 | yes Evaluation Count:104 |
| 0-104 |
| 59 | return false; never executed: return false; | 0 |
| 60 | | - |
| 61 | const bool p1_equals_q1 = comparePoints(p1, q1); | - |
| 62 | const bool p2_equals_q2 = comparePoints(p2, q2); | - |
| 63 | | - |
| 64 | if (p1_equals_q1 && p2_equals_q2) evaluated: p1_equals_q1| yes Evaluation Count:4 | yes Evaluation Count:100 |
partially evaluated: p2_equals_q2| yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-100 |
| 65 | return true; executed: return true;Execution Count:4 | 4 |
| 66 | | - |
| 67 | const bool p1_equals_q2 = comparePoints(p1, q2); | - |
| 68 | const bool p2_equals_q1 = comparePoints(p2, q1); | - |
| 69 | | - |
| 70 | if (p1_equals_q2 && p2_equals_q1) partially evaluated: p1_equals_q2| no Evaluation Count:0 | yes Evaluation Count:100 |
never evaluated: p2_equals_q1 | 0-100 |
| 71 | return true; never executed: return true; | 0 |
| 72 | | - |
| 73 | const QPointF pDelta = p2 - p1; | - |
| 74 | const QPointF qDelta = q2 - q1; | - |
| 75 | | - |
| 76 | const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); | - |
| 77 | | - |
| 78 | if (qFuzzyIsNull(par)) { partially evaluated: qFuzzyIsNull(par)| no Evaluation Count:0 | yes Evaluation Count:100 |
| 0-100 |
| 79 | const QPointF normal(-pDelta.y(), pDelta.x()); | - |
| 80 | | - |
| 81 | | - |
| 82 | if (qFuzzyIsNull(dot(normal, q1 - p1))) { never evaluated: qFuzzyIsNull(dot(normal, q1 - p1)) | 0 |
| 83 | const qreal dp = dot(pDelta, pDelta); | - |
| 84 | | - |
| 85 | const qreal tq1 = dot(pDelta, q1 - p1); | - |
| 86 | const qreal tq2 = dot(pDelta, q2 - p1); | - |
| 87 | | - |
| 88 | if ((tq1 > 0 && tq1 < dp) || (tq2 > 0 && tq2 < dp)) never evaluated: tq1 < dp never evaluated: tq2 < dp | 0 |
| 89 | return true; never executed: return true; | 0 |
| 90 | | - |
| 91 | const qreal dq = dot(qDelta, qDelta); | - |
| 92 | | - |
| 93 | const qreal tp1 = dot(qDelta, p1 - q1); | - |
| 94 | const qreal tp2 = dot(qDelta, p2 - q1); | - |
| 95 | | - |
| 96 | if ((tp1 > 0 && tp1 < dq) || (tp2 > 0 && tp2 < dq)) never evaluated: tp1 < dq never evaluated: tp2 < dq | 0 |
| 97 | return true; never executed: return true; | 0 |
| 98 | } | 0 |
| 99 | | - |
| 100 | return false; never executed: return false; | 0 |
| 101 | } | - |
| 102 | | - |
| 103 | const qreal invPar = 1 / par; | - |
| 104 | | - |
| 105 | const qreal tp = (qDelta.y() * (q1.x() - p1.x()) - | - |
| 106 | qDelta.x() * (q1.y() - p1.y())) * invPar; | - |
| 107 | | - |
| 108 | if (tp < 0 || tp > 1) evaluated: tp < 0| yes Evaluation Count:15 | yes Evaluation Count:85 |
evaluated: tp > 1| yes Evaluation Count:11 | yes Evaluation Count:74 |
| 11-85 |
| 109 | return false; executed: return false;Execution Count:26 | 26 |
| 110 | | - |
| 111 | const qreal tq = (pDelta.y() * (q1.x() - p1.x()) - | - |
| 112 | pDelta.x() * (q1.y() - p1.y())) * invPar; | - |
| 113 | | - |
| 114 | return tq >= 0 && tq <= 1; executed: return tq >= 0 && tq <= 1;Execution Count:74 | 74 |
| 115 | } | - |
| 116 | | - |
| 117 | bool QIntersectionFinder::hasIntersections(const QPathSegments &a, const QPathSegments &b) const | - |
| 118 | { | - |
| 119 | if (a.segments() == 0 || b.segments() == 0) partially evaluated: a.segments() == 0| no Evaluation Count:0 | yes Evaluation Count:121 |
partially evaluated: b.segments() == 0| no Evaluation Count:0 | yes Evaluation Count:121 |
| 0-121 |
| 120 | return false; never executed: return false; | 0 |
| 121 | | - |
| 122 | const QRectF &rb0 = b.elementBounds(0); | - |
| 123 | | - |
| 124 | qreal minX = rb0.left(); | - |
| 125 | qreal minY = rb0.top(); | - |
| 126 | qreal maxX = rb0.right(); | - |
| 127 | qreal maxY = rb0.bottom(); | - |
| 128 | | - |
| 129 | for (int i = 1; i < b.segments(); ++i) { evaluated: i < b.segments()| yes Evaluation Count:17667 | yes Evaluation Count:121 |
| 121-17667 |
| 130 | const QRectF &r = b.elementBounds(i); | - |
| 131 | minX = qMin(minX, r.left()); | - |
| 132 | minY = qMin(minY, r.top()); | - |
| 133 | maxX = qMax(maxX, r.right()); | - |
| 134 | maxY = qMax(maxY, r.bottom()); | - |
| 135 | } executed: }Execution Count:17667 | 17667 |
| 136 | | - |
| 137 | QRectF rb(minX, minY, maxX - minX, maxY - minY); | - |
| 138 | | - |
| 139 | for (int i = 0; i < a.segments(); ++i) { evaluated: i < a.segments()| yes Evaluation Count:604 | yes Evaluation Count:43 |
| 43-604 |
| 140 | const QRectF &r1 = a.elementBounds(i); | - |
| 141 | | - |
| 142 | if (r1.left() > rb.right() || rb.left() > r1.right()) evaluated: r1.left() > rb.right()| yes Evaluation Count:192 | yes Evaluation Count:412 |
evaluated: rb.left() > r1.right()| yes Evaluation Count:96 | yes Evaluation Count:316 |
| 96-412 |
| 143 | continue; executed: continue;Execution Count:288 | 288 |
| 144 | if (r1.top() > rb.bottom() || rb.top() > r1.bottom()) evaluated: r1.top() > rb.bottom()| yes Evaluation Count:59 | yes Evaluation Count:257 |
evaluated: rb.top() > r1.bottom()| yes Evaluation Count:70 | yes Evaluation Count:187 |
| 59-257 |
| 145 | continue; executed: continue;Execution Count:129 | 129 |
| 146 | | - |
| 147 | for (int j = 0; j < b.segments(); ++j) { evaluated: j < b.segments()| yes Evaluation Count:50257 | yes Evaluation Count:109 |
| 109-50257 |
| 148 | const QRectF &r2 = b.elementBounds(j); | - |
| 149 | | - |
| 150 | if (r1.left() > r2.right() || r2.left() > r1.right()) evaluated: r1.left() > r2.right()| yes Evaluation Count:24436 | yes Evaluation Count:25821 |
evaluated: r2.left() > r1.right()| yes Evaluation Count:23185 | yes Evaluation Count:2636 |
| 2636-25821 |
| 151 | continue; executed: continue;Execution Count:47621 | 47621 |
| 152 | if (r1.top() > r2.bottom() || r2.top() > r1.bottom()) evaluated: r1.top() > r2.bottom()| yes Evaluation Count:477 | yes Evaluation Count:2159 |
evaluated: r2.top() > r1.bottom()| yes Evaluation Count:2055 | yes Evaluation Count:104 |
| 104-2159 |
| 153 | continue; executed: continue;Execution Count:2532 | 2532 |
| 154 | | - |
| 155 | if (linesIntersect(a.lineAt(i), b.lineAt(j))) evaluated: linesIntersect(a.lineAt(i), b.lineAt(j))| yes Evaluation Count:78 | yes Evaluation Count:26 |
| 26-78 |
| 156 | return true; executed: return true;Execution Count:78 | 78 |
| 157 | } executed: }Execution Count:26 | 26 |
| 158 | } executed: }Execution Count:109 | 109 |
| 159 | | - |
| 160 | return false; executed: return false;Execution Count:43 | 43 |
| 161 | } | - |
| 162 | | - |
| 163 | namespace { | - |
| 164 | struct TreeNode | - |
| 165 | { | - |
| 166 | qreal splitLeft; | - |
| 167 | qreal splitRight; | - |
| 168 | bool leaf; | - |
| 169 | | - |
| 170 | int lowestLeftIndex; | - |
| 171 | int lowestRightIndex; | - |
| 172 | | - |
| 173 | union { | - |
| 174 | struct { | - |
| 175 | int first; | - |
| 176 | int last; | - |
| 177 | } interval; | - |
| 178 | struct { | - |
| 179 | int left; | - |
| 180 | int right; | - |
| 181 | } children; | - |
| 182 | } index; | - |
| 183 | }; | - |
| 184 | | - |
| 185 | struct RectF | - |
| 186 | { | - |
| 187 | qreal x1; | - |
| 188 | qreal y1; | - |
| 189 | qreal x2; | - |
| 190 | qreal y2; | - |
| 191 | }; | - |
| 192 | | - |
| 193 | class SegmentTree | - |
| 194 | { | - |
| 195 | public: | - |
| 196 | SegmentTree(QPathSegments &segments); | - |
| 197 | | - |
| 198 | QRectF boundingRect() const; | - |
| 199 | | - |
| 200 | void produceIntersections(int segment); | - |
| 201 | | - |
| 202 | private: | - |
| 203 | TreeNode buildTree(int first, int last, int depth, const RectF &bounds); | - |
| 204 | | - |
| 205 | void produceIntersectionsLeaf(const TreeNode &node, int segment); | - |
| 206 | void produceIntersections(const TreeNode &node, int segment, const RectF &segmentBounds, const RectF &nodeBounds, int axis); | - |
| 207 | void intersectLines(const QLineF &a, const QLineF &b, QDataBuffer<QIntersection> &intersections); | - |
| 208 | | - |
| 209 | QPathSegments &m_segments; | - |
| 210 | QVector<int> m_index; | - |
| 211 | | - |
| 212 | RectF m_bounds; | - |
| 213 | | - |
| 214 | QVector<TreeNode> m_tree; | - |
| 215 | QDataBuffer<QIntersection> m_intersections; | - |
| 216 | }; | - |
| 217 | | - |
| 218 | SegmentTree::SegmentTree(QPathSegments &segments) | - |
| 219 | : m_segments(segments), | - |
| 220 | m_intersections(0) | - |
| 221 | { | - |
| 222 | m_bounds.x1 = qt_inf(); | - |
| 223 | m_bounds.y1 = qt_inf(); | - |
| 224 | m_bounds.x2 = -qt_inf(); | - |
| 225 | m_bounds.y2 = -qt_inf(); | - |
| 226 | | - |
| 227 | m_index.resize(m_segments.segments()); | - |
| 228 | | - |
| 229 | for (int i = 0; i < m_index.size(); ++i) { evaluated: i < m_index.size()| yes Evaluation Count:488 | yes Evaluation Count:70 |
| 70-488 |
| 230 | m_index[i] = i; | - |
| 231 | | - |
| 232 | const QRectF &segmentBounds = m_segments.elementBounds(i); | - |
| 233 | | - |
| 234 | if (segmentBounds.left() < m_bounds.x1) evaluated: segmentBounds.left() < m_bounds.x1| yes Evaluation Count:73 | yes Evaluation Count:415 |
| 73-415 |
| 235 | m_bounds.x1 = segmentBounds.left(); executed: m_bounds.x1 = segmentBounds.left();Execution Count:73 | 73 |
| 236 | if (segmentBounds.top() < m_bounds.y1) evaluated: segmentBounds.top() < m_bounds.y1| yes Evaluation Count:71 | yes Evaluation Count:417 |
| 71-417 |
| 237 | m_bounds.y1 = segmentBounds.top(); executed: m_bounds.y1 = segmentBounds.top();Execution Count:71 | 71 |
| 238 | if (segmentBounds.right() > m_bounds.x2) evaluated: segmentBounds.right() > m_bounds.x2| yes Evaluation Count:93 | yes Evaluation Count:395 |
| 93-395 |
| 239 | m_bounds.x2 = segmentBounds.right(); executed: m_bounds.x2 = segmentBounds.right();Execution Count:93 | 93 |
| 240 | if (segmentBounds.bottom() > m_bounds.y2) evaluated: segmentBounds.bottom() > m_bounds.y2| yes Evaluation Count:155 | yes Evaluation Count:333 |
| 155-333 |
| 241 | m_bounds.y2 = segmentBounds.bottom(); executed: m_bounds.y2 = segmentBounds.bottom();Execution Count:155 | 155 |
| 242 | } executed: }Execution Count:488 | 488 |
| 243 | | - |
| 244 | m_tree.resize(1); | - |
| 245 | | - |
| 246 | TreeNode root = buildTree(0, m_index.size(), 0, m_bounds); | - |
| 247 | m_tree[0] = root; | - |
| 248 | } executed: }Execution Count:70 | 70 |
| 249 | | - |
| 250 | QRectF SegmentTree::boundingRect() const | - |
| 251 | { | - |
| 252 | return QRectF(QPointF(m_bounds.x1, m_bounds.y1), | 0 |
| 253 | QPointF(m_bounds.x2, m_bounds.y2)); never executed: return QRectF(QPointF(m_bounds.x1, m_bounds.y1), QPointF(m_bounds.x2, m_bounds.y2)); | 0 |
| 254 | } | - |
| 255 | | - |
| 256 | static inline qreal coordinate(const QPointF &pos, int axis) | - |
| 257 | { | - |
| 258 | return axis == 0 ? pos.x() : pos.y(); executed: return axis == 0 ? pos.x() : pos.y();Execution Count:1921 | 1921 |
| 259 | } | - |
| 260 | | - |
| 261 | TreeNode SegmentTree::buildTree(int first, int last, int depth, const RectF &bounds) | - |
| 262 | { | - |
| 263 | if (depth >= 24 || (last - first) <= 10) { evaluated: depth >= 24| yes Evaluation Count:4 | yes Evaluation Count:196 |
evaluated: (last - first) <= 10| yes Evaluation Count:131 | yes Evaluation Count:65 |
| 4-196 |
| 264 | TreeNode node; | - |
| 265 | node.leaf = true; | - |
| 266 | node.index.interval.first = first; | - |
| 267 | node.index.interval.last = last; | - |
| 268 | | - |
| 269 | return node; executed: return node;Execution Count:135 | 135 |
| 270 | } | - |
| 271 | | - |
| 272 | int splitAxis = (depth & 1); | - |
| 273 | | - |
| 274 | TreeNode node; | - |
| 275 | node.leaf = false; | - |
| 276 | | - |
| 277 | qreal split = 0.5f * ((&bounds.x1)[splitAxis] + (&bounds.x2)[splitAxis]); | - |
| 278 | | - |
| 279 | node.splitLeft = (&bounds.x1)[splitAxis]; | - |
| 280 | node.splitRight = (&bounds.x2)[splitAxis]; | - |
| 281 | | - |
| 282 | node.lowestLeftIndex = 2147483647; | - |
| 283 | node.lowestRightIndex = 2147483647; | - |
| 284 | | - |
| 285 | const int treeSize = m_tree.size(); | - |
| 286 | | - |
| 287 | node.index.children.left = treeSize; | - |
| 288 | node.index.children.right = treeSize + 1; | - |
| 289 | | - |
| 290 | m_tree.resize(treeSize + 2); | - |
| 291 | | - |
| 292 | int l = first; | - |
| 293 | int r = last - 1; | - |
| 294 | | - |
| 295 | | - |
| 296 | while (l <= r) { evaluated: l <= r| yes Evaluation Count:882 | yes Evaluation Count:65 |
| 65-882 |
| 297 | const int index = m_index.at(l); | - |
| 298 | const QRectF &segmentBounds = m_segments.elementBounds(index); | - |
| 299 | | - |
| 300 | qreal lowCoordinate = coordinate(segmentBounds.topLeft(), splitAxis); | - |
| 301 | | - |
| 302 | if (coordinate(segmentBounds.center(), splitAxis) < split) { evaluated: coordinate(segmentBounds.center(), splitAxis) < split| yes Evaluation Count:157 | yes Evaluation Count:725 |
| 157-725 |
| 303 | qreal highCoordinate = coordinate(segmentBounds.bottomRight(), splitAxis); | - |
| 304 | if (highCoordinate > node.splitLeft) evaluated: highCoordinate > node.splitLeft| yes Evaluation Count:26 | yes Evaluation Count:131 |
| 26-131 |
| 305 | node.splitLeft = highCoordinate; executed: node.splitLeft = highCoordinate;Execution Count:26 | 26 |
| 306 | if (index < node.lowestLeftIndex) evaluated: index < node.lowestLeftIndex| yes Evaluation Count:40 | yes Evaluation Count:117 |
| 40-117 |
| 307 | node.lowestLeftIndex = index; executed: node.lowestLeftIndex = index;Execution Count:40 | 40 |
| 308 | ++l; | - |
| 309 | } else { executed: }Execution Count:157 | 157 |
| 310 | if (lowCoordinate < node.splitRight) evaluated: lowCoordinate < node.splitRight| yes Evaluation Count:151 | yes Evaluation Count:574 |
| 151-574 |
| 311 | node.splitRight = lowCoordinate; executed: node.splitRight = lowCoordinate;Execution Count:151 | 151 |
| 312 | if (index < node.lowestRightIndex) evaluated: index < node.lowestRightIndex| yes Evaluation Count:170 | yes Evaluation Count:555 |
| 170-555 |
| 313 | node.lowestRightIndex = index; executed: node.lowestRightIndex = index;Execution Count:170 | 170 |
| 314 | qSwap(m_index[l], m_index[r]); | - |
| 315 | --r; | - |
| 316 | } executed: }Execution Count:725 | 725 |
| 317 | } | - |
| 318 | | - |
| 319 | RectF lbounds = bounds; | - |
| 320 | (&lbounds.x2)[splitAxis] = node.splitLeft; | - |
| 321 | | - |
| 322 | RectF rbounds = bounds; | - |
| 323 | (&rbounds.x1)[splitAxis] = node.splitRight; | - |
| 324 | | - |
| 325 | TreeNode left = buildTree(first, l, depth + 1, lbounds); | - |
| 326 | m_tree[node.index.children.left] = left; | - |
| 327 | | - |
| 328 | TreeNode right = buildTree(l, last, depth + 1, rbounds); | - |
| 329 | m_tree[node.index.children.right] = right; | - |
| 330 | | - |
| 331 | return node; executed: return node;Execution Count:65 | 65 |
| 332 | } | - |
| 333 | | - |
| 334 | void SegmentTree::intersectLines(const QLineF &a, const QLineF &b, QDataBuffer<QIntersection> &intersections) | - |
| 335 | { | - |
| 336 | const QPointF p1 = a.p1(); | - |
| 337 | const QPointF p2 = a.p2(); | - |
| 338 | | - |
| 339 | const QPointF q1 = b.p1(); | - |
| 340 | const QPointF q2 = b.p2(); | - |
| 341 | | - |
| 342 | if (comparePoints(p1, p2) || comparePoints(q1, q2)) partially evaluated: comparePoints(p1, p2)| no Evaluation Count:0 | yes Evaluation Count:862 |
partially evaluated: comparePoints(q1, q2)| no Evaluation Count:0 | yes Evaluation Count:862 |
| 0-862 |
| 343 | return; | 0 |
| 344 | | - |
| 345 | const bool p1_equals_q1 = comparePoints(p1, q1); | - |
| 346 | const bool p2_equals_q2 = comparePoints(p2, q2); | - |
| 347 | | - |
| 348 | if (p1_equals_q1 && p2_equals_q2) evaluated: p1_equals_q1| yes Evaluation Count:70 | yes Evaluation Count:792 |
evaluated: p2_equals_q2| yes Evaluation Count:26 | yes Evaluation Count:44 |
| 26-792 |
| 349 | return; executed: return;Execution Count:26 | 26 |
| 350 | | - |
| 351 | const bool p1_equals_q2 = comparePoints(p1, q2); | - |
| 352 | const bool p2_equals_q1 = comparePoints(p2, q1); | - |
| 353 | | - |
| 354 | if (p1_equals_q2 && p2_equals_q1) evaluated: p1_equals_q2| yes Evaluation Count:451 | yes Evaluation Count:385 |
evaluated: p2_equals_q1| yes Evaluation Count:4 | yes Evaluation Count:447 |
| 4-451 |
| 355 | return; executed: return;Execution Count:4 | 4 |
| 356 | | - |
| 357 | const QPointF pDelta = p2 - p1; | - |
| 358 | const QPointF qDelta = q2 - q1; | - |
| 359 | | - |
| 360 | const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x(); | - |
| 361 | | - |
| 362 | if (qFuzzyIsNull(par)) { evaluated: qFuzzyIsNull(par)| yes Evaluation Count:154 | yes Evaluation Count:678 |
| 154-678 |
| 363 | const QPointF normal(-pDelta.y(), pDelta.x()); | - |
| 364 | | - |
| 365 | | - |
| 366 | if (qFuzzyIsNull(dot(normal, q1 - p1))) { partially evaluated: qFuzzyIsNull(dot(normal, q1 - p1))| yes Evaluation Count:154 | no Evaluation Count:0 |
| 0-154 |
| 367 | const qreal invDp = 1 / dot(pDelta, pDelta); | - |
| 368 | | - |
| 369 | const qreal tq1 = dot(pDelta, q1 - p1) * invDp; | - |
| 370 | const qreal tq2 = dot(pDelta, q2 - p1) * invDp; | - |
| 371 | | - |
| 372 | if (tq1 > 0 && tq1 < 1) { evaluated: tq1 > 0| yes Evaluation Count:61 | yes Evaluation Count:93 |
evaluated: tq1 < 1| yes Evaluation Count:37 | yes Evaluation Count:24 |
| 24-93 |
| 373 | QIntersection intersection; | - |
| 374 | intersection.alphaA = tq1; | - |
| 375 | intersection.alphaB = 0; | - |
| 376 | intersection.pos = q1; | - |
| 377 | intersections.add(intersection); | - |
| 378 | } executed: }Execution Count:37 | 37 |
| 379 | | - |
| 380 | if (tq2 > 0 && tq2 < 1) { evaluated: tq2 > 0| yes Evaluation Count:104 | yes Evaluation Count:50 |
evaluated: tq2 < 1| yes Evaluation Count:29 | yes Evaluation Count:75 |
| 29-104 |
| 381 | QIntersection intersection; | - |
| 382 | intersection.alphaA = tq2; | - |
| 383 | intersection.alphaB = 1; | - |
| 384 | intersection.pos = q2; | - |
| 385 | intersections.add(intersection); | - |
| 386 | } executed: }Execution Count:29 | 29 |
| 387 | | - |
| 388 | const qreal invDq = 1 / dot(qDelta, qDelta); | - |
| 389 | | - |
| 390 | const qreal tp1 = dot(qDelta, p1 - q1) * invDq; | - |
| 391 | const qreal tp2 = dot(qDelta, p2 - q1) * invDq; | - |
| 392 | | - |
| 393 | if (tp1 > 0 && tp1 < 1) { evaluated: tp1 > 0| yes Evaluation Count:83 | yes Evaluation Count:71 |
evaluated: tp1 < 1| yes Evaluation Count:37 | yes Evaluation Count:46 |
| 37-83 |
| 394 | QIntersection intersection; | - |
| 395 | intersection.alphaA = 0; | - |
| 396 | intersection.alphaB = tp1; | - |
| 397 | intersection.pos = p1; | - |
| 398 | intersections.add(intersection); | - |
| 399 | } executed: }Execution Count:37 | 37 |
| 400 | | - |
| 401 | if (tp2 > 0 && tp2 < 1) { evaluated: tp2 > 0| yes Evaluation Count:120 | yes Evaluation Count:34 |
evaluated: tp2 < 1| yes Evaluation Count:35 | yes Evaluation Count:85 |
| 34-120 |
| 402 | QIntersection intersection; | - |
| 403 | intersection.alphaA = 1; | - |
| 404 | intersection.alphaB = tp2; | - |
| 405 | intersection.pos = p2; | - |
| 406 | intersections.add(intersection); | - |
| 407 | } executed: }Execution Count:35 | 35 |
| 408 | } executed: }Execution Count:154 | 154 |
| 409 | | - |
| 410 | return; executed: return;Execution Count:154 | 154 |
| 411 | } | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| 415 | if (p1_equals_q1 || p1_equals_q2 || p2_equals_q1 || p2_equals_q2) evaluated: p1_equals_q1| yes Evaluation Count:14 | yes Evaluation Count:664 |
evaluated: p1_equals_q2| yes Evaluation Count:408 | yes Evaluation Count:256 |
evaluated: p2_equals_q1| yes Evaluation Count:156 | yes Evaluation Count:100 |
evaluated: p2_equals_q2| yes Evaluation Count:14 | yes Evaluation Count:86 |
| 14-664 |
| 416 | return; executed: return;Execution Count:592 | 592 |
| 417 | | - |
| 418 | | - |
| 419 | const qreal tp = (qDelta.y() * (q1.x() - p1.x()) - | - |
| 420 | qDelta.x() * (q1.y() - p1.y())) / par; | - |
| 421 | const qreal tq = (pDelta.y() * (q1.x() - p1.x()) - | - |
| 422 | pDelta.x() * (q1.y() - p1.y())) / par; | - |
| 423 | | - |
| 424 | if (tp<0 || tp>1 || tq<0 || tq>1) partially evaluated: tp<0| no Evaluation Count:0 | yes Evaluation Count:86 |
partially evaluated: tp>1| no Evaluation Count:0 | yes Evaluation Count:86 |
partially evaluated: tq<0| no Evaluation Count:0 | yes Evaluation Count:86 |
partially evaluated: tq>1| no Evaluation Count:0 | yes Evaluation Count:86 |
| 0-86 |
| 425 | return; | 0 |
| 426 | | - |
| 427 | const bool p_zero = qFuzzyIsNull(tp); | - |
| 428 | const bool p_one = qFuzzyIsNull(tp - 1); | - |
| 429 | | - |
| 430 | const bool q_zero = qFuzzyIsNull(tq); | - |
| 431 | const bool q_one = qFuzzyIsNull(tq - 1); | - |
| 432 | | - |
| 433 | if ((q_zero || q_one) && (p_zero || p_one)) evaluated: q_zero| yes Evaluation Count:13 | yes Evaluation Count:73 |
evaluated: q_one| yes Evaluation Count:21 | yes Evaluation Count:52 |
partially evaluated: p_zero| no Evaluation Count:0 | yes Evaluation Count:34 |
partially evaluated: p_one| no Evaluation Count:0 | yes Evaluation Count:34 |
| 0-73 |
| 434 | return; | 0 |
| 435 | | - |
| 436 | QPointF pt; | - |
| 437 | if (p_zero) { evaluated: p_zero| yes Evaluation Count:15 | yes Evaluation Count:71 |
| 15-71 |
| 438 | pt = p1; | - |
| 439 | } else if (p_one) { evaluated: p_one| yes Evaluation Count:17 | yes Evaluation Count:54 |
executed: }Execution Count:15 | 15-54 |
| 440 | pt = p2; | - |
| 441 | } else if (q_zero) { evaluated: q_zero| yes Evaluation Count:13 | yes Evaluation Count:41 |
executed: }Execution Count:17 | 13-41 |
| 442 | pt = q1; | - |
| 443 | } else if (q_one) { evaluated: q_one| yes Evaluation Count:21 | yes Evaluation Count:20 |
executed: }Execution Count:13 | 13-21 |
| 444 | pt = q2; | - |
| 445 | } else { executed: }Execution Count:21 | 21 |
| 446 | pt = q1 + (q2 - q1) * tq; | - |
| 447 | } executed: }Execution Count:20 | 20 |
| 448 | | - |
| 449 | QIntersection intersection; | - |
| 450 | intersection.alphaA = tp; | - |
| 451 | intersection.alphaB = tq; | - |
| 452 | intersection.pos = pt; | - |
| 453 | intersections.add(intersection); | - |
| 454 | } executed: }Execution Count:86 | 86 |
| 455 | | - |
| 456 | void SegmentTree::produceIntersections(int segment) | - |
| 457 | { | - |
| 458 | const QRectF &segmentBounds = m_segments.elementBounds(segment); | - |
| 459 | | - |
| 460 | RectF sbounds; | - |
| 461 | sbounds.x1 = segmentBounds.left(); | - |
| 462 | sbounds.y1 = segmentBounds.top(); | - |
| 463 | sbounds.x2 = segmentBounds.right(); | - |
| 464 | sbounds.y2 = segmentBounds.bottom(); | - |
| 465 | | - |
| 466 | produceIntersections(m_tree.at(0), segment, sbounds, m_bounds, 0); | - |
| 467 | } executed: }Execution Count:488 | 488 |
| 468 | | - |
| 469 | void SegmentTree::produceIntersectionsLeaf(const TreeNode &node, int segment) | - |
| 470 | { | - |
| 471 | const QRectF &r1 = m_segments.elementBounds(segment); | - |
| 472 | const QLineF lineA = m_segments.lineAt(segment); | - |
| 473 | | - |
| 474 | for (int i = node.index.interval.first; i < node.index.interval.last; ++i) { evaluated: i < node.index.interval.last| yes Evaluation Count:4301 | yes Evaluation Count:651 |
| 651-4301 |
| 475 | const int other = m_index.at(i); | - |
| 476 | if (other >= segment) evaluated: other >= segment| yes Evaluation Count:2118 | yes Evaluation Count:2183 |
| 2118-2183 |
| 477 | continue; executed: continue;Execution Count:2118 | 2118 |
| 478 | | - |
| 479 | const QRectF &r2 = m_segments.elementBounds(other); | - |
| 480 | | - |
| 481 | if (r1.left() > r2.right() || r2.left() > r1.right()) evaluated: r1.left() > r2.right()| yes Evaluation Count:291 | yes Evaluation Count:1892 |
evaluated: r2.left() > r1.right()| yes Evaluation Count:523 | yes Evaluation Count:1369 |
| 291-1892 |
| 482 | continue; executed: continue;Execution Count:814 | 814 |
| 483 | if (r1.top() > r2.bottom() || r2.top() > r1.bottom()) evaluated: r1.top() > r2.bottom()| yes Evaluation Count:265 | yes Evaluation Count:1104 |
evaluated: r2.top() > r1.bottom()| yes Evaluation Count:242 | yes Evaluation Count:862 |
| 242-1104 |
| 484 | continue; executed: continue;Execution Count:507 | 507 |
| 485 | | - |
| 486 | m_intersections.reset(); | - |
| 487 | | - |
| 488 | const QLineF lineB = m_segments.lineAt(other); | - |
| 489 | | - |
| 490 | intersectLines(lineA, lineB, m_intersections); | - |
| 491 | | - |
| 492 | for (int k = 0; k < m_intersections.size(); ++k) { evaluated: k < m_intersections.size()| yes Evaluation Count:224 | yes Evaluation Count:862 |
| 224-862 |
| 493 | QPathSegments::Intersection i_isect, j_isect; | - |
| 494 | i_isect.vertex = j_isect.vertex = m_segments.addPoint(m_intersections.at(k).pos); | - |
| 495 | | - |
| 496 | i_isect.t = m_intersections.at(k).alphaA; | - |
| 497 | j_isect.t = m_intersections.at(k).alphaB; | - |
| 498 | | - |
| 499 | i_isect.next = 0; | - |
| 500 | j_isect.next = 0; | - |
| 501 | | - |
| 502 | m_segments.addIntersection(segment, i_isect); | - |
| 503 | m_segments.addIntersection(other, j_isect); | - |
| 504 | } executed: }Execution Count:224 | 224 |
| 505 | } executed: }Execution Count:862 | 862 |
| 506 | } executed: }Execution Count:651 | 651 |
| 507 | | - |
| 508 | void SegmentTree::produceIntersections(const TreeNode &node, int segment, const RectF &segmentBounds, const RectF &nodeBounds, int axis) | - |
| 509 | { | - |
| 510 | if (node.leaf) { evaluated: node.leaf| yes Evaluation Count:651 | yes Evaluation Count:1670 |
| 651-1670 |
| 511 | produceIntersectionsLeaf(node, segment); | - |
| 512 | return; executed: return;Execution Count:651 | 651 |
| 513 | } | - |
| 514 | | - |
| 515 | RectF lbounds = nodeBounds; | - |
| 516 | (&lbounds.x2)[axis] = node.splitLeft; | - |
| 517 | | - |
| 518 | RectF rbounds = nodeBounds; | - |
| 519 | (&rbounds.x1)[axis] = node.splitRight; | - |
| 520 | | - |
| 521 | if (segment > node.lowestLeftIndex && (&segmentBounds.x1)[axis] <= node.splitLeft) evaluated: segment > node.lowestLeftIndex| yes Evaluation Count:355 | yes Evaluation Count:1315 |
evaluated: (&segmentBounds.x1)[axis] <= node.splitLeft| yes Evaluation Count:240 | yes Evaluation Count:115 |
| 115-1315 |
| 522 | produceIntersections(m_tree.at(node.index.children.left), segment, segmentBounds, lbounds, !axis); executed: produceIntersections(m_tree.at(node.index.children.left), segment, segmentBounds, lbounds, !axis);Execution Count:240 | 240 |
| 523 | | - |
| 524 | if (segment > node.lowestRightIndex && (&segmentBounds.x2)[axis] >= node.splitRight) evaluated: segment > node.lowestRightIndex| yes Evaluation Count:1608 | yes Evaluation Count:62 |
evaluated: (&segmentBounds.x2)[axis] >= node.splitRight| yes Evaluation Count:1593 | yes Evaluation Count:15 |
| 15-1608 |
| 525 | produceIntersections(m_tree.at(node.index.children.right), segment, segmentBounds, rbounds, !axis); executed: produceIntersections(m_tree.at(node.index.children.right), segment, segmentBounds, rbounds, !axis);Execution Count:1593 | 1593 |
| 526 | } executed: }Execution Count:1670 | 1670 |
| 527 | | - |
| 528 | } | - |
| 529 | | - |
| 530 | void QIntersectionFinder::produceIntersections(QPathSegments &segments) | - |
| 531 | { | - |
| 532 | SegmentTree tree(segments); | - |
| 533 | | - |
| 534 | for (int i = 0; i < segments.segments(); ++i) evaluated: i < segments.segments()| yes Evaluation Count:488 | yes Evaluation Count:70 |
| 70-488 |
| 535 | tree.produceIntersections(i); executed: tree.produceIntersections(i);Execution Count:488 | 488 |
| 536 | } executed: }Execution Count:70 | 70 |
| 537 | | - |
| 538 | class QKdPointTree | - |
| 539 | { | - |
| 540 | public: | - |
| 541 | enum Traversal { | - |
| 542 | TraverseBoth, | - |
| 543 | TraverseLeft, | - |
| 544 | TraverseRight, | - |
| 545 | TraverseNone | - |
| 546 | }; | - |
| 547 | | - |
| 548 | struct Node { | - |
| 549 | int point; | - |
| 550 | int id; | - |
| 551 | | - |
| 552 | Node *left; | - |
| 553 | Node *right; | - |
| 554 | }; | - |
| 555 | | - |
| 556 | QKdPointTree(const QPathSegments &segments) | - |
| 557 | : m_segments(&segments) | - |
| 558 | , m_nodes(m_segments->points()) | - |
| 559 | , m_id(0) | - |
| 560 | { | - |
| 561 | m_nodes.resize(m_segments->points()); | - |
| 562 | | - |
| 563 | for (int i = 0; i < m_nodes.size(); ++i) { evaluated: i < m_nodes.size()| yes Evaluation Count:712 | yes Evaluation Count:70 |
| 70-712 |
| 564 | m_nodes.at(i).point = i; | - |
| 565 | m_nodes.at(i).id = -1; | - |
| 566 | } executed: }Execution Count:712 | 712 |
| 567 | | - |
| 568 | m_rootNode = build(0, m_nodes.size()); | - |
| 569 | } executed: }Execution Count:70 | 70 |
| 570 | | - |
| 571 | int build(int begin, int end, int depth = 0); | - |
| 572 | | - |
| 573 | Node *rootNode() | - |
| 574 | { | - |
| 575 | return &m_nodes.at(m_rootNode); executed: return &m_nodes.at(m_rootNode);Execution Count:782 | 782 |
| 576 | } | - |
| 577 | | - |
| 578 | inline int nextId() | - |
| 579 | { | - |
| 580 | return m_id++; executed: return m_id++;Execution Count:430 | 430 |
| 581 | } | - |
| 582 | | - |
| 583 | private: | - |
| 584 | const QPathSegments *m_segments; | - |
| 585 | QDataBuffer<Node> m_nodes; | - |
| 586 | | - |
| 587 | int m_rootNode; | - |
| 588 | int m_id; | - |
| 589 | }; | - |
| 590 | | - |
| 591 | template <typename T> | - |
| 592 | void qTraverseKdPointTree(QKdPointTree::Node &node, T &t, int depth = 0) | - |
| 593 | { | - |
| 594 | QKdPointTree::Traversal status = t(node, depth); | - |
| 595 | | - |
| 596 | const bool traverseRight = (status == QKdPointTree::TraverseBoth || status == QKdPointTree::TraverseRight); evaluated: status == QKdPointTree::TraverseBoth| yes Evaluation Count:837 | yes Evaluation Count:3366 |
evaluated: status == QKdPointTree::TraverseRight| yes Evaluation Count:1833 | yes Evaluation Count:1533 |
| 837-3366 |
| 597 | const bool traverseLeft = (status == QKdPointTree::TraverseBoth || status == QKdPointTree::TraverseLeft); evaluated: status == QKdPointTree::TraverseBoth| yes Evaluation Count:837 | yes Evaluation Count:3366 |
evaluated: status == QKdPointTree::TraverseLeft| yes Evaluation Count:821 | yes Evaluation Count:2545 |
| 821-3366 |
| 598 | | - |
| 599 | if (traverseLeft && node.left) evaluated: traverseLeft| yes Evaluation Count:1658 | yes Evaluation Count:2545 |
evaluated: node.left| yes Evaluation Count:1083 | yes Evaluation Count:575 |
| 575-2545 |
| 600 | ::qTraverseKdPointTree<T>(*node.left, t, depth + 1); executed: ::qTraverseKdPointTree<T>(*node.left, t, depth + 1);Execution Count:1083 | 1083 |
| 601 | | - |
| 602 | if (traverseRight && node.right) evaluated: traverseRight| yes Evaluation Count:2670 | yes Evaluation Count:1533 |
evaluated: node.right| yes Evaluation Count:2408 | yes Evaluation Count:262 |
| 262-2670 |
| 603 | ::qTraverseKdPointTree<T>(*node.right, t, depth + 1); executed: ::qTraverseKdPointTree<T>(*node.right, t, depth + 1);Execution Count:2408 | 2408 |
| 604 | } executed: }Execution Count:4203 | 4203 |
| 605 | | - |
| 606 | static inline qreal component(const QPointF &point, unsigned int i) | - |
| 607 | { | - |
| 608 | qt_noop(); | - |
| 609 | const qreal components[] = { point.x(), point.y() }; | - |
| 610 | return components[i]; executed: return components[i];Execution Count:3658 | 3658 |
| 611 | } | - |
| 612 | | - |
| 613 | int QKdPointTree::build(int begin, int end, int depth) | - |
| 614 | { | - |
| 615 | qt_noop(); | - |
| 616 | | - |
| 617 | const qreal pivot = component(m_segments->pointAt(m_nodes.at(begin).point), depth & 1); | - |
| 618 | | - |
| 619 | int first = begin + 1; | - |
| 620 | int last = end - 1; | - |
| 621 | | - |
| 622 | while (first <= last) { evaluated: first <= last| yes Evaluation Count:2946 | yes Evaluation Count:712 |
| 712-2946 |
| 623 | const qreal value = component(m_segments->pointAt(m_nodes.at(first).point), depth & 1); | - |
| 624 | | - |
| 625 | if (value < pivot) evaluated: value < pivot| yes Evaluation Count:722 | yes Evaluation Count:2224 |
| 722-2224 |
| 626 | ++first; executed: ++first;Execution Count:722 | 722 |
| 627 | else { | - |
| 628 | qSwap(m_nodes.at(first), m_nodes.at(last)); | - |
| 629 | --last; | - |
| 630 | } executed: }Execution Count:2224 | 2224 |
| 631 | } | - |
| 632 | | - |
| 633 | qSwap(m_nodes.at(last), m_nodes.at(begin)); | - |
| 634 | | - |
| 635 | if (last > begin) evaluated: last > begin| yes Evaluation Count:184 | yes Evaluation Count:528 |
| 184-528 |
| 636 | m_nodes.at(last).left = &m_nodes.at(build(begin, last, depth + 1)); executed: m_nodes.at(last).left = &m_nodes.at(build(begin, last, depth + 1));Execution Count:184 | 184 |
| 637 | else | - |
| 638 | m_nodes.at(last).left = 0; executed: m_nodes.at(last).left = 0;Execution Count:528 | 528 |
| 639 | | - |
| 640 | if (last + 1 < end) evaluated: last + 1 < end| yes Evaluation Count:458 | yes Evaluation Count:254 |
| 254-458 |
| 641 | m_nodes.at(last).right = &m_nodes.at(build(last + 1, end, depth + 1)); executed: m_nodes.at(last).right = &m_nodes.at(build(last + 1, end, depth + 1));Execution Count:458 | 458 |
| 642 | else | - |
| 643 | m_nodes.at(last).right = 0; executed: m_nodes.at(last).right = 0;Execution Count:254 | 254 |
| 644 | | - |
| 645 | return last; executed: return last;Execution Count:712 | 712 |
| 646 | } | - |
| 647 | | - |
| 648 | class QKdPointFinder | - |
| 649 | { | - |
| 650 | public: | - |
| 651 | QKdPointFinder(int point, const QPathSegments &segments, QKdPointTree &tree) | - |
| 652 | : m_point(point) | - |
| 653 | , m_result(-1) | - |
| 654 | , m_segments(&segments) | - |
| 655 | , m_tree(&tree) | - |
| 656 | { | - |
| 657 | pointComponents[0] = segments.pointAt(point).x(); | - |
| 658 | pointComponents[1] = segments.pointAt(point).y(); | - |
| 659 | } executed: }Execution Count:712 | 712 |
| 660 | | - |
| 661 | inline QKdPointTree::Traversal operator()(QKdPointTree::Node &node, int depth) | - |
| 662 | { | - |
| 663 | if (m_result != -1) partially evaluated: m_result != -1| no Evaluation Count:0 | yes Evaluation Count:4203 |
| 0-4203 |
| 664 | return QKdPointTree::TraverseNone; never executed: return QKdPointTree::TraverseNone; | 0 |
| 665 | | - |
| 666 | const QPointF &nodePoint = m_segments->pointAt(node.point); | - |
| 667 | | - |
| 668 | const qreal pivotComponents[] = { nodePoint.x(), nodePoint.y() }; | - |
| 669 | | - |
| 670 | const qreal pivot = pivotComponents[depth & 1]; | - |
| 671 | const qreal value = pointComponents[depth & 1]; | - |
| 672 | | - |
| 673 | if (fuzzyIsNull(pivot - value)) { evaluated: fuzzyIsNull(pivot - value)| yes Evaluation Count:1549 | yes Evaluation Count:2654 |
| 1549-2654 |
| 674 | const qreal pivot2 = pivotComponents[(depth + 1) & 1]; | - |
| 675 | const qreal value2 = pointComponents[(depth + 1) & 1]; | - |
| 676 | | - |
| 677 | if (fuzzyIsNull(pivot2 - value2)) { evaluated: fuzzyIsNull(pivot2 - value2)| yes Evaluation Count:712 | yes Evaluation Count:837 |
| 712-837 |
| 678 | if (node.id < 0) evaluated: node.id < 0| yes Evaluation Count:430 | yes Evaluation Count:282 |
| 282-430 |
| 679 | node.id = m_tree->nextId(); executed: node.id = m_tree->nextId();Execution Count:430 | 430 |
| 680 | | - |
| 681 | m_result = node.id; | - |
| 682 | return QKdPointTree::TraverseNone; executed: return QKdPointTree::TraverseNone;Execution Count:712 | 712 |
| 683 | } else | - |
| 684 | return QKdPointTree::TraverseBoth; executed: return QKdPointTree::TraverseBoth;Execution Count:837 | 837 |
| 685 | } else if (value < pivot) { evaluated: value < pivot| yes Evaluation Count:821 | yes Evaluation Count:1833 |
| 821-1833 |
| 686 | return QKdPointTree::TraverseLeft; executed: return QKdPointTree::TraverseLeft;Execution Count:821 | 821 |
| 687 | } else { | - |
| 688 | return QKdPointTree::TraverseRight; executed: return QKdPointTree::TraverseRight;Execution Count:1833 | 1833 |
| 689 | } | - |
| 690 | } | - |
| 691 | | - |
| 692 | int result() const | - |
| 693 | { | - |
| 694 | return m_result; executed: return m_result;Execution Count:1424 | 1424 |
| 695 | } | - |
| 696 | | - |
| 697 | private: | - |
| 698 | int m_point; | - |
| 699 | qreal pointComponents[2]; | - |
| 700 | int m_result; | - |
| 701 | const QPathSegments *m_segments; | - |
| 702 | QKdPointTree *m_tree; | - |
| 703 | }; | - |
| 704 | | - |
| 705 | | - |
| 706 | void QPathSegments::mergePoints() | - |
| 707 | { | - |
| 708 | QKdPointTree tree(*this); | - |
| 709 | | - |
| 710 | if (tree.rootNode()) { partially evaluated: tree.rootNode()| yes Evaluation Count:70 | no Evaluation Count:0 |
| 0-70 |
| 711 | QDataBuffer<QPointF> mergedPoints(points()); | - |
| 712 | QDataBuffer<int> pointIndices(points()); | - |
| 713 | | - |
| 714 | for (int i = 0; i < points(); ++i) { evaluated: i < points()| yes Evaluation Count:712 | yes Evaluation Count:70 |
| 70-712 |
| 715 | QKdPointFinder finder(i, *this, tree); | - |
| 716 | ::qTraverseKdPointTree<QKdPointFinder>(*tree.rootNode(), finder); | - |
| 717 | | - |
| 718 | qt_noop(); | - |
| 719 | | - |
| 720 | if (finder.result() >= mergedPoints.size()) evaluated: finder.result() >= mergedPoints.size()| yes Evaluation Count:430 | yes Evaluation Count:282 |
| 282-430 |
| 721 | mergedPoints << m_points.at(i); executed: mergedPoints << m_points.at(i);Execution Count:430 | 430 |
| 722 | | - |
| 723 | pointIndices << finder.result(); | - |
| 724 | } executed: }Execution Count:712 | 712 |
| 725 | | - |
| 726 | for (int i = 0; i < m_segments.size(); ++i) { evaluated: i < m_segments.size()| yes Evaluation Count:488 | yes Evaluation Count:70 |
| 70-488 |
| 727 | m_segments.at(i).va = pointIndices.at(m_segments.at(i).va); | - |
| 728 | m_segments.at(i).vb = pointIndices.at(m_segments.at(i).vb); | - |
| 729 | } executed: }Execution Count:488 | 488 |
| 730 | | - |
| 731 | for (int i = 0; i < m_intersections.size(); ++i) evaluated: i < m_intersections.size()| yes Evaluation Count:448 | yes Evaluation Count:70 |
| 70-448 |
| 732 | m_intersections.at(i).vertex = pointIndices.at(m_intersections.at(i).vertex); executed: m_intersections.at(i).vertex = pointIndices.at(m_intersections.at(i).vertex);Execution Count:448 | 448 |
| 733 | | - |
| 734 | m_points.swap(mergedPoints); | - |
| 735 | } executed: }Execution Count:70 | 70 |
| 736 | } executed: }Execution Count:70 | 70 |
| 737 | | - |
| 738 | void QWingedEdge::intersectAndAdd() | - |
| 739 | { | - |
| 740 | QIntersectionFinder finder; | - |
| 741 | finder.produceIntersections(m_segments); | - |
| 742 | | - |
| 743 | m_segments.mergePoints(); | - |
| 744 | | - |
| 745 | for (int i = 0; i < m_segments.points(); ++i) evaluated: i < m_segments.points()| yes Evaluation Count:430 | yes Evaluation Count:70 |
| 70-430 |
| 746 | addVertex(m_segments.pointAt(i)); executed: addVertex(m_segments.pointAt(i));Execution Count:430 | 430 |
| 747 | | - |
| 748 | QDataBuffer<QPathSegments::Intersection> intersections(m_segments.segments()); | - |
| 749 | for (int i = 0; i < m_segments.segments(); ++i) { evaluated: i < m_segments.segments()| yes Evaluation Count:488 | yes Evaluation Count:70 |
| 70-488 |
| 750 | intersections.reset(); | - |
| 751 | | - |
| 752 | int pathId = m_segments.pathId(i); | - |
| 753 | | - |
| 754 | const QPathSegments::Intersection *isect = m_segments.intersectionAt(i); | - |
| 755 | while (isect) { evaluated: isect| yes Evaluation Count:448 | yes Evaluation Count:488 |
| 448-488 |
| 756 | intersections << *isect; | - |
| 757 | | - |
| 758 | if (isect->next) { evaluated: isect->next| yes Evaluation Count:258 | yes Evaluation Count:190 |
| 190-258 |
| 759 | isect += isect->next; | - |
| 760 | } else { executed: }Execution Count:258 | 258 |
| 761 | isect = 0; | - |
| 762 | } executed: }Execution Count:190 | 190 |
| 763 | } | - |
| 764 | | - |
| 765 | qSort(intersections.data(), intersections.data() + intersections.size()); | - |
| 766 | | - |
| 767 | int first = m_segments.segmentAt(i).va; | - |
| 768 | int second = m_segments.segmentAt(i).vb; | - |
| 769 | | - |
| 770 | int last = first; | - |
| 771 | for (int j = 0; j < intersections.size(); ++j) { evaluated: j < intersections.size()| yes Evaluation Count:448 | yes Evaluation Count:488 |
| 448-488 |
| 772 | const QPathSegments::Intersection &isect = intersections.at(j); | - |
| 773 | | - |
| 774 | QPathEdge *ep = edge(addEdge(last, isect.vertex)); | - |
| 775 | | - |
| 776 | if (ep) { evaluated: ep| yes Evaluation Count:200 | yes Evaluation Count:248 |
| 200-248 |
| 777 | const int dir = m_segments.pointAt(last).y() < m_segments.pointAt(isect.vertex).y() ? 1 : -1; evaluated: m_segments.pointAt(last).y() < m_segments.pointAt(isect.vertex).y()| yes Evaluation Count:39 | yes Evaluation Count:161 |
| 39-161 |
| 778 | if (pathId == 0) evaluated: pathId == 0| yes Evaluation Count:108 | yes Evaluation Count:92 |
| 92-108 |
| 779 | ep->windingA += dir; executed: ep->windingA += dir;Execution Count:108 | 108 |
| 780 | else | - |
| 781 | ep->windingB += dir; executed: ep->windingB += dir;Execution Count:92 | 92 |
| 782 | } | - |
| 783 | | - |
| 784 | last = isect.vertex; | - |
| 785 | } executed: }Execution Count:448 | 448 |
| 786 | | - |
| 787 | QPathEdge *ep = edge(addEdge(last, second)); | - |
| 788 | | - |
| 789 | if (ep) { evaluated: ep| yes Evaluation Count:398 | yes Evaluation Count:90 |
| 90-398 |
| 790 | const int dir = m_segments.pointAt(last).y() < m_segments.pointAt(second).y() ? 1 : -1; evaluated: m_segments.pointAt(last).y() < m_segments.pointAt(second).y()| yes Evaluation Count:94 | yes Evaluation Count:304 |
| 94-304 |
| 791 | if (pathId == 0) evaluated: pathId == 0| yes Evaluation Count:310 | yes Evaluation Count:88 |
| 88-310 |
| 792 | ep->windingA += dir; executed: ep->windingA += dir;Execution Count:310 | 310 |
| 793 | else | - |
| 794 | ep->windingB += dir; executed: ep->windingB += dir;Execution Count:88 | 88 |
| 795 | } | - |
| 796 | } executed: }Execution Count:488 | 488 |
| 797 | } executed: }Execution Count:70 | 70 |
| 798 | | - |
| 799 | QWingedEdge::QWingedEdge() : | - |
| 800 | m_edges(0), | - |
| 801 | m_vertices(0), | - |
| 802 | m_segments(0) | - |
| 803 | { | - |
| 804 | } | 0 |
| 805 | | - |
| 806 | QWingedEdge::QWingedEdge(const QPainterPath &subject, const QPainterPath &clip) : | - |
| 807 | m_edges(subject.elementCount()), | - |
| 808 | m_vertices(subject.elementCount()), | - |
| 809 | m_segments(subject.elementCount()) | - |
| 810 | { | - |
| 811 | m_segments.setPath(subject); | - |
| 812 | m_segments.addPath(clip); | - |
| 813 | | - |
| 814 | intersectAndAdd(); | - |
| 815 | } executed: }Execution Count:70 | 70 |
| 816 | | - |
| 817 | QWingedEdge::TraversalStatus QWingedEdge::next(const QWingedEdge::TraversalStatus &status) const | - |
| 818 | { | - |
| 819 | const QPathEdge *sp = edge(status.edge); | - |
| 820 | qt_noop(); | - |
| 821 | | - |
| 822 | TraversalStatus result; | - |
| 823 | result.edge = sp->next(status.traversal, status.direction); | - |
| 824 | result.traversal = status.traversal; | - |
| 825 | result.direction = status.direction; | - |
| 826 | | - |
| 827 | const QPathEdge *rp = edge(result.edge); | - |
| 828 | qt_noop(); | - |
| 829 | | - |
| 830 | if (sp->vertex(status.direction) == rp->vertex(status.direction)) evaluated: sp->vertex(status.direction) == rp->vertex(status.direction)| yes Evaluation Count:1182 | yes Evaluation Count:2457 |
| 1182-2457 |
| 831 | result.flip(); executed: result.flip();Execution Count:1182 | 1182 |
| 832 | | - |
| 833 | return result; executed: return result;Execution Count:3639 | 3639 |
| 834 | } | - |
| 835 | | - |
| 836 | static bool isLine(const QBezier &bezier) | - |
| 837 | { | - |
| 838 | const bool equal_1_2 = comparePoints(bezier.pt1(), bezier.pt2()); | - |
| 839 | const bool equal_2_3 = comparePoints(bezier.pt2(), bezier.pt3()); | - |
| 840 | const bool equal_3_4 = comparePoints(bezier.pt3(), bezier.pt4()); | - |
| 841 | | - |
| 842 | | - |
| 843 | if (equal_1_2 && equal_2_3 && equal_3_4) partially evaluated: equal_1_2| no Evaluation Count:0 | yes Evaluation Count:700 |
never evaluated: equal_2_3 never evaluated: equal_3_4 | 0-700 |
| 844 | return true; never executed: return true; | 0 |
| 845 | | - |
| 846 | if (comparePoints(bezier.pt1(), bezier.pt4())) partially evaluated: comparePoints(bezier.pt1(), bezier.pt4())| no Evaluation Count:0 | yes Evaluation Count:700 |
| 0-700 |
| 847 | return equal_1_2 || equal_3_4; never executed: return equal_1_2 || equal_3_4; | 0 |
| 848 | | - |
| 849 | return (equal_1_2 && equal_3_4) || (equal_1_2 && equal_2_3) || (equal_2_3 && equal_3_4); executed: return (equal_1_2 && equal_3_4) || (equal_1_2 && equal_2_3) || (equal_2_3 && equal_3_4);Execution Count:700 | 700 |
| 850 | } | - |
| 851 | | - |
| 852 | void QPathSegments::setPath(const QPainterPath &path) | - |
| 853 | { | - |
| 854 | m_points.reset(); | - |
| 855 | m_intersections.reset(); | - |
| 856 | m_segments.reset(); | - |
| 857 | | - |
| 858 | m_pathId = 0; | - |
| 859 | | - |
| 860 | addPath(path); | - |
| 861 | } executed: }Execution Count:312 | 312 |
| 862 | | - |
| 863 | void QPathSegments::addPath(const QPainterPath &path) | - |
| 864 | { | - |
| 865 | int firstSegment = m_segments.size(); | - |
| 866 | | - |
| 867 | bool hasMoveTo = false; | - |
| 868 | int lastMoveTo = 0; | - |
| 869 | int last = 0; | - |
| 870 | for (int i = 0; i < path.elementCount(); ++i) { evaluated: i < path.elementCount()| yes Evaluation Count:3272 | yes Evaluation Count:382 |
| 382-3272 |
| 871 | int current = m_points.size(); | - |
| 872 | | - |
| 873 | QPointF currentPoint; | - |
| 874 | if (path.elementAt(i).type == QPainterPath::CurveToElement) evaluated: path.elementAt(i).type == QPainterPath::CurveToElement| yes Evaluation Count:700 | yes Evaluation Count:2572 |
| 700-2572 |
| 875 | currentPoint = path.elementAt(i+2); executed: currentPoint = path.elementAt(i+2);Execution Count:700 | 700 |
| 876 | else | - |
| 877 | currentPoint = path.elementAt(i); executed: currentPoint = path.elementAt(i);Execution Count:2572 | 2572 |
| 878 | | - |
| 879 | if (i > 0 && comparePoints(m_points.at(lastMoveTo), currentPoint)) evaluated: i > 0| yes Evaluation Count:2944 | yes Evaluation Count:328 |
evaluated: comparePoints(m_points.at(lastMoveTo), currentPoint)| yes Evaluation Count:468 | yes Evaluation Count:2476 |
| 328-2944 |
| 880 | current = lastMoveTo; executed: current = lastMoveTo;Execution Count:468 | 468 |
| 881 | else | - |
| 882 | m_points << currentPoint; executed: m_points << currentPoint;Execution Count:2804 | 2804 |
| 883 | | - |
| 884 | switch (path.elementAt(i).type) { | - |
| 885 | case QPainterPath::MoveToElement: | - |
| 886 | if (hasMoveTo && last != lastMoveTo && !comparePoints(m_points.at(last), m_points.at(lastMoveTo))) evaluated: hasMoveTo| yes Evaluation Count:197 | yes Evaluation Count:328 |
evaluated: last != lastMoveTo| yes Evaluation Count:2 | yes Evaluation Count:195 |
partially evaluated: !comparePoints(m_points.at(last), m_points.at(lastMoveTo))| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-328 |
| 887 | m_segments << Segment(m_pathId, last, lastMoveTo); executed: m_segments << Segment(m_pathId, last, lastMoveTo);Execution Count:2 | 2 |
| 888 | hasMoveTo = true; | - |
| 889 | last = lastMoveTo = current; | - |
| 890 | break; executed: break;Execution Count:525 | 525 |
| 891 | case QPainterPath::LineToElement: | - |
| 892 | m_segments << Segment(m_pathId, last, current); | - |
| 893 | last = current; | - |
| 894 | break; executed: break;Execution Count:2047 | 2047 |
| 895 | case QPainterPath::CurveToElement: | - |
| 896 | { | - |
| 897 | QBezier bezier = QBezier::fromPoints(m_points.at(last), path.elementAt(i), path.elementAt(i+1), path.elementAt(i+2)); | - |
| 898 | if (isLine(bezier)) { partially evaluated: isLine(bezier)| no Evaluation Count:0 | yes Evaluation Count:700 |
| 0-700 |
| 899 | m_segments << Segment(m_pathId, last, current); | - |
| 900 | } else { | 0 |
| 901 | QRectF bounds = bezier.bounds(); | - |
| 902 | | - |
| 903 | | - |
| 904 | int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * (2 * qreal(3.14) / 6)); | - |
| 905 | | - |
| 906 | if (threshold < 3) threshold = 3; executed: threshold = 3;Execution Count:80 evaluated: threshold < 3| yes Evaluation Count:80 | yes Evaluation Count:620 |
| 80-620 |
| 907 | qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1); | - |
| 908 | | - |
| 909 | for (int t = 1; t < threshold - 1; ++t) { evaluated: t < threshold - 1| yes Evaluation Count:16720 | yes Evaluation Count:700 |
| 700-16720 |
| 910 | currentPoint = bezier.pointAt(t * one_over_threshold_minus_1); | - |
| 911 | | - |
| 912 | int index = m_points.size(); | - |
| 913 | m_segments << Segment(m_pathId, last, index); | - |
| 914 | last = index; | - |
| 915 | | - |
| 916 | m_points << currentPoint; | - |
| 917 | } executed: }Execution Count:16720 | 16720 |
| 918 | | - |
| 919 | m_segments << Segment(m_pathId, last, current); | - |
| 920 | } executed: }Execution Count:700 | 700 |
| 921 | } | - |
| 922 | last = current; | - |
| 923 | i += 2; | - |
| 924 | break; executed: break;Execution Count:700 | 700 |
| 925 | default: | - |
| 926 | qt_noop(); | - |
| 927 | break; | 0 |
| 928 | } | - |
| 929 | } executed: }Execution Count:3272 | 3272 |
| 930 | | - |
| 931 | if (hasMoveTo && last != lastMoveTo && !comparePoints(m_points.at(last), m_points.at(lastMoveTo))) evaluated: hasMoveTo| yes Evaluation Count:328 | yes Evaluation Count:54 |
evaluated: last != lastMoveTo| yes Evaluation Count:55 | yes Evaluation Count:273 |
partially evaluated: !comparePoints(m_points.at(last), m_points.at(lastMoveTo))| yes Evaluation Count:55 | no Evaluation Count:0 |
| 0-328 |
| 932 | m_segments << Segment(m_pathId, last, lastMoveTo); executed: m_segments << Segment(m_pathId, last, lastMoveTo);Execution Count:55 | 55 |
| 933 | | - |
| 934 | for (int i = firstSegment; i < m_segments.size(); ++i) { evaluated: i < m_segments.size()| yes Evaluation Count:19524 | yes Evaluation Count:382 |
| 382-19524 |
| 935 | const QLineF line = lineAt(i); | - |
| 936 | | - |
| 937 | qreal x1 = line.p1().x(); | - |
| 938 | qreal y1 = line.p1().y(); | - |
| 939 | qreal x2 = line.p2().x(); | - |
| 940 | qreal y2 = line.p2().y(); | - |
| 941 | | - |
| 942 | if (x2 < x1) evaluated: x2 < x1| yes Evaluation Count:9308 | yes Evaluation Count:10216 |
| 9308-10216 |
| 943 | qSwap(x1, x2); executed: qSwap(x1, x2);Execution Count:9308 | 9308 |
| 944 | if (y2 < y1) evaluated: y2 < y1| yes Evaluation Count:9298 | yes Evaluation Count:10226 |
| 9298-10226 |
| 945 | qSwap(y1, y2); executed: qSwap(y1, y2);Execution Count:9298 | 9298 |
| 946 | | - |
| 947 | m_segments.at(i).bounds = QRectF(x1, y1, x2 - x1, y2 - y1); | - |
| 948 | } executed: }Execution Count:19524 | 19524 |
| 949 | | - |
| 950 | ++m_pathId; | - |
| 951 | } executed: }Execution Count:382 | 382 |
| 952 | | - |
| 953 | qreal QWingedEdge::delta(int vertex, int a, int b) const | - |
| 954 | { | - |
| 955 | const QPathEdge *ap = edge(a); | - |
| 956 | const QPathEdge *bp = edge(b); | - |
| 957 | | - |
| 958 | double a_angle = ap->angle; | - |
| 959 | double b_angle = bp->angle; | - |
| 960 | | - |
| 961 | if (vertex == ap->second) evaluated: vertex == ap->second| yes Evaluation Count:157 | yes Evaluation Count:437 |
| 157-437 |
| 962 | a_angle = ap->invAngle; executed: a_angle = ap->invAngle;Execution Count:157 | 157 |
| 963 | | - |
| 964 | if (vertex == bp->second) evaluated: vertex == bp->second| yes Evaluation Count:437 | yes Evaluation Count:157 |
| 157-437 |
| 965 | b_angle = bp->invAngle; executed: b_angle = bp->invAngle;Execution Count:437 | 437 |
| 966 | | - |
| 967 | double result = b_angle - a_angle; | - |
| 968 | | - |
| 969 | if (result >= 128.) partially evaluated: result >= 128.| no Evaluation Count:0 | yes Evaluation Count:594 |
| 0-594 |
| 970 | return result - 128.; never executed: return result - 128.; | 0 |
| 971 | else if (result < 0) evaluated: result < 0| yes Evaluation Count:317 | yes Evaluation Count:277 |
| 277-317 |
| 972 | return result + 128.; executed: return result + 128.;Execution Count:317 | 317 |
| 973 | else | - |
| 974 | return result; executed: return result;Execution Count:277 | 277 |
| 975 | } | - |
| 976 | | - |
| 977 | static inline QPointF midPoint(const QWingedEdge &list, int ei) | - |
| 978 | { | - |
| 979 | const QPathEdge *ep = list.edge(ei); | - |
| 980 | qt_noop(); | - |
| 981 | | - |
| 982 | const QPointF a = *list.vertex(ep->first); | - |
| 983 | const QPointF b = *list.vertex(ep->second); | - |
| 984 | return a + 0.5 * (b - a); never executed: return a + 0.5 * (b - a); | 0 |
| 985 | } | - |
| 986 | | - |
| 987 | QWingedEdge::TraversalStatus QWingedEdge::findInsertStatus(int vi, int ei) const | - |
| 988 | { | - |
| 989 | const QPathVertex *vp = vertex(vi); | - |
| 990 | | - |
| 991 | qt_noop(); | - |
| 992 | qt_noop(); | - |
| 993 | qt_noop(); | - |
| 994 | | - |
| 995 | int position = vp->edge; | - |
| 996 | qreal d = 128.; | - |
| 997 | | - |
| 998 | TraversalStatus status; | - |
| 999 | status.direction = edge(vp->edge)->directionTo(vi); | - |
| 1000 | status.traversal = QPathEdge::RightTraversal; | - |
| 1001 | status.edge = vp->edge; | - |
| 1002 | | - |
| 1003 | | - |
| 1004 | | - |
| 1005 | | - |
| 1006 | | - |
| 1007 | | - |
| 1008 | do { | - |
| 1009 | status = next(status); | - |
| 1010 | status.flip(); | - |
| 1011 | | - |
| 1012 | qt_noop(); | - |
| 1013 | qreal d2 = delta(vi, ei, status.edge); | - |
| 1014 | | - |
| 1015 | | - |
| 1016 | | - |
| 1017 | | - |
| 1018 | | - |
| 1019 | | - |
| 1020 | if (d2 < d) { evaluated: d2 < d| yes Evaluation Count:541 | yes Evaluation Count:53 |
| 53-541 |
| 1021 | position = status.edge; | - |
| 1022 | d = d2; | - |
| 1023 | } executed: }Execution Count:541 | 541 |
| 1024 | } while (status.edge != vp->edge); executed: }Execution Count:594 evaluated: status.edge != vp->edge| yes Evaluation Count:92 | yes Evaluation Count:502 |
| 92-594 |
| 1025 | | - |
| 1026 | status.traversal = QPathEdge::LeftTraversal; | - |
| 1027 | status.direction = QPathEdge::Forward; | - |
| 1028 | status.edge = position; | - |
| 1029 | | - |
| 1030 | if (edge(status.edge)->vertex(status.direction) != vi) evaluated: edge(status.edge)->vertex(status.direction) != vi| yes Evaluation Count:117 | yes Evaluation Count:385 |
| 117-385 |
| 1031 | status.flip(); executed: status.flip();Execution Count:117 | 117 |
| 1032 | | - |
| 1033 | | - |
| 1034 | | - |
| 1035 | | - |
| 1036 | | - |
| 1037 | qt_noop(); | - |
| 1038 | | - |
| 1039 | return status; executed: return status;Execution Count:502 | 502 |
| 1040 | } | - |
| 1041 | | - |
| 1042 | void QWingedEdge::removeEdge(int ei) | - |
| 1043 | { | - |
| 1044 | QPathEdge *ep = edge(ei); | - |
| 1045 | | - |
| 1046 | TraversalStatus status; | - |
| 1047 | status.direction = QPathEdge::Forward; | - |
| 1048 | status.traversal = QPathEdge::RightTraversal; | - |
| 1049 | status.edge = ei; | - |
| 1050 | | - |
| 1051 | TraversalStatus forwardRight = next(status); | - |
| 1052 | forwardRight.flipDirection(); | - |
| 1053 | | - |
| 1054 | status.traversal = QPathEdge::LeftTraversal; | - |
| 1055 | TraversalStatus forwardLeft = next(status); | - |
| 1056 | forwardLeft.flipDirection(); | - |
| 1057 | | - |
| 1058 | status.direction = QPathEdge::Backward; | - |
| 1059 | TraversalStatus backwardLeft = next(status); | - |
| 1060 | backwardLeft.flipDirection(); | - |
| 1061 | | - |
| 1062 | status.traversal = QPathEdge::RightTraversal; | - |
| 1063 | TraversalStatus backwardRight = next(status); | - |
| 1064 | backwardRight.flipDirection(); | - |
| 1065 | | - |
| 1066 | edge(forwardRight.edge)->setNext(forwardRight.traversal, forwardRight.direction, forwardLeft.edge); | - |
| 1067 | edge(forwardLeft.edge)->setNext(forwardLeft.traversal, forwardLeft.direction, forwardRight.edge); | - |
| 1068 | | - |
| 1069 | edge(backwardRight.edge)->setNext(backwardRight.traversal, backwardRight.direction, backwardLeft.edge); | - |
| 1070 | edge(backwardLeft.edge)->setNext(backwardLeft.traversal, backwardLeft.direction, backwardRight.edge); | - |
| 1071 | | - |
| 1072 | ep->setNext(QPathEdge::Forward, ei); | - |
| 1073 | ep->setNext(QPathEdge::Backward, ei); | - |
| 1074 | | - |
| 1075 | QPathVertex *a = vertex(ep->first); | - |
| 1076 | QPathVertex *b = vertex(ep->second); | - |
| 1077 | | - |
| 1078 | a->edge = backwardRight.edge; | - |
| 1079 | b->edge = forwardRight.edge; | - |
| 1080 | } executed: }Execution Count:20 | 20 |
| 1081 | | - |
| 1082 | static int commonEdge(const QWingedEdge &list, int a, int b) | - |
| 1083 | { | - |
| 1084 | const QPathVertex *ap = list.vertex(a); | - |
| 1085 | qt_noop(); | - |
| 1086 | | - |
| 1087 | const QPathVertex *bp = list.vertex(b); | - |
| 1088 | qt_noop(); | - |
| 1089 | | - |
| 1090 | if (ap->edge < 0 || bp->edge < 0) evaluated: ap->edge < 0| yes Evaluation Count:82 | yes Evaluation Count:516 |
evaluated: bp->edge < 0| yes Evaluation Count:273 | yes Evaluation Count:243 |
| 82-516 |
| 1091 | return -1; executed: return -1;Execution Count:355 | 355 |
| 1092 | | - |
| 1093 | QWingedEdge::TraversalStatus status; | - |
| 1094 | status.edge = ap->edge; | - |
| 1095 | status.direction = list.edge(status.edge)->directionTo(a); | - |
| 1096 | status.traversal = QPathEdge::RightTraversal; | - |
| 1097 | | - |
| 1098 | do { | - |
| 1099 | const QPathEdge *ep = list.edge(status.edge); | - |
| 1100 | | - |
| 1101 | if ((ep->first == a && ep->second == b) evaluated: ep->first == a| yes Evaluation Count:138 | yes Evaluation Count:247 |
evaluated: ep->second == b| yes Evaluation Count:110 | yes Evaluation Count:28 |
| 28-247 |
| 1102 | || (ep->first == b && ep->second == a)) evaluated: ep->first == b| yes Evaluation Count:22 | yes Evaluation Count:253 |
partially evaluated: ep->second == a| yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-253 |
| 1103 | return status.edge; executed: return status.edge;Execution Count:132 | 132 |
| 1104 | | - |
| 1105 | status = list.next(status); | - |
| 1106 | status.flip(); | - |
| 1107 | } while (status.edge != ap->edge); executed: }Execution Count:253 evaluated: status.edge != ap->edge| yes Evaluation Count:142 | yes Evaluation Count:111 |
| 111-253 |
| 1108 | | - |
| 1109 | return -1; executed: return -1;Execution Count:111 | 111 |
| 1110 | } | - |
| 1111 | | - |
| 1112 | static double computeAngle(const QPointF &v) | - |
| 1113 | { | - |
| 1114 | | - |
| 1115 | if (v.x() == 0) { evaluated: v.x() == 0| yes Evaluation Count:218 | yes Evaluation Count:248 |
| 218-248 |
| 1116 | return v.y() <= 0 ? 0 : 64.; executed: return v.y() <= 0 ? 0 : 64.;Execution Count:218 | 218 |
| 1117 | } else if (v.y() == 0) { partially evaluated: v.y() == 0| yes Evaluation Count:248 | no Evaluation Count:0 |
| 0-248 |
| 1118 | return v.x() <= 0 ? 32. : 96.; executed: return v.x() <= 0 ? 32. : 96.;Execution Count:248 | 248 |
| 1119 | } | - |
| 1120 | | - |
| 1121 | double vx = v.x(); | - |
| 1122 | double vy = v.y(); | - |
| 1123 | normalize(vx, vy); | - |
| 1124 | if (vy < 0) { | 0 |
| 1125 | if (vx < 0) { | 0 |
| 1126 | return -32. * vx; never executed: return -32. * vx; | 0 |
| 1127 | } else { | - |
| 1128 | return 128. - 32. * vx; never executed: return 128. - 32. * vx; | 0 |
| 1129 | } | - |
| 1130 | } else { | - |
| 1131 | return 64. + 32. * vx; never executed: return 64. + 32. * vx; | 0 |
| 1132 | } | - |
| 1133 | | - |
| 1134 | | - |
| 1135 | | - |
| 1136 | | - |
| 1137 | } | - |
| 1138 | | - |
| 1139 | int QWingedEdge::addEdge(const QPointF &a, const QPointF &b) | - |
| 1140 | { | - |
| 1141 | int fi = insert(a); | - |
| 1142 | int si = insert(b); | - |
| 1143 | | - |
| 1144 | return addEdge(fi, si); never executed: return addEdge(fi, si); | 0 |
| 1145 | } | - |
| 1146 | | - |
| 1147 | int QWingedEdge::addEdge(int fi, int si) | - |
| 1148 | { | - |
| 1149 | if (fi == si) evaluated: fi == si| yes Evaluation Count:338 | yes Evaluation Count:598 |
| 338-598 |
| 1150 | return -1; executed: return -1;Execution Count:338 | 338 |
| 1151 | | - |
| 1152 | int common = commonEdge(*this, fi, si); | - |
| 1153 | if (common >= 0) evaluated: common >= 0| yes Evaluation Count:132 | yes Evaluation Count:466 |
| 132-466 |
| 1154 | return common; executed: return common;Execution Count:132 | 132 |
| 1155 | | - |
| 1156 | m_edges << QPathEdge(fi, si); | - |
| 1157 | | - |
| 1158 | int ei = m_edges.size() - 1; | - |
| 1159 | | - |
| 1160 | QPathVertex *fp = vertex(fi); | - |
| 1161 | QPathVertex *sp = vertex(si); | - |
| 1162 | | - |
| 1163 | QPathEdge *ep = edge(ei); | - |
| 1164 | | - |
| 1165 | const QPointF tangent = QPointF(*sp) - QPointF(*fp); | - |
| 1166 | ep->angle = computeAngle(tangent); | - |
| 1167 | ep->invAngle = ep->angle + 64; | - |
| 1168 | if (ep->invAngle >= 128) evaluated: ep->invAngle >= 128| yes Evaluation Count:233 | yes Evaluation Count:233 |
| 233 |
| 1169 | ep->invAngle -= 128; executed: ep->invAngle -= 128;Execution Count:233 | 233 |
| 1170 | | - |
| 1171 | QPathVertex *vertices[2] = { fp, sp }; | - |
| 1172 | QPathEdge::Direction dirs[2] = { QPathEdge::Backward, QPathEdge::Forward }; | - |
| 1173 | | - |
| 1174 | | - |
| 1175 | | - |
| 1176 | | - |
| 1177 | | - |
| 1178 | for (int i = 0; i < 2; ++i) { evaluated: i < 2| yes Evaluation Count:932 | yes Evaluation Count:466 |
| 466-932 |
| 1179 | QPathVertex *vp = vertices[i]; | - |
| 1180 | if (vp->edge < 0) { evaluated: vp->edge < 0| yes Evaluation Count:430 | yes Evaluation Count:502 |
| 430-502 |
| 1181 | vp->edge = ei; | - |
| 1182 | ep->setNext(dirs[i], ei); | - |
| 1183 | } else { executed: }Execution Count:430 | 430 |
| 1184 | int vi = ep->vertex(dirs[i]); | - |
| 1185 | qt_noop(); | - |
| 1186 | | - |
| 1187 | TraversalStatus os = findInsertStatus(vi, ei); | - |
| 1188 | QPathEdge *op = edge(os.edge); | - |
| 1189 | | - |
| 1190 | qt_noop(); | - |
| 1191 | | - |
| 1192 | TraversalStatus ns = next(os); | - |
| 1193 | ns.flipDirection(); | - |
| 1194 | QPathEdge *np = edge(ns.edge); | - |
| 1195 | | - |
| 1196 | op->setNext(os.traversal, os.direction, ei); | - |
| 1197 | np->setNext(ns.traversal, ns.direction, ei); | - |
| 1198 | | - |
| 1199 | int oe = os.edge; | - |
| 1200 | int ne = ns.edge; | - |
| 1201 | | - |
| 1202 | os = next(os); | - |
| 1203 | ns = next(ns); | - |
| 1204 | | - |
| 1205 | os.flipDirection(); | - |
| 1206 | ns.flipDirection(); | - |
| 1207 | | - |
| 1208 | qt_noop(); | - |
| 1209 | qt_noop(); | - |
| 1210 | | - |
| 1211 | ep->setNext(os.traversal, os.direction, oe); | - |
| 1212 | ep->setNext(ns.traversal, ns.direction, ne); | - |
| 1213 | } executed: }Execution Count:502 | 502 |
| 1214 | } | - |
| 1215 | | - |
| 1216 | qt_noop(); | - |
| 1217 | qt_noop(); | - |
| 1218 | qt_noop(); | - |
| 1219 | qt_noop(); | - |
| 1220 | | - |
| 1221 | return ei; executed: return ei;Execution Count:466 | 466 |
| 1222 | } | - |
| 1223 | | - |
| 1224 | int QWingedEdge::insert(const QPathVertex &vertex) | - |
| 1225 | { | - |
| 1226 | if (!m_vertices.isEmpty()) { never evaluated: !m_vertices.isEmpty() | 0 |
| 1227 | const QPathVertex &last = m_vertices.last(); | - |
| 1228 | if (vertex.x == last.x && vertex.y == last.y) never evaluated: vertex.x == last.x never evaluated: vertex.y == last.y | 0 |
| 1229 | return m_vertices.size() - 1; never executed: return m_vertices.size() - 1; | 0 |
| 1230 | | - |
| 1231 | for (int i = 0; i < m_vertices.size(); ++i) { never evaluated: i < m_vertices.size() | 0 |
| 1232 | const QPathVertex &v = m_vertices.at(i); | - |
| 1233 | if (qFuzzyCompare(v.x, vertex.x) && qFuzzyCompare(v.y, vertex.y)) { never evaluated: qFuzzyCompare(v.x, vertex.x) never evaluated: qFuzzyCompare(v.y, vertex.y) | 0 |
| 1234 | return i; never executed: return i; | 0 |
| 1235 | } | - |
| 1236 | } | 0 |
| 1237 | } | 0 |
| 1238 | | - |
| 1239 | m_vertices << vertex; | - |
| 1240 | return m_vertices.size() - 1; never executed: return m_vertices.size() - 1; | 0 |
| 1241 | } | - |
| 1242 | | - |
| 1243 | static void addLineTo(QPainterPath &path, const QPointF &point) | - |
| 1244 | { | - |
| 1245 | const int elementCount = path.elementCount(); | - |
| 1246 | if (elementCount >= 2) { evaluated: elementCount >= 2| yes Evaluation Count:214 | yes Evaluation Count:60 |
| 60-214 |
| 1247 | const QPainterPath::Element &middle = path.elementAt(elementCount - 1); | - |
| 1248 | if (middle.type == QPainterPath::LineToElement) { evaluated: middle.type == QPainterPath::LineToElement| yes Evaluation Count:213 | yes Evaluation Count:1 |
| 1-213 |
| 1249 | const QPointF first = path.elementAt(elementCount - 2); | - |
| 1250 | const QPointF d1 = point - first; | - |
| 1251 | const QPointF d2 = middle - first; | - |
| 1252 | | - |
| 1253 | const QPointF p(-d1.y(), d1.x()); | - |
| 1254 | | - |
| 1255 | if (qFuzzyIsNull(dot(p, d2))) { evaluated: qFuzzyIsNull(dot(p, d2))| yes Evaluation Count:6 | yes Evaluation Count:207 |
| 6-207 |
| 1256 | path.setElementPositionAt(elementCount - 1, point.x(), point.y()); | - |
| 1257 | return; executed: return;Execution Count:6 | 6 |
| 1258 | } | - |
| 1259 | } executed: }Execution Count:207 | 207 |
| 1260 | } executed: }Execution Count:208 | 208 |
| 1261 | | - |
| 1262 | path.lineTo(point); | - |
| 1263 | } executed: }Execution Count:268 | 268 |
| 1264 | | - |
| 1265 | static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal) | - |
| 1266 | { | - |
| 1267 | QWingedEdge::TraversalStatus status; | - |
| 1268 | status.edge = edge; | - |
| 1269 | status.traversal = traversal; | - |
| 1270 | status.direction = QPathEdge::Forward; | - |
| 1271 | | - |
| 1272 | path.moveTo(*list.vertex(list.edge(edge)->first)); | - |
| 1273 | | - |
| 1274 | do { | - |
| 1275 | const QPathEdge *ep = list.edge(status.edge); | - |
| 1276 | | - |
| 1277 | addLineTo(path, *list.vertex(ep->vertex(status.direction))); | - |
| 1278 | | - |
| 1279 | if (status.traversal == QPathEdge::LeftTraversal) evaluated: status.traversal == QPathEdge::LeftTraversal| yes Evaluation Count:6 | yes Evaluation Count:268 |
| 6-268 |
| 1280 | ep->flag &= ~16; executed: ep->flag &= ~16;Execution Count:6 | 6 |
| 1281 | else | - |
| 1282 | ep->flag &= ~32; executed: ep->flag &= ~32;Execution Count:268 | 268 |
| 1283 | | - |
| 1284 | status = list.next(status); | - |
| 1285 | } while (status.edge != edge); executed: }Execution Count:274 evaluated: status.edge != edge| yes Evaluation Count:213 | yes Evaluation Count:61 |
| 61-274 |
| 1286 | } executed: }Execution Count:61 | 61 |
| 1287 | | - |
| 1288 | void QWingedEdge::simplify() | - |
| 1289 | { | - |
| 1290 | for (int i = 0; i < edgeCount(); ++i) { evaluated: i < edgeCount()| yes Evaluation Count:466 | yes Evaluation Count:70 |
| 70-466 |
| 1291 | const QPathEdge *ep = edge(i); | - |
| 1292 | | - |
| 1293 | | - |
| 1294 | int flag = 0x3 << 4; | - |
| 1295 | if ((ep->flag & flag) == flag) { evaluated: (ep->flag & flag) == flag| yes Evaluation Count:20 | yes Evaluation Count:446 |
| 20-446 |
| 1296 | removeEdge(i); | - |
| 1297 | | - |
| 1298 | ep->flag &= ~flag; | - |
| 1299 | } executed: }Execution Count:20 | 20 |
| 1300 | } executed: }Execution Count:466 | 466 |
| 1301 | } executed: }Execution Count:70 | 70 |
| 1302 | | - |
| 1303 | QPainterPath QWingedEdge::toPath() const | - |
| 1304 | { | - |
| 1305 | QPainterPath path; | - |
| 1306 | | - |
| 1307 | for (int i = 0; i < edgeCount(); ++i) { evaluated: i < edgeCount()| yes Evaluation Count:466 | yes Evaluation Count:70 |
| 70-466 |
| 1308 | const QPathEdge *ep = edge(i); | - |
| 1309 | | - |
| 1310 | if (ep->flag & 16) { evaluated: ep->flag & 16| yes Evaluation Count:1 | yes Evaluation Count:465 |
| 1-465 |
| 1311 | add(path, *this, i, QPathEdge::LeftTraversal); | - |
| 1312 | } executed: }Execution Count:1 | 1 |
| 1313 | | - |
| 1314 | if (ep->flag & 32) evaluated: ep->flag & 32| yes Evaluation Count:60 | yes Evaluation Count:406 |
| 60-406 |
| 1315 | add(path, *this, i, QPathEdge::RightTraversal); executed: add(path, *this, i, QPathEdge::RightTraversal);Execution Count:60 | 60 |
| 1316 | } executed: }Execution Count:466 | 466 |
| 1317 | | - |
| 1318 | return path; executed: return path;Execution Count:70 | 70 |
| 1319 | } | - |
| 1320 | | - |
| 1321 | bool QPathClipper::intersect() | - |
| 1322 | { | - |
| 1323 | if (subjectPath == clipPath) evaluated: subjectPath == clipPath| yes Evaluation Count:5 | yes Evaluation Count:402 |
| 5-402 |
| 1324 | return true; executed: return true;Execution Count:5 | 5 |
| 1325 | | - |
| 1326 | QRectF r1 = subjectPath.controlPointRect(); | - |
| 1327 | QRectF r2 = clipPath.controlPointRect(); | - |
| 1328 | if (qMax(r1.x(), r2.x()) > qMin(r1.x() + r1.width(), r2.x() + r2.width()) || partially evaluated: qMax(r1.x(), r2.x()) > qMin(r1.x() + r1.width(), r2.x() + r2.width())| no Evaluation Count:0 | yes Evaluation Count:402 |
| 0-402 |
| 1329 | qMax(r1.y(), r2.y()) > qMin(r1.y() + r1.height(), r2.y() + r2.height())) { partially evaluated: qMax(r1.y(), r2.y()) > qMin(r1.y() + r1.height(), r2.y() + r2.height())| no Evaluation Count:0 | yes Evaluation Count:402 |
| 0-402 |
| 1330 | | - |
| 1331 | return false; never executed: return false; | 0 |
| 1332 | } | - |
| 1333 | | - |
| 1334 | bool subjectIsRect = pathToRect(subjectPath); | - |
| 1335 | bool clipIsRect = pathToRect(clipPath); | - |
| 1336 | | - |
| 1337 | if (subjectIsRect && clipIsRect) evaluated: subjectIsRect| yes Evaluation Count:315 | yes Evaluation Count:87 |
evaluated: clipIsRect| yes Evaluation Count:214 | yes Evaluation Count:101 |
| 87-315 |
| 1338 | return true; executed: return true;Execution Count:214 | 214 |
| 1339 | else if (subjectIsRect) evaluated: subjectIsRect| yes Evaluation Count:101 | yes Evaluation Count:87 |
| 87-101 |
| 1340 | return clipPath.intersects(r1); executed: return clipPath.intersects(r1);Execution Count:101 | 101 |
| 1341 | else if (clipIsRect) evaluated: clipIsRect| yes Evaluation Count:3 | yes Evaluation Count:84 |
| 3-84 |
| 1342 | return subjectPath.intersects(r2); executed: return subjectPath.intersects(r2);Execution Count:3 | 3 |
| 1343 | | - |
| 1344 | QPathSegments a(subjectPath.elementCount()); | - |
| 1345 | a.setPath(subjectPath); | - |
| 1346 | QPathSegments b(clipPath.elementCount()); | - |
| 1347 | b.setPath(clipPath); | - |
| 1348 | | - |
| 1349 | QIntersectionFinder finder; | - |
| 1350 | if (finder.hasIntersections(a, b)) evaluated: finder.hasIntersections(a, b)| yes Evaluation Count:54 | yes Evaluation Count:30 |
| 30-54 |
| 1351 | return true; executed: return true;Execution Count:54 | 54 |
| 1352 | | - |
| 1353 | for (int i = 0; i < clipPath.elementCount(); ++i) { evaluated: i < clipPath.elementCount()| yes Evaluation Count:1299 | yes Evaluation Count:25 |
| 25-1299 |
| 1354 | if (clipPath.elementAt(i).type == QPainterPath::MoveToElement) { evaluated: clipPath.elementAt(i).type == QPainterPath::MoveToElement| yes Evaluation Count:76 | yes Evaluation Count:1223 |
| 76-1223 |
| 1355 | const QPointF point = clipPath.elementAt(i); | - |
| 1356 | if (r1.contains(point) && subjectPath.contains(point)) evaluated: r1.contains(point)| yes Evaluation Count:7 | yes Evaluation Count:69 |
evaluated: subjectPath.contains(point)| yes Evaluation Count:5 | yes Evaluation Count:2 |
| 2-69 |
| 1357 | return true; executed: return true;Execution Count:5 | 5 |
| 1358 | } executed: }Execution Count:71 | 71 |
| 1359 | } executed: }Execution Count:1294 | 1294 |
| 1360 | | - |
| 1361 | for (int i = 0; i < subjectPath.elementCount(); ++i) { evaluated: i < subjectPath.elementCount()| yes Evaluation Count:83 | yes Evaluation Count:8 |
| 8-83 |
| 1362 | if (subjectPath.elementAt(i).type == QPainterPath::MoveToElement) { evaluated: subjectPath.elementAt(i).type == QPainterPath::MoveToElement| yes Evaluation Count:27 | yes Evaluation Count:56 |
| 27-56 |
| 1363 | const QPointF point = subjectPath.elementAt(i); | - |
| 1364 | if (r2.contains(point) && clipPath.contains(point)) evaluated: r2.contains(point)| yes Evaluation Count:23 | yes Evaluation Count:4 |
evaluated: clipPath.contains(point)| yes Evaluation Count:17 | yes Evaluation Count:6 |
| 4-23 |
| 1365 | return true; executed: return true;Execution Count:17 | 17 |
| 1366 | } executed: }Execution Count:10 | 10 |
| 1367 | } executed: }Execution Count:66 | 66 |
| 1368 | | - |
| 1369 | return false; executed: return false;Execution Count:8 | 8 |
| 1370 | } | - |
| 1371 | | - |
| 1372 | bool QPathClipper::contains() | - |
| 1373 | { | - |
| 1374 | if (subjectPath == clipPath) evaluated: subjectPath == clipPath| yes Evaluation Count:5 | yes Evaluation Count:40 |
| 5-40 |
| 1375 | return false; executed: return false;Execution Count:5 | 5 |
| 1376 | | - |
| 1377 | QRectF r1 = subjectPath.controlPointRect(); | - |
| 1378 | QRectF r2 = clipPath.controlPointRect(); | - |
| 1379 | if (qMax(r1.x(), r2.x()) > qMin(r1.x() + r1.width(), r2.x() + r2.width()) || partially evaluated: qMax(r1.x(), r2.x()) > qMin(r1.x() + r1.width(), r2.x() + r2.width())| no Evaluation Count:0 | yes Evaluation Count:40 |
| 0-40 |
| 1380 | qMax(r1.y(), r2.y()) > qMin(r1.y() + r1.height(), r2.y() + r2.height())) { partially evaluated: qMax(r1.y(), r2.y()) > qMin(r1.y() + r1.height(), r2.y() + r2.height())| no Evaluation Count:0 | yes Evaluation Count:40 |
| 0-40 |
| 1381 | | - |
| 1382 | return false; never executed: return false; | 0 |
| 1383 | } | - |
| 1384 | | - |
| 1385 | bool clipIsRect = pathToRect(clipPath); | - |
| 1386 | if (clipIsRect) evaluated: clipIsRect| yes Evaluation Count:3 | yes Evaluation Count:37 |
| 3-37 |
| 1387 | return subjectPath.contains(r2); executed: return subjectPath.contains(r2);Execution Count:3 | 3 |
| 1388 | | - |
| 1389 | QPathSegments a(subjectPath.elementCount()); | - |
| 1390 | a.setPath(subjectPath); | - |
| 1391 | QPathSegments b(clipPath.elementCount()); | - |
| 1392 | b.setPath(clipPath); | - |
| 1393 | | - |
| 1394 | QIntersectionFinder finder; | - |
| 1395 | if (finder.hasIntersections(a, b)) evaluated: finder.hasIntersections(a, b)| yes Evaluation Count:24 | yes Evaluation Count:13 |
| 13-24 |
| 1396 | return false; executed: return false;Execution Count:24 | 24 |
| 1397 | | - |
| 1398 | for (int i = 0; i < clipPath.elementCount(); ++i) { evaluated: i < clipPath.elementCount()| yes Evaluation Count:126 | yes Evaluation Count:10 |
| 10-126 |
| 1399 | if (clipPath.elementAt(i).type == QPainterPath::MoveToElement) { evaluated: clipPath.elementAt(i).type == QPainterPath::MoveToElement| yes Evaluation Count:18 | yes Evaluation Count:108 |
| 18-108 |
| 1400 | const QPointF point = clipPath.elementAt(i); | - |
| 1401 | if (!r1.contains(point) || !subjectPath.contains(point)) evaluated: !r1.contains(point)| yes Evaluation Count:1 | yes Evaluation Count:17 |
evaluated: !subjectPath.contains(point)| yes Evaluation Count:2 | yes Evaluation Count:15 |
| 1-17 |
| 1402 | return false; executed: return false;Execution Count:3 | 3 |
| 1403 | } executed: }Execution Count:15 | 15 |
| 1404 | } executed: }Execution Count:123 | 123 |
| 1405 | | - |
| 1406 | return true; executed: return true;Execution Count:10 | 10 |
| 1407 | } | - |
| 1408 | | - |
| 1409 | QPathClipper::QPathClipper(const QPainterPath &subject, | - |
| 1410 | const QPainterPath &clip) | - |
| 1411 | : subjectPath(subject) | - |
| 1412 | , clipPath(clip) | - |
| 1413 | { | - |
| 1414 | aMask = subjectPath.fillRule() == Qt::WindingFill ? ~0x0 : 0x1; evaluated: subjectPath.fillRule() == Qt::WindingFill| yes Evaluation Count:119 | yes Evaluation Count:535 |
| 119-535 |
| 1415 | bMask = clipPath.fillRule() == Qt::WindingFill ? ~0x0 : 0x1; evaluated: clipPath.fillRule() == Qt::WindingFill| yes Evaluation Count:263 | yes Evaluation Count:391 |
| 263-391 |
| 1416 | } executed: }Execution Count:654 | 654 |
| 1417 | | - |
| 1418 | template <typename Iterator, typename Equality> | - |
| 1419 | Iterator qRemoveDuplicates(Iterator begin, Iterator end, Equality eq) | - |
| 1420 | { | - |
| 1421 | if (begin == end) partially evaluated: begin == end| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 1422 | return end; never executed: return end; | 0 |
| 1423 | | - |
| 1424 | Iterator last = begin; | - |
| 1425 | ++begin; | - |
| 1426 | Iterator insert = begin; | - |
| 1427 | for (Iterator it = begin; it != end; ++it) { evaluated: it != end| yes Evaluation Count:360 | yes Evaluation Count:70 |
| 70-360 |
| 1428 | if (!eq(*it, *last)) { evaluated: !eq(*it, *last)| yes Evaluation Count:96 | yes Evaluation Count:264 |
| 96-264 |
| 1429 | *insert++ = *it; | - |
| 1430 | last = it; | - |
| 1431 | } executed: }Execution Count:96 | 96 |
| 1432 | } executed: }Execution Count:360 | 360 |
| 1433 | | - |
| 1434 | return insert; executed: return insert;Execution Count:70 | 70 |
| 1435 | } | - |
| 1436 | | - |
| 1437 | static void clear(QWingedEdge& list, int edge, QPathEdge::Traversal traversal) | - |
| 1438 | { | - |
| 1439 | QWingedEdge::TraversalStatus status; | - |
| 1440 | status.edge = edge; | - |
| 1441 | status.traversal = traversal; | - |
| 1442 | status.direction = QPathEdge::Forward; | - |
| 1443 | | - |
| 1444 | do { | - |
| 1445 | if (status.traversal == QPathEdge::LeftTraversal) evaluated: status.traversal == QPathEdge::LeftTraversal| yes Evaluation Count:440 | yes Evaluation Count:178 |
| 178-440 |
| 1446 | list.edge(status.edge)->flag |= 1; executed: list.edge(status.edge)->flag |= 1;Execution Count:440 | 440 |
| 1447 | else | - |
| 1448 | list.edge(status.edge)->flag |= 2; executed: list.edge(status.edge)->flag |= 2;Execution Count:178 | 178 |
| 1449 | | - |
| 1450 | status = list.next(status); | - |
| 1451 | } while (status.edge != edge); executed: }Execution Count:618 evaluated: status.edge != edge| yes Evaluation Count:507 | yes Evaluation Count:111 |
| 111-618 |
| 1452 | } executed: }Execution Count:111 | 111 |
| 1453 | | - |
| 1454 | template <typename InputIterator> | - |
| 1455 | InputIterator qFuzzyFind(InputIterator first, InputIterator last, qreal val) | - |
| 1456 | { | - |
| 1457 | while (first != last && !::qFuzzyCompare(qreal(*first), qreal(val))) partially evaluated: first != last| yes Evaluation Count:299 | no Evaluation Count:0 |
evaluated: !::qFuzzyCompare(qreal(*first), qreal(val))| yes Evaluation Count:127 | yes Evaluation Count:172 |
| 0-299 |
| 1458 | ++first; executed: ++first;Execution Count:127 | 127 |
| 1459 | return first; executed: return first;Execution Count:172 | 172 |
| 1460 | } | - |
| 1461 | | - |
| 1462 | static bool fuzzyCompare(qreal a, qreal b) | - |
| 1463 | { | - |
| 1464 | return qFuzzyCompare(a, b); executed: return qFuzzyCompare(a, b);Execution Count:360 | 360 |
| 1465 | } | - |
| 1466 | | - |
| 1467 | bool QPathClipper::pathToRect(const QPainterPath &path, QRectF *rect) | - |
| 1468 | { | - |
| 1469 | if (path.elementCount() != 5) evaluated: path.elementCount() != 5| yes Evaluation Count:333 | yes Evaluation Count:705 |
| 333-705 |
| 1470 | return false; executed: return false;Execution Count:333 | 333 |
| 1471 | | - |
| 1472 | const bool mightBeRect = path.elementAt(0).isMoveTo() partially evaluated: path.elementAt(0).isMoveTo()| yes Evaluation Count:705 | no Evaluation Count:0 |
| 0-705 |
| 1473 | && path.elementAt(1).isLineTo() partially evaluated: path.elementAt(1).isLineTo()| yes Evaluation Count:705 | no Evaluation Count:0 |
| 0-705 |
| 1474 | && path.elementAt(2).isLineTo() partially evaluated: path.elementAt(2).isLineTo()| yes Evaluation Count:705 | no Evaluation Count:0 |
| 0-705 |
| 1475 | && path.elementAt(3).isLineTo() partially evaluated: path.elementAt(3).isLineTo()| yes Evaluation Count:705 | no Evaluation Count:0 |
| 0-705 |
| 1476 | && path.elementAt(4).isLineTo(); partially evaluated: path.elementAt(4).isLineTo()| yes Evaluation Count:705 | no Evaluation Count:0 |
| 0-705 |
| 1477 | | - |
| 1478 | if (!mightBeRect) partially evaluated: !mightBeRect| no Evaluation Count:0 | yes Evaluation Count:705 |
| 0-705 |
| 1479 | return false; never executed: return false; | 0 |
| 1480 | | - |
| 1481 | const qreal x1 = path.elementAt(0).x; | - |
| 1482 | const qreal y1 = path.elementAt(0).y; | - |
| 1483 | | - |
| 1484 | const qreal x2 = path.elementAt(1).x; | - |
| 1485 | const qreal y2 = path.elementAt(2).y; | - |
| 1486 | | - |
| 1487 | if (path.elementAt(1).y != y1) evaluated: path.elementAt(1).y != y1| yes Evaluation Count:20 | yes Evaluation Count:685 |
| 20-685 |
| 1488 | return false; executed: return false;Execution Count:20 | 20 |
| 1489 | | - |
| 1490 | if (path.elementAt(2).x != x2) partially evaluated: path.elementAt(2).x != x2| no Evaluation Count:0 | yes Evaluation Count:685 |
| 0-685 |
| 1491 | return false; never executed: return false; | 0 |
| 1492 | | - |
| 1493 | if (path.elementAt(3).x != x1 || path.elementAt(3).y != y2) partially evaluated: path.elementAt(3).x != x1| no Evaluation Count:0 | yes Evaluation Count:685 |
partially evaluated: path.elementAt(3).y != y2| no Evaluation Count:0 | yes Evaluation Count:685 |
| 0-685 |
| 1494 | return false; never executed: return false; | 0 |
| 1495 | | - |
| 1496 | if (path.elementAt(4).x != x1 || path.elementAt(4).y != y1) partially evaluated: path.elementAt(4).x != x1| no Evaluation Count:0 | yes Evaluation Count:685 |
partially evaluated: path.elementAt(4).y != y1| no Evaluation Count:0 | yes Evaluation Count:685 |
| 0-685 |
| 1497 | return false; never executed: return false; | 0 |
| 1498 | | - |
| 1499 | if (rect) partially evaluated: rect| no Evaluation Count:0 | yes Evaluation Count:685 |
| 0-685 |
| 1500 | rect->setCoords(x1, y1, x2, y2); never executed: rect->setCoords(x1, y1, x2, y2); | 0 |
| 1501 | | - |
| 1502 | return true; executed: return true;Execution Count:685 | 685 |
| 1503 | } | - |
| 1504 | | - |
| 1505 | | - |
| 1506 | QPainterPath QPathClipper::clip(Operation operation) | - |
| 1507 | { | - |
| 1508 | op = operation; | - |
| 1509 | | - |
| 1510 | if (op != Simplify) { evaluated: op != Simplify| yes Evaluation Count:148 | yes Evaluation Count:54 |
| 54-148 |
| 1511 | if (subjectPath == clipPath) evaluated: subjectPath == clipPath| yes Evaluation Count:57 | yes Evaluation Count:91 |
| 57-91 |
| 1512 | return op == BoolSub ? QPainterPath() : subjectPath; executed: return op == BoolSub ? QPainterPath() : subjectPath;Execution Count:57 | 57 |
| 1513 | | - |
| 1514 | bool subjectIsRect = pathToRect(subjectPath, 0); | - |
| 1515 | bool clipIsRect = pathToRect(clipPath, 0); | - |
| 1516 | | - |
| 1517 | const QRectF clipBounds = clipPath.boundingRect(); | - |
| 1518 | const QRectF subjectBounds = subjectPath.boundingRect(); | - |
| 1519 | | - |
| 1520 | if (!clipBounds.intersects(subjectBounds)) { evaluated: !clipBounds.intersects(subjectBounds)| yes Evaluation Count:6 | yes Evaluation Count:85 |
| 6-85 |
| 1521 | switch (op) { | - |
| 1522 | case BoolSub: | - |
| 1523 | return subjectPath; never executed: return subjectPath; | 0 |
| 1524 | case BoolAnd: | - |
| 1525 | return QPainterPath(); never executed: return QPainterPath(); | 0 |
| 1526 | case BoolOr: { | - |
| 1527 | QPainterPath result = subjectPath; | - |
| 1528 | if (result.fillRule() == clipPath.fillRule()) { partially evaluated: result.fillRule() == clipPath.fillRule()| yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-6 |
| 1529 | result.addPath(clipPath); | - |
| 1530 | } else if (result.fillRule() == Qt::WindingFill) { executed: }Execution Count:6 never evaluated: result.fillRule() == Qt::WindingFill | 0-6 |
| 1531 | result = result.simplified(); | - |
| 1532 | result.addPath(clipPath); | - |
| 1533 | } else { | 0 |
| 1534 | result.addPath(clipPath.simplified()); | - |
| 1535 | } | 0 |
| 1536 | return result; executed: return result;Execution Count:6 | 6 |
| 1537 | } | - |
| 1538 | default: | - |
| 1539 | break; | 0 |
| 1540 | } | - |
| 1541 | } | 0 |
| 1542 | | - |
| 1543 | if (clipBounds.contains(subjectBounds)) { evaluated: clipBounds.contains(subjectBounds)| yes Evaluation Count:19 | yes Evaluation Count:66 |
| 19-66 |
| 1544 | if (clipIsRect) { evaluated: clipIsRect| yes Evaluation Count:7 | yes Evaluation Count:12 |
| 7-12 |
| 1545 | switch (op) { | - |
| 1546 | case BoolSub: | - |
| 1547 | return QPainterPath(); executed: return QPainterPath();Execution Count:5 | 5 |
| 1548 | case BoolAnd: | - |
| 1549 | return subjectPath; never executed: return subjectPath; | 0 |
| 1550 | case BoolOr: | - |
| 1551 | return clipPath; executed: return clipPath;Execution Count:2 | 2 |
| 1552 | default: | - |
| 1553 | break; | 0 |
| 1554 | } | - |
| 1555 | } | 0 |
| 1556 | } else if (subjectBounds.contains(clipBounds)) { executed: }Execution Count:12 evaluated: subjectBounds.contains(clipBounds)| yes Evaluation Count:54 | yes Evaluation Count:12 |
| 12-54 |
| 1557 | if (subjectIsRect) { partially evaluated: subjectIsRect| yes Evaluation Count:54 | no Evaluation Count:0 |
| 0-54 |
| 1558 | switch (op) { | - |
| 1559 | case BoolSub: | - |
| 1560 | if (clipPath.fillRule() == Qt::OddEvenFill) { evaluated: clipPath.fillRule() == Qt::OddEvenFill| yes Evaluation Count:4 | yes Evaluation Count:50 |
| 4-50 |
| 1561 | QPainterPath result = clipPath; | - |
| 1562 | result.addRect(subjectBounds); | - |
| 1563 | return result; executed: return result;Execution Count:4 | 4 |
| 1564 | } else { | - |
| 1565 | QPainterPath result = clipPath.simplified(); | - |
| 1566 | result.addRect(subjectBounds); | - |
| 1567 | return result; executed: return result;Execution Count:50 | 50 |
| 1568 | } | - |
| 1569 | case BoolAnd: | - |
| 1570 | return clipPath; never executed: return clipPath; | 0 |
| 1571 | case BoolOr: | - |
| 1572 | return subjectPath; never executed: return subjectPath; | 0 |
| 1573 | default: | - |
| 1574 | break; | 0 |
| 1575 | } | - |
| 1576 | } | 0 |
| 1577 | } | 0 |
| 1578 | | - |
| 1579 | if (op == BoolAnd) { evaluated: op == BoolAnd| yes Evaluation Count:8 | yes Evaluation Count:16 |
| 8-16 |
| 1580 | if (subjectIsRect) partially evaluated: subjectIsRect| yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
| 1581 | return intersect(clipPath, subjectBounds); executed: return intersect(clipPath, subjectBounds);Execution Count:8 | 8 |
| 1582 | else if (clipIsRect) never evaluated: clipIsRect | 0 |
| 1583 | return intersect(subjectPath, clipBounds); never executed: return intersect(subjectPath, clipBounds); | 0 |
| 1584 | } | - |
| 1585 | } executed: }Execution Count:16 | 16 |
| 1586 | | - |
| 1587 | QWingedEdge list(subjectPath, clipPath); | - |
| 1588 | | - |
| 1589 | doClip(list, ClipMode); | - |
| 1590 | | - |
| 1591 | QPainterPath path = list.toPath(); | - |
| 1592 | return path; executed: return path;Execution Count:70 | 70 |
| 1593 | } | - |
| 1594 | | - |
| 1595 | bool QPathClipper::doClip(QWingedEdge &list, ClipperMode mode) | - |
| 1596 | { | - |
| 1597 | QVector<qreal> y_coords; | - |
| 1598 | y_coords.reserve(list.vertexCount()); | - |
| 1599 | for (int i = 0; i < list.vertexCount(); ++i) evaluated: i < list.vertexCount()| yes Evaluation Count:430 | yes Evaluation Count:70 |
| 70-430 |
| 1600 | y_coords << list.vertex(i)->y; executed: y_coords << list.vertex(i)->y;Execution Count:430 | 430 |
| 1601 | | - |
| 1602 | qSort(y_coords.begin(), y_coords.end()); | - |
| 1603 | y_coords.resize(qRemoveDuplicates(y_coords.begin(), y_coords.end(), fuzzyCompare) - y_coords.begin()); | - |
| 1604 | bool found; | - |
| 1605 | do { | - |
| 1606 | found = false; | - |
| 1607 | int index = 0; | - |
| 1608 | qreal maxHeight = 0; | - |
| 1609 | for (int i = 0; i < list.edgeCount(); ++i) { evaluated: i < list.edgeCount()| yes Evaluation Count:1204 | yes Evaluation Count:156 |
| 156-1204 |
| 1610 | QPathEdge *edge = list.edge(i); | - |
| 1611 | | - |
| 1612 | | - |
| 1613 | if ((edge->flag & 0x3) == 0x3) evaluated: (edge->flag & 0x3) == 0x3| yes Evaluation Count:600 | yes Evaluation Count:604 |
| 600-604 |
| 1614 | continue; executed: continue;Execution Count:600 | 600 |
| 1615 | | - |
| 1616 | QPathVertex *a = list.vertex(edge->first); | - |
| 1617 | QPathVertex *b = list.vertex(edge->second); | - |
| 1618 | | - |
| 1619 | if (qFuzzyCompare(a->y, b->y)) evaluated: qFuzzyCompare(a->y, b->y)| yes Evaluation Count:320 | yes Evaluation Count:284 |
| 284-320 |
| 1620 | continue; executed: continue;Execution Count:320 | 320 |
| 1621 | | - |
| 1622 | found = true; | - |
| 1623 | | - |
| 1624 | qreal height = qAbs(a->y - b->y); | - |
| 1625 | if (height > maxHeight) { evaluated: height > maxHeight| yes Evaluation Count:100 | yes Evaluation Count:184 |
| 100-184 |
| 1626 | index = i; | - |
| 1627 | maxHeight = height; | - |
| 1628 | } executed: }Execution Count:100 | 100 |
| 1629 | } executed: }Execution Count:284 | 284 |
| 1630 | | - |
| 1631 | if (found) { evaluated: found| yes Evaluation Count:86 | yes Evaluation Count:70 |
| 70-86 |
| 1632 | QPathEdge *edge = list.edge(index); | - |
| 1633 | | - |
| 1634 | QPathVertex *a = list.vertex(edge->first); | - |
| 1635 | QPathVertex *b = list.vertex(edge->second); | - |
| 1636 | | - |
| 1637 | | - |
| 1638 | const int first = qFuzzyFind(y_coords.begin(), y_coords.end(), qMin(a->y, b->y)) - y_coords.begin(); | - |
| 1639 | const int last = qFuzzyFind(y_coords.begin() + first, y_coords.end(), qMax(a->y, b->y)) - y_coords.begin(); | - |
| 1640 | | - |
| 1641 | qt_noop(); | - |
| 1642 | qt_noop(); | - |
| 1643 | | - |
| 1644 | qreal bestY = 0.5 * (y_coords[first] + y_coords[first+1]); | - |
| 1645 | qreal biggestGap = y_coords[first+1] - y_coords[first]; | - |
| 1646 | | - |
| 1647 | for (int i = first + 1; i < last; ++i) { evaluated: i < last| yes Evaluation Count:16 | yes Evaluation Count:86 |
| 16-86 |
| 1648 | qreal gap = y_coords[i+1] - y_coords[i]; | - |
| 1649 | | - |
| 1650 | if (gap > biggestGap) { evaluated: gap > biggestGap| yes Evaluation Count:2 | yes Evaluation Count:14 |
| 2-14 |
| 1651 | bestY = 0.5 * (y_coords[i] + y_coords[i+1]); | - |
| 1652 | biggestGap = gap; | - |
| 1653 | } executed: }Execution Count:2 | 2 |
| 1654 | } executed: }Execution Count:16 | 16 |
| 1655 | | - |
| 1656 | | - |
| 1657 | | - |
| 1658 | | - |
| 1659 | | - |
| 1660 | if (handleCrossingEdges(list, bestY, mode) && mode == CheckMode) partially evaluated: handleCrossingEdges(list, bestY, mode)| no Evaluation Count:0 | yes Evaluation Count:86 |
never evaluated: mode == CheckMode | 0-86 |
| 1661 | return true; never executed: return true; | 0 |
| 1662 | | - |
| 1663 | edge->flag |= 0x3; | - |
| 1664 | } executed: }Execution Count:86 | 86 |
| 1665 | } while (found); executed: }Execution Count:156 evaluated: found| yes Evaluation Count:86 | yes Evaluation Count:70 |
| 70-156 |
| 1666 | | - |
| 1667 | if (mode == ClipMode) partially evaluated: mode == ClipMode| yes Evaluation Count:70 | no Evaluation Count:0 |
| 0-70 |
| 1668 | list.simplify(); executed: list.simplify();Execution Count:70 | 70 |
| 1669 | | - |
| 1670 | return false; executed: return false;Execution Count:70 | 70 |
| 1671 | } | - |
| 1672 | | - |
| 1673 | static void traverse(QWingedEdge &list, int edge, QPathEdge::Traversal traversal) | - |
| 1674 | { | - |
| 1675 | QWingedEdge::TraversalStatus status; | - |
| 1676 | status.edge = edge; | - |
| 1677 | status.traversal = traversal; | - |
| 1678 | status.direction = QPathEdge::Forward; | - |
| 1679 | | - |
| 1680 | do { | - |
| 1681 | int flag = status.traversal == QPathEdge::LeftTraversal ? 1 : 2; evaluated: status.traversal == QPathEdge::LeftTraversal| yes Evaluation Count:26 | yes Evaluation Count:288 |
| 26-288 |
| 1682 | | - |
| 1683 | QPathEdge *ep = list.edge(status.edge); | - |
| 1684 | | - |
| 1685 | ep->flag |= (flag | (flag << 4)); | - |
| 1686 | | - |
| 1687 | | - |
| 1688 | | - |
| 1689 | | - |
| 1690 | | - |
| 1691 | status = list.next(status); | - |
| 1692 | } while (status.edge != edge); executed: }Execution Count:314 evaluated: status.edge != edge| yes Evaluation Count:241 | yes Evaluation Count:73 |
| 73-314 |
| 1693 | } executed: }Execution Count:73 | 73 |
| 1694 | | - |
| 1695 | struct QCrossingEdge | - |
| 1696 | { | - |
| 1697 | int edge; | - |
| 1698 | qreal x; | - |
| 1699 | | - |
| 1700 | bool operator<(const QCrossingEdge &edge) const | - |
| 1701 | { | - |
| 1702 | return x < edge.x; executed: return x < edge.x;Execution Count:224 | 224 |
| 1703 | } | - |
| 1704 | }; | - |
| 1705 | | - |
| 1706 | static bool bool_op(bool a, bool b, QPathClipper::Operation op) | - |
| 1707 | { | - |
| 1708 | switch (op) { | - |
| 1709 | case QPathClipper::BoolAnd: | - |
| 1710 | return a && b; never executed: return a && b; | 0 |
| 1711 | case QPathClipper::BoolOr: | - |
| 1712 | case QPathClipper::Simplify: | - |
| 1713 | return a || b; executed: return a || b;Execution Count:76 | 76 |
| 1714 | case QPathClipper::BoolSub: | - |
| 1715 | return a && !b; executed: return a && !b;Execution Count:56 | 56 |
| 1716 | default: | - |
| 1717 | qt_noop(); | - |
| 1718 | return false; never executed: return false; | 0 |
| 1719 | } | - |
| 1720 | } | 0 |
| 1721 | | - |
| 1722 | bool QWingedEdge::isInside(qreal x, qreal y) const | - |
| 1723 | { | - |
| 1724 | int winding = 0; | - |
| 1725 | for (int i = 0; i < edgeCount(); ++i) { never evaluated: i < edgeCount() | 0 |
| 1726 | const QPathEdge *ep = edge(i); | - |
| 1727 | | - |
| 1728 | | - |
| 1729 | int w = ((ep->flag >> 4) ^ (ep->flag >> 5)) & 1; | - |
| 1730 | | - |
| 1731 | if (!w) | 0 |
| 1732 | continue; never executed: continue; | 0 |
| 1733 | | - |
| 1734 | QPointF a = *vertex(ep->first); | - |
| 1735 | QPointF b = *vertex(ep->second); | - |
| 1736 | | - |
| 1737 | if ((a.y() < y && b.y() > y) || (a.y() > y && b.y() < y)) { never evaluated: a.y() < y never evaluated: b.y() > y never evaluated: a.y() > y never evaluated: b.y() < y | 0 |
| 1738 | qreal intersectionX = a.x() + (b.x() - a.x()) * (y - a.y()) / (b.y() - a.y()); | - |
| 1739 | | - |
| 1740 | if (intersectionX > x) never evaluated: intersectionX > x | 0 |
| 1741 | winding += w; never executed: winding += w; | 0 |
| 1742 | } | 0 |
| 1743 | } | 0 |
| 1744 | | - |
| 1745 | return winding & 1; never executed: return winding & 1; | 0 |
| 1746 | } | - |
| 1747 | | - |
| 1748 | static QVector<QCrossingEdge> findCrossings(const QWingedEdge &list, qreal y) | - |
| 1749 | { | - |
| 1750 | QVector<QCrossingEdge> crossings; | - |
| 1751 | for (int i = 0; i < list.edgeCount(); ++i) { evaluated: i < list.edgeCount()| yes Evaluation Count:738 | yes Evaluation Count:86 |
| 86-738 |
| 1752 | const QPathEdge *edge = list.edge(i); | - |
| 1753 | QPointF a = *list.vertex(edge->first); | - |
| 1754 | QPointF b = *list.vertex(edge->second); | - |
| 1755 | | - |
| 1756 | if ((a.y() < y && b.y() > y) || (a.y() > y && b.y() < y)) { evaluated: a.y() < y| yes Evaluation Count:345 | yes Evaluation Count:393 |
evaluated: b.y() > y| yes Evaluation Count:109 | yes Evaluation Count:236 |
evaluated: a.y() > y| yes Evaluation Count:393 | yes Evaluation Count:236 |
evaluated: b.y() < y| yes Evaluation Count:109 | yes Evaluation Count:284 |
| 109-393 |
| 1757 | const qreal intersection = a.x() + (b.x() - a.x()) * (y - a.y()) / (b.y() - a.y()); | - |
| 1758 | const QCrossingEdge edge = { i, intersection }; | - |
| 1759 | crossings << edge; | - |
| 1760 | } executed: }Execution Count:218 | 218 |
| 1761 | } executed: }Execution Count:738 | 738 |
| 1762 | return crossings; executed: return crossings;Execution Count:86 | 86 |
| 1763 | } | - |
| 1764 | | - |
| 1765 | bool QPathClipper::handleCrossingEdges(QWingedEdge &list, qreal y, ClipperMode mode) | - |
| 1766 | { | - |
| 1767 | QVector<QCrossingEdge> crossings = findCrossings(list, y); | - |
| 1768 | | - |
| 1769 | qt_noop(); | - |
| 1770 | qSort(crossings.begin(), crossings.end()); | - |
| 1771 | | - |
| 1772 | int windingA = 0; | - |
| 1773 | int windingB = 0; | - |
| 1774 | | - |
| 1775 | int windingD = 0; | - |
| 1776 | | - |
| 1777 | | - |
| 1778 | | - |
| 1779 | | - |
| 1780 | for (int i = 0; i < crossings.size() - 1; ++i) { evaluated: i < crossings.size() - 1| yes Evaluation Count:132 | yes Evaluation Count:86 |
| 86-132 |
| 1781 | int ei = crossings.at(i).edge; | - |
| 1782 | const QPathEdge *edge = list.edge(ei); | - |
| 1783 | | - |
| 1784 | windingA += edge->windingA; | - |
| 1785 | windingB += edge->windingB; | - |
| 1786 | | - |
| 1787 | const bool hasLeft = (edge->flag >> 4) & 1; | - |
| 1788 | const bool hasRight = (edge->flag >> 4) & 2; | - |
| 1789 | | - |
| 1790 | windingD += hasLeft ^ hasRight; | - |
| 1791 | | - |
| 1792 | const bool inA = (windingA & aMask) != 0; | - |
| 1793 | const bool inB = (windingB & bMask) != 0; | - |
| 1794 | const bool inD = (windingD & 0x1) != 0; | - |
| 1795 | | - |
| 1796 | const bool inside = bool_op(inA, inB, op); | - |
| 1797 | const bool add = inD ^ inside; | - |
| 1798 | | - |
| 1799 | | - |
| 1800 | | - |
| 1801 | | - |
| 1802 | | - |
| 1803 | if (add) { evaluated: add| yes Evaluation Count:73 | yes Evaluation Count:59 |
| 59-73 |
| 1804 | if (mode == CheckMode) partially evaluated: mode == CheckMode| no Evaluation Count:0 | yes Evaluation Count:73 |
| 0-73 |
| 1805 | return true; never executed: return true; | 0 |
| 1806 | | - |
| 1807 | qreal y0 = list.vertex(edge->first)->y; | - |
| 1808 | qreal y1 = list.vertex(edge->second)->y; | - |
| 1809 | | - |
| 1810 | if (y0 < y1) { evaluated: y0 < y1| yes Evaluation Count:6 | yes Evaluation Count:67 |
| 6-67 |
| 1811 | if (!(edge->flag & 1)) partially evaluated: !(edge->flag & 1)| yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-6 |
| 1812 | traverse(list, ei, QPathEdge::LeftTraversal); executed: traverse(list, ei, QPathEdge::LeftTraversal);Execution Count:6 | 6 |
| 1813 | | - |
| 1814 | if (!(edge->flag & 2)) partially evaluated: !(edge->flag & 2)| no Evaluation Count:0 | yes Evaluation Count:6 |
| 0-6 |
| 1815 | clear(list, ei, QPathEdge::RightTraversal); never executed: clear(list, ei, QPathEdge::RightTraversal); | 0 |
| 1816 | } else { executed: }Execution Count:6 | 6 |
| 1817 | if (!(edge->flag & 1)) evaluated: !(edge->flag & 1)| yes Evaluation Count:60 | yes Evaluation Count:7 |
| 7-60 |
| 1818 | clear(list, ei, QPathEdge::LeftTraversal); executed: clear(list, ei, QPathEdge::LeftTraversal);Execution Count:60 | 60 |
| 1819 | | - |
| 1820 | if (!(edge->flag & 2)) partially evaluated: !(edge->flag & 2)| yes Evaluation Count:67 | no Evaluation Count:0 |
| 0-67 |
| 1821 | traverse(list, ei, QPathEdge::RightTraversal); executed: traverse(list, ei, QPathEdge::RightTraversal);Execution Count:67 | 67 |
| 1822 | } executed: }Execution Count:67 | 67 |
| 1823 | | - |
| 1824 | ++windingD; | - |
| 1825 | } else { executed: }Execution Count:73 | 73 |
| 1826 | if (!(edge->flag & 1)) evaluated: !(edge->flag & 1)| yes Evaluation Count:20 | yes Evaluation Count:39 |
| 20-39 |
| 1827 | clear(list, ei, QPathEdge::LeftTraversal); executed: clear(list, ei, QPathEdge::LeftTraversal);Execution Count:20 | 20 |
| 1828 | | - |
| 1829 | if (!(edge->flag & 2)) evaluated: !(edge->flag & 2)| yes Evaluation Count:31 | yes Evaluation Count:28 |
| 28-31 |
| 1830 | clear(list, ei, QPathEdge::RightTraversal); executed: clear(list, ei, QPathEdge::RightTraversal);Execution Count:31 | 31 |
| 1831 | } executed: }Execution Count:59 | 59 |
| 1832 | } | - |
| 1833 | | - |
| 1834 | return false; executed: return false;Execution Count:86 | 86 |
| 1835 | } | - |
| 1836 | | - |
| 1837 | namespace { | - |
| 1838 | | - |
| 1839 | QList<QPainterPath> toSubpaths(const QPainterPath &path) | - |
| 1840 | { | - |
| 1841 | | - |
| 1842 | QList<QPainterPath> subpaths; | - |
| 1843 | if (path.isEmpty()) partially evaluated: path.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-8 |
| 1844 | return subpaths; never executed: return subpaths; | 0 |
| 1845 | | - |
| 1846 | QPainterPath current; | - |
| 1847 | for (int i = 0; i < path.elementCount(); ++i) { evaluated: i < path.elementCount()| yes Evaluation Count:128 | yes Evaluation Count:8 |
| 8-128 |
| 1848 | const QPainterPath::Element &e = path.elementAt(i); | - |
| 1849 | switch (e.type) { | - |
| 1850 | case QPainterPath::MoveToElement: | - |
| 1851 | if (current.elementCount() > 1) evaluated: current.elementCount() > 1| yes Evaluation Count:8 | yes Evaluation Count:8 |
| 8 |
| 1852 | subpaths += current; executed: subpaths += current;Execution Count:8 | 8 |
| 1853 | current = QPainterPath(); | - |
| 1854 | current.moveTo(e); | - |
| 1855 | break; executed: break;Execution Count:16 | 16 |
| 1856 | case QPainterPath::LineToElement: | - |
| 1857 | current.lineTo(e); | - |
| 1858 | break; executed: break;Execution Count:112 | 112 |
| 1859 | case QPainterPath::CurveToElement: { | - |
| 1860 | current.cubicTo(e, path.elementAt(i + 1), path.elementAt(i + 2)); | - |
| 1861 | i+=2; | - |
| 1862 | break; | 0 |
| 1863 | } | - |
| 1864 | case QPainterPath::CurveToDataElement: | - |
| 1865 | qt_noop(); | - |
| 1866 | break; | 0 |
| 1867 | } | - |
| 1868 | } executed: }Execution Count:128 | 128 |
| 1869 | | - |
| 1870 | if (current.elementCount() > 1) partially evaluated: current.elementCount() > 1| yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
| 1871 | subpaths << current; executed: subpaths << current;Execution Count:8 | 8 |
| 1872 | | - |
| 1873 | return subpaths; executed: return subpaths;Execution Count:8 | 8 |
| 1874 | } | - |
| 1875 | | - |
| 1876 | enum Edge | - |
| 1877 | { | - |
| 1878 | Left, Top, Right, Bottom | - |
| 1879 | }; | - |
| 1880 | | - |
| 1881 | static bool isVertical(Edge edge) | - |
| 1882 | { | - |
| 1883 | return edge == Left || edge == Right; never executed: return edge == Left || edge == Right; | 0 |
| 1884 | } | - |
| 1885 | | - |
| 1886 | template <Edge edge> | - |
| 1887 | bool compare(const QPointF &p, qreal t) | - |
| 1888 | { | - |
| 1889 | switch (edge) | - |
| 1890 | { | - |
| 1891 | case Left: | - |
| 1892 | return p.x() < t; executed: return p.x() < t;Execution Count:96 | 96 |
| 1893 | case Right: | - |
| 1894 | return p.x() > t; executed: return p.x() > t;Execution Count:200 | 200 |
| 1895 | case Top: | - |
| 1896 | return p.y() < t; executed: return p.y() < t;Execution Count:48 | 48 |
| 1897 | default: | - |
| 1898 | return p.y() > t; executed: return p.y() > t;Execution Count:152 | 152 |
| 1899 | } | - |
| 1900 | } | 0 |
| 1901 | | - |
| 1902 | template <Edge edge> | - |
| 1903 | QPointF intersectLine(const QPointF &a, const QPointF &b, qreal t) | - |
| 1904 | { | - |
| 1905 | QLineF line(a, b); | - |
| 1906 | switch (edge) { | - |
| 1907 | case Left: | - |
| 1908 | case Right: | - |
| 1909 | return line.pointAt((t - a.x()) / (b.x() - a.x())); executed: return line.pointAt((t - a.x()) / (b.x() - a.x()));Execution Count:44 | 44 |
| 1910 | default: | - |
| 1911 | return line.pointAt((t - a.y()) / (b.y() - a.y())); executed: return line.pointAt((t - a.y()) / (b.y() - a.y()));Execution Count:44 | 44 |
| 1912 | } | - |
| 1913 | } | 0 |
| 1914 | | - |
| 1915 | void addLine(QPainterPath &path, const QLineF &line) | - |
| 1916 | { | - |
| 1917 | if (path.elementCount() > 0) evaluated: path.elementCount() > 0| yes Evaluation Count:118 | yes Evaluation Count:44 |
| 44-118 |
| 1918 | path.lineTo(line.p1()); executed: path.lineTo(line.p1());Execution Count:118 | 118 |
| 1919 | else | - |
| 1920 | path.moveTo(line.p1()); executed: path.moveTo(line.p1());Execution Count:44 | 44 |
| 1921 | | - |
| 1922 | path.lineTo(line.p2()); | - |
| 1923 | } executed: }Execution Count:162 | 162 |
| 1924 | | - |
| 1925 | template <Edge edge> | - |
| 1926 | void clipLine(const QPointF &a, const QPointF &b, qreal t, QPainterPath &result) | - |
| 1927 | { | - |
| 1928 | bool outA = compare<edge>(a, t); | - |
| 1929 | bool outB = compare<edge>(b, t); | - |
| 1930 | if (outA && outB) evaluated: outA| yes Evaluation Count:130 | yes Evaluation Count:118 |
evaluated: outB| yes Evaluation Count:86 | yes Evaluation Count:44 |
| 44-130 |
| 1931 | return; executed: return;Execution Count:86 | 86 |
| 1932 | | - |
| 1933 | if (outA) evaluated: outA| yes Evaluation Count:44 | yes Evaluation Count:118 |
| 44-118 |
| 1934 | addLine(result, QLineF(intersectLine<edge>(a, b, t), b)); executed: addLine(result, QLineF(intersectLine<edge>(a, b, t), b));Execution Count:44 | 44 |
| 1935 | else if(outB) evaluated: outB| yes Evaluation Count:44 | yes Evaluation Count:74 |
| 44-74 |
| 1936 | addLine(result, QLineF(a, intersectLine<edge>(a, b, t))); executed: addLine(result, QLineF(a, intersectLine<edge>(a, b, t)));Execution Count:44 | 44 |
| 1937 | else | - |
| 1938 | addLine(result, QLineF(a, b)); executed: addLine(result, QLineF(a, b));Execution Count:74 | 74 |
| 1939 | } | - |
| 1940 | | - |
| 1941 | void addBezier(QPainterPath &path, const QBezier &bezier) | - |
| 1942 | { | - |
| 1943 | if (path.elementCount() > 0) never evaluated: path.elementCount() > 0 | 0 |
| 1944 | path.lineTo(bezier.pt1()); never executed: path.lineTo(bezier.pt1()); | 0 |
| 1945 | else | - |
| 1946 | path.moveTo(bezier.pt1()); never executed: path.moveTo(bezier.pt1()); | 0 |
| 1947 | | - |
| 1948 | path.cubicTo(bezier.pt2(), bezier.pt3(), bezier.pt4()); | - |
| 1949 | } | 0 |
| 1950 | | - |
| 1951 | template <Edge edge> | - |
| 1952 | void clipBezier(const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, qreal t, QPainterPath &result) | - |
| 1953 | { | - |
| 1954 | QBezier bezier = QBezier::fromPoints(a, b, c, d); | - |
| 1955 | | - |
| 1956 | bool outA = compare<edge>(a, t); | - |
| 1957 | bool outB = compare<edge>(b, t); | - |
| 1958 | bool outC = compare<edge>(c, t); | - |
| 1959 | bool outD = compare<edge>(d, t); | - |
| 1960 | | - |
| 1961 | int outCount = int(outA) + int(outB) + int(outC) + int(outD); | - |
| 1962 | | - |
| 1963 | if (outCount == 4) never evaluated: outCount == 4 | 0 |
| 1964 | return; | 0 |
| 1965 | | - |
| 1966 | if (outCount == 0) { never evaluated: outCount == 0 | 0 |
| 1967 | addBezier(result, bezier); | - |
| 1968 | return; | 0 |
| 1969 | } | - |
| 1970 | | - |
| 1971 | QTransform flip = isVertical(edge) ? QTransform(0, 1, 1, 0, 0, 0) : QTransform(); never evaluated: isVertical(edge) | 0 |
| 1972 | QBezier unflipped = bezier; | - |
| 1973 | QBezier flipped = bezier.mapBy(flip); | - |
| 1974 | | - |
| 1975 | qreal t0 = 0, t1 = 1; | - |
| 1976 | int stationary = flipped.stationaryYPoints(t0, t1); | - |
| 1977 | | - |
| 1978 | qreal segments[4]; | - |
| 1979 | QPointF points[4]; | - |
| 1980 | points[0] = unflipped.pt1(); | - |
| 1981 | segments[0] = 0; | - |
| 1982 | | - |
| 1983 | int segmentCount = 0; | - |
| 1984 | if (stationary > 0) { never evaluated: stationary > 0 | 0 |
| 1985 | ++segmentCount; | - |
| 1986 | segments[segmentCount] = t0; | - |
| 1987 | points[segmentCount] = unflipped.pointAt(t0); | - |
| 1988 | } | 0 |
| 1989 | if (stationary > 1) { never evaluated: stationary > 1 | 0 |
| 1990 | ++segmentCount; | - |
| 1991 | segments[segmentCount] = t1; | - |
| 1992 | points[segmentCount] = unflipped.pointAt(t1); | - |
| 1993 | } | 0 |
| 1994 | ++segmentCount; | - |
| 1995 | segments[segmentCount] = 1; | - |
| 1996 | points[segmentCount] = unflipped.pt4(); | - |
| 1997 | | - |
| 1998 | qreal lastIntersection = 0; | - |
| 1999 | for (int i = 0; i < segmentCount; ++i) { never evaluated: i < segmentCount | 0 |
| 2000 | outA = compare<edge>(points[i], t); | - |
| 2001 | outB = compare<edge>(points[i+1], t); | - |
| 2002 | | - |
| 2003 | if (outA != outB) { never evaluated: outA != outB | 0 |
| 2004 | qreal intersection = flipped.tForY(segments[i], segments[i+1], t); | - |
| 2005 | | - |
| 2006 | if (outB) | 0 |
| 2007 | addBezier(result, unflipped.getSubRange(lastIntersection, intersection)); never executed: addBezier(result, unflipped.getSubRange(lastIntersection, intersection)); | 0 |
| 2008 | | - |
| 2009 | lastIntersection = intersection; | - |
| 2010 | } | 0 |
| 2011 | } | 0 |
| 2012 | | - |
| 2013 | if (!outB) | 0 |
| 2014 | addBezier(result, unflipped.getSubRange(lastIntersection, 1)); never executed: addBezier(result, unflipped.getSubRange(lastIntersection, 1)); | 0 |
| 2015 | } | 0 |
| 2016 | | - |
| 2017 | | - |
| 2018 | template <Edge edge> | - |
| 2019 | QPainterPath clip(const QPainterPath &path, qreal t) | - |
| 2020 | { | - |
| 2021 | QPainterPath result; | - |
| 2022 | for (int i = 1; i < path.elementCount(); ++i) { evaluated: i < path.elementCount()| yes Evaluation Count:238 | yes Evaluation Count:44 |
| 44-238 |
| 2023 | const QPainterPath::Element &element = path.elementAt(i); | - |
| 2024 | qt_noop(); | - |
| 2025 | if (element.isLineTo()) { partially evaluated: element.isLineTo()| yes Evaluation Count:238 | no Evaluation Count:0 |
| 0-238 |
| 2026 | clipLine<edge>(path.elementAt(i-1), path.elementAt(i), t, result); | - |
| 2027 | } else { executed: }Execution Count:238 | 238 |
| 2028 | clipBezier<edge>(path.elementAt(i-1), path.elementAt(i), path.elementAt(i+1), path.elementAt(i+2), t, result); | - |
| 2029 | i += 2; | - |
| 2030 | } | 0 |
| 2031 | } | - |
| 2032 | | - |
| 2033 | int last = path.elementCount() - 1; | - |
| 2034 | if (QPointF(path.elementAt(last)) != QPointF(path.elementAt(0))) evaluated: QPointF(path.elementAt(last)) != QPointF(path.elementAt(0))| yes Evaluation Count:10 | yes Evaluation Count:34 |
| 10-34 |
| 2035 | clipLine<edge>(path.elementAt(last), path.elementAt(0), t, result); executed: clipLine<edge>(path.elementAt(last), path.elementAt(0), t, result);Execution Count:10 | 10 |
| 2036 | | - |
| 2037 | return result; executed: return result;Execution Count:44 | 44 |
| 2038 | } | - |
| 2039 | | - |
| 2040 | QPainterPath intersectPath(const QPainterPath &path, const QRectF &rect) | - |
| 2041 | { | - |
| 2042 | QList<QPainterPath> subpaths = toSubpaths(path); | - |
| 2043 | | - |
| 2044 | QPainterPath result; | - |
| 2045 | result.setFillRule(path.fillRule()); | - |
| 2046 | for (int i = 0; i < subpaths.size(); ++i) { evaluated: i < subpaths.size()| yes Evaluation Count:16 | yes Evaluation Count:8 |
| 8-16 |
| 2047 | QPainterPath subPath = subpaths.at(i); | - |
| 2048 | QRectF bounds = subPath.boundingRect(); | - |
| 2049 | if (bounds.intersects(rect)) { partially evaluated: bounds.intersects(rect)| yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
| 2050 | if (bounds.left() < rect.left()) evaluated: bounds.left() < rect.left()| yes Evaluation Count:6 | yes Evaluation Count:10 |
| 6-10 |
| 2051 | subPath = clip<Left>(subPath, rect.left()); executed: subPath = clip<Left>(subPath, rect.left());Execution Count:6 | 6 |
| 2052 | if (bounds.right() > rect.right()) partially evaluated: bounds.right() > rect.right()| yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
| 2053 | subPath = clip<Right>(subPath, rect.right()); executed: subPath = clip<Right>(subPath, rect.right());Execution Count:16 | 16 |
| 2054 | | - |
| 2055 | bounds = subPath.boundingRect(); | - |
| 2056 | | - |
| 2057 | if (bounds.top() < rect.top()) evaluated: bounds.top() < rect.top()| yes Evaluation Count:6 | yes Evaluation Count:10 |
| 6-10 |
| 2058 | subPath = clip<Top>(subPath, rect.top()); executed: subPath = clip<Top>(subPath, rect.top());Execution Count:6 | 6 |
| 2059 | if (bounds.bottom() > rect.bottom()) partially evaluated: bounds.bottom() > rect.bottom()| yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
| 2060 | subPath = clip<Bottom>(subPath, rect.bottom()); executed: subPath = clip<Bottom>(subPath, rect.bottom());Execution Count:16 | 16 |
| 2061 | | - |
| 2062 | if (subPath.elementCount() > 1) partially evaluated: subPath.elementCount() > 1| yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
| 2063 | result.addPath(subPath); executed: result.addPath(subPath);Execution Count:16 | 16 |
| 2064 | } executed: }Execution Count:16 | 16 |
| 2065 | } executed: }Execution Count:16 | 16 |
| 2066 | return result; executed: return result;Execution Count:8 | 8 |
| 2067 | } | - |
| 2068 | | - |
| 2069 | } | - |
| 2070 | | - |
| 2071 | QPainterPath QPathClipper::intersect(const QPainterPath &path, const QRectF &rect) | - |
| 2072 | { | - |
| 2073 | return intersectPath(path, rect); executed: return intersectPath(path, rect);Execution Count:8 | 8 |
| 2074 | } | - |
| 2075 | | - |
| 2076 | | - |
| 2077 | | - |
| | |