OpenCoverage

qline.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qline.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qline.h"-
41#include "qdebug.h"-
42#include "qdatastream.h"-
43#include "qmath.h"-
44#include <private/qnumeric_p.h>-
45-
46QT_BEGIN_NAMESPACE-
47-
48/*!-
49 \class QLine-
50 \inmodule QtCore-
51 \ingroup painting-
52-
53 \brief The QLine class provides a two-dimensional vector using-
54 integer precision.-
55-
56 A QLine describes a finite length line (or a line segment) on a-
57 two-dimensional surface. The start and end points of the line are-
58 specified using integer point accuracy for coordinates. Use the-
59 QLineF constructor to retrieve a floating point copy.-
60-
61 \table-
62 \row-
63 \li \inlineimage qline-point.png-
64 \li \inlineimage qline-coordinates.png-
65 \endtable-
66-
67 The positions of the line's start and end points can be retrieved-
68 using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The-
69 dx() and dy() functions return the horizontal and vertical-
70 components of the line. Use isNull() to determine whether the-
71 QLine represents a valid line or a null line.-
72-
73 Finally, the line can be translated a given offset using the-
74 translate() function.-
75-
76 \sa QLineF, QPolygon, QRect-
77*/-
78-
79/*!-
80 \fn QLine::QLine()-
81-
82 Constructs a null line.-
83*/-
84-
85/*!-
86 \fn QLine::QLine(const QPoint &p1, const QPoint &p2)-
87-
88 Constructs a line object that represents the line between \a p1 and-
89 \a p2.-
90*/-
91-
92/*!-
93 \fn QLine::QLine(int x1, int y1, int x2, int y2)-
94-
95 Constructs a line object that represents the line between (\a x1, \a y1) and-
96 (\a x2, \a y2).-
97*/-
98-
99/*!-
100 \fn bool QLine::isNull() const-
101-
102 Returns \c true if the line is not set up with valid start and end point;-
103 otherwise returns \c false.-
104*/-
105-
106/*!-
107 \fn QPoint QLine::p1() const-
108-
109 Returns the line's start point.-
110-
111 \sa x1(), y1(), p2()-
112*/-
113-
114/*!-
115 \fn QPoint QLine::p2() const-
116-
117 Returns the line's end point.-
118-
119 \sa x2(), y2(), p1()-
120*/-
121-
122/*!-
123 \fn int QLine::x1() const-
124-
125 Returns the x-coordinate of the line's start point.-
126-
127 \sa p1()-
128*/-
129-
130/*!-
131 \fn int QLine::y1() const-
132-
133 Returns the y-coordinate of the line's start point.-
134-
135 \sa p1()-
136*/-
137-
138/*!-
139 \fn int QLine::x2() const-
140-
141 Returns the x-coordinate of the line's end point.-
142-
143 \sa p2()-
144*/-
145-
146/*!-
147 \fn int QLine::y2() const-
148-
149 Returns the y-coordinate of the line's end point.-
150-
151 \sa p2()-
152*/-
153-
154/*!-
155 \fn int QLine::dx() const-
156-
157 Returns the horizontal component of the line's vector.-
158-
159 \sa dy()-
160*/-
161-
162/*!-
163 \fn int QLine::dy() const-
164-
165 Returns the vertical component of the line's vector.-
166-
167 \sa dx()-
168*/-
169-
170/*!-
171 \fn bool QLine::operator!=(const QLine &line) const-
172-
173 Returns \c true if the given \a line is not the same as \e this line.-
174-
175 A line is different from another line if any of their start or-
176 end points differ, or the internal order of the points is different.-
177*/-
178-
179/*!-
180 \fn bool QLine::operator==(const QLine &line) const-
181-
182 Returns \c true if the given \a line is the same as \e this line.-
183-
184 A line is identical to another line if the start and end points-
185 are identical, and the internal order of the points is the same.-
186*/-
187-
188/*!-
189 \fn void QLine::translate(const QPoint &offset)-
190-
191 Translates this line by the given \a offset.-
192*/-
193-
194/*!-
195 \fn void QLine::translate(int dx, int dy)-
196 \overload-
197-
198 Translates this line the distance specified by \a dx and \a dy.-
199*/-
200-
201/*!-
202 \fn QLine QLine::translated(const QPoint &offset) const-
203-
204 \since 4.4-
205-
206 Returns this line translated by the given \a offset.-
207*/-
208-
209/*!-
210 \fn QLine QLine::translated(int dx, int dy) const-
211 \overload-
212 \since 4.4-
213-
214 Returns this line translated the distance specified by \a dx and \a dy.-
215*/-
216-
217-
218/*!-
219 \fn void QLine::setP1(const QPoint &p1)-
220 \since 4.4-
221-
222 Sets the starting point of this line to \a p1.-
223-
224 \sa setP2(), p1()-
225*/-
226-
227-
228/*!-
229 \fn void QLine::setP2(const QPoint &p2)-
230 \since 4.4-
231-
232 Sets the end point of this line to \a p2.-
233-
234 \sa setP1(), p2()-
235*/-
236-
237-
238/*!-
239 \fn void QLine::setPoints(const QPoint &p1, const QPoint &p2)-
240 \since 4.4-
241-
242 Sets the start point of this line to \a p1 and the end point of this line to \a p2.-
243-
244 \sa setP1(), setP2(), p1(), p2()-
245*/-
246-
247-
248/*!-
249 \fn void QLine::setLine(int x1, int y1, int x2, int y2)-
250 \since 4.4-
251-
252 Sets this line to the start in \a x1, \a y1 and end in \a x2, \a y2.-
253-
254 \sa setP1(), setP2(), p1(), p2()-
255*/-
256-
257-
258-
259#ifndef QT_NO_DEBUG_STREAM-
260QDebug operator<<(QDebug dbg, const QLine &p)-
261{-
262 QDebugStateSaver saver(dbg);-
263 dbg.nospace() << "QLine(" << p.p1() << ',' << p.p2() << ')';-
264 return dbg;
executed 2 times by 2 tests: return dbg;
Executed by:
  • tst_QDebug
  • tst_QVariant
2
265}-
266#endif-
267-
268#ifndef QT_NO_DATASTREAM-
269/*!-
270 \relates QLine-
271-
272 Writes the given \a line to the given \a stream and returns a-
273 reference to the stream.-
274-
275 \sa {Serializing Qt Data Types}-
276*/-
277-
278QDataStream &operator<<(QDataStream &stream, const QLine &line)-
279{-
280 stream << line.p1() << line.p2();-
281 return stream;
executed 3 times by 2 tests: return stream;
Executed by:
  • tst_QMetaType
  • tst_QVariant
3
282}-
283-
284/*!-
285 \relates QLine-
286-
287 Reads a line from the given \a stream into the given \a line and-
288 returns a reference to the stream.-
289-
290 \sa {Serializing Qt Data Types}-
291*/-
292-
293QDataStream &operator>>(QDataStream &stream, QLine &line)-
294{-
295 QPoint p1, p2;-
296 stream >> p1;-
297 stream >> p2;-
298 line = QLine(p1, p2);-
299-
300 return stream;
executed 7 times by 2 tests: return stream;
Executed by:
  • tst_QMetaType
  • tst_QVariant
7
301}-
302-
303#endif // QT_NO_DATASTREAM-
304-
305-
306#ifndef M_2PI-
307#define M_2PI 6.28318530717958647692528676655900576-
308#endif-
309-
310/*!-
311 \class QLineF-
312 \inmodule QtCore-
313 \ingroup painting-
314-
315 \brief The QLineF class provides a two-dimensional vector using-
316 floating point precision.-
317-
318 A QLineF describes a finite length line (or line segment) on a-
319 two-dimensional surface. QLineF defines the start and end points-
320 of the line using floating point accuracy for coordinates. Use-
321 the toLine() function to retrieve an integer based copy of this-
322 line.-
323-
324 \table-
325 \row-
326 \li \inlineimage qline-point.png-
327 \li \inlineimage qline-coordinates.png-
328 \endtable-
329-
330 The positions of the line's start and end points can be retrieved-
331 using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The-
332 dx() and dy() functions return the horizontal and vertical-
333 components of the line, respectively.-
334-
335 The line's length can be retrieved using the length() function,-
336 and altered using the setLength() function. Similarly, angle()-
337 and setAngle() are respectively used for retrieving and altering-
338 the angle of the line. Use the isNull()-
339 function to determine whether the QLineF represents a valid line-
340 or a null line.-
341-
342 The intersect() function determines the IntersectType for this-
343 line and a given line, while the angleTo() function returns the-
344 angle between the lines. In addition, the unitVector() function-
345 returns a line that has the same starting point as this line, but-
346 with a length of only 1, while the normalVector() function returns-
347 a line that is perpendicular to this line with the same starting-
348 point and length.-
349-
350 Finally, the line can be translated a given offset using the-
351 translate() function, and can be traversed using the pointAt()-
352 function.-
353-
354 \sa QLine, QPolygonF, QRectF-
355*/-
356-
357/*!-
358 \enum QLineF::IntersectType-
359-
360 Describes the intersection between two lines.-
361-
362 \table-
363 \row-
364 \li \inlineimage qlinef-unbounded.png-
365 \li \inlineimage qlinef-bounded.png-
366 \row-
367 \li QLineF::UnboundedIntersection-
368 \li QLineF::BoundedIntersection-
369 \endtable-
370-
371 \value NoIntersection Indicates that the lines do not intersect;-
372 i.e. they are parallel.-
373-
374 \value UnboundedIntersection The two lines intersect, but not-
375 within the range defined by their lengths. This will be the case-
376 if the lines are not parallel.-
377-
378 intersect() will also return this value if the intersect point is-
379 within the start and end point of only one of the lines.-
380-
381 \value BoundedIntersection The two lines intersect with each other-
382 within the start and end points of each line.-
383-
384 \sa intersect()-
385*/-
386-
387/*!-
388 \fn QLineF::QLineF()-
389-
390 Constructs a null line.-
391*/-
392-
393/*!-
394 \fn QLineF::QLineF(const QPointF &p1, const QPointF &p2)-
395-
396 Constructs a line object that represents the line between \a p1 and-
397 \a p2.-
398*/-
399-
400/*!-
401 \fn QLineF::QLineF(qreal x1, qreal y1, qreal x2, qreal y2)-
402-
403 Constructs a line object that represents the line between (\a x1, \a y1) and-
404 (\a x2, \a y2).-
405*/-
406-
407/*!-
408 \fn QLineF::QLineF(const QLine &line)-
409-
410 Construct a QLineF object from the given integer-based \a line.-
411-
412 \sa toLine()-
413*/-
414-
415/*!-
416 \fn bool QLineF::isNull() const-
417-
418 Returns \c true if the line is not set up with valid start and end point;-
419 otherwise returns \c false.-
420*/-
421-
422/*!-
423 \fn QPointF QLineF::p1() const-
424-
425 Returns the line's start point.-
426-
427 \sa x1(), y1(), p2()-
428*/-
429-
430/*!-
431 \fn QPointF QLineF::p2() const-
432-
433 Returns the line's end point.-
434-
435 \sa x2(), y2(), p1()-
436*/-
437-
438/*!-
439 \fn QLine QLineF::toLine() const-
440-
441 Returns an integer based copy of this line.-
442-
443 Note that the returned line's start and end points are rounded to-
444 the nearest integer.-
445-
446 \sa QLineF()-
447*/-
448/*!-
449 \fn qreal QLineF::x1() const-
450-
451 Returns the x-coordinate of the line's start point.-
452-
453 \sa p1()-
454*/-
455-
456/*!-
457 \fn qreal QLineF::y1() const-
458-
459 Returns the y-coordinate of the line's start point.-
460-
461 \sa p1()-
462*/-
463-
464/*!-
465 \fn qreal QLineF::x2() const-
466-
467 Returns the x-coordinate of the line's end point.-
468-
469 \sa p2()-
470*/-
471-
472/*!-
473 \fn qreal QLineF::y2() const-
474-
475 Returns the y-coordinate of the line's end point.-
476-
477 \sa p2()-
478*/-
479-
480/*!-
481 \fn qreal QLineF::dx() const-
482-
483 Returns the horizontal component of the line's vector.-
484-
485 \sa dy(), pointAt()-
486*/-
487-
488/*!-
489 \fn qreal QLineF::dy() const-
490-
491 Returns the vertical component of the line's vector.-
492-
493 \sa dx(), pointAt()-
494*/-
495-
496/*!-
497 \fn QLineF::setLength(qreal length)-
498-
499 Sets the length of the line to the given \a length. QLineF will-
500 move the end point - p2() - of the line to give the line its new length.-
501-
502 If the line is a null line, the length will remain zero regardless-
503 of the length specified.-
504-
505 \sa length(), isNull()-
506*/-
507-
508/*!-
509 \fn QLineF QLineF::normalVector() const-
510-
511 Returns a line that is perpendicular to this line with the same starting-
512 point and length.-
513-
514 \image qlinef-normalvector.png-
515-
516 \sa unitVector()-
517*/-
518-
519/*!-
520 \fn bool QLineF::operator!=(const QLineF &line) const-
521-
522 Returns \c true if the given \a line is not the same as \e this line.-
523-
524 A line is different from another line if their start or end points-
525 differ, or the internal order of the points is different.-
526*/-
527-
528/*!-
529 \fn bool QLineF::operator==(const QLineF &line) const-
530-
531 Returns \c true if the given \a line is the same as this line.-
532-
533 A line is identical to another line if the start and end points-
534 are identical, and the internal order of the points is the same.-
535*/-
536-
537/*!-
538 \fn qreal QLineF::pointAt(qreal t) const-
539-
540 Returns the point at the parameterized position specified by \a-
541 t. The function returns the line's start point if t = 0, and its end-
542 point if t = 1.-
543-
544 \sa dx(), dy()-
545*/-
546-
547/*!-
548 Returns the length of the line.-
549-
550 \sa setLength()-
551*/-
552qreal QLineF::length() const-
553{-
554 qreal x = pt2.x() - pt1.x();-
555 qreal y = pt2.y() - pt1.y();-
556 return qSqrt(x*x + y*y);
executed 133358 times by 22 tests: return qSqrt(x*x + y*y);
Executed by:
  • tst_QAccessibility
  • tst_QBrush
  • tst_QCheckBox
  • tst_QDataStream
  • tst_QGestureRecognizer
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QPrinter
  • tst_QProgressBar
  • tst_QStyle
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
133358
557}-
558-
559/*!-
560 \since 4.4-
561-
562 Returns the angle of the line in degrees.-
563-
564 The return value will be in the range of values from 0.0 up to but not-
565 including 360.0. The angles are measured counter-clockwise from a point-
566 on the x-axis to the right of the origin (x > 0).-
567-
568 \sa setAngle()-
569*/-
570qreal QLineF::angle() const-
571{-
572 const qreal dx = pt2.x() - pt1.x();-
573 const qreal dy = pt2.y() - pt1.y();-
574-
575 const qreal theta = qAtan2(-dy, dx) * 360.0 / M_2PI;-
576-
577 const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
theta < 0Description
TRUEevaluated 53865 times by 16 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGestureRecognizer
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
FALSEevaluated 54312 times by 11 tests
Evaluated by:
  • tst_QGestureRecognizer
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
53865-54312
578-
579 if (qFuzzyCompare(theta_normalized, qreal(360)))
qFuzzyCompare(...d, qreal(360))Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QLine
FALSEevaluated 108175 times by 16 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGestureRecognizer
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
2-108175
580 return qreal(0);
executed 2 times by 1 test: return qreal(0);
Executed by:
  • tst_QLine
2
581 else-
582 return theta_normalized;
executed 108175 times by 16 tests: return theta_normalized;
Executed by:
  • tst_QCheckBox
  • tst_QGestureRecognizer
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
108175
583}-
584-
585/*!-
586 \since 4.4-
587-
588 Sets the angle of the line to the given \a angle (in degrees).-
589 This will change the position of the second point of the line such that-
590 the line has the given angle.-
591-
592 Positive values for the angles mean counter-clockwise while negative values-
593 mean the clockwise direction. Zero degrees is at the 3 o'clock position.-
594-
595 \sa angle()-
596*/-
597void QLineF::setAngle(qreal angle)-
598{-
599 const qreal angleR = angle * M_2PI / 360.0;-
600 const qreal l = length();-
601-
602 const qreal dx = qCos(angleR) * l;-
603 const qreal dy = -qSin(angleR) * l;-
604-
605 pt2.rx() = pt1.x() + dx;-
606 pt2.ry() = pt1.y() + dy;-
607}
executed 1804 times by 1 test: end of block
Executed by:
  • tst_QLine
1804
608-
609/*!-
610 \since 4.4-
611-
612 Returns a QLineF with the given \a length and \a angle.-
613-
614 The first point of the line will be on the origin.-
615-
616 Positive values for the angles mean counter-clockwise while negative values-
617 mean the clockwise direction. Zero degrees is at the 3 o'clock position.-
618*/-
619QLineF QLineF::fromPolar(qreal length, qreal angle)-
620{-
621 const qreal angleR = angle * M_2PI / 360.0;-
622 return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
executed 4169 times by 2 tests: return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
Executed by:
  • tst_QLine
  • tst_QPainterPath
4169
623}-
624-
625/*!-
626 Returns the unit vector for this line, i.e a line starting at the-
627 same point as \e this line with a length of 1.0.-
628-
629 \sa normalVector()-
630*/-
631QLineF QLineF::unitVector() const-
632{-
633 qreal x = pt2.x() - pt1.x();-
634 qreal y = pt2.y() - pt1.y();-
635-
636 qreal len = qSqrt(x*x + y*y);-
637 QLineF f(p1(), QPointF(pt1.x() + x/len, pt1.y() + y/len));-
638-
639#ifndef QT_NO_DEBUG-
640 if (qAbs(f.length() - 1) >= 0.001)
qAbs(f.length() - 1) >= 0.001Description
TRUEnever evaluated
FALSEevaluated 102875 times by 16 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
0-102875
641 qWarning("QLine::unitVector: New line does not have unit length");
never executed: QMessageLogger(__FILE__, 641, __PRETTY_FUNCTION__).warning("QLine::unitVector: New line does not have unit length");
0
642#endif-
643-
644 return f;
executed 102875 times by 16 tests: return f;
Executed by:
  • tst_QAccessibility
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
102875
645}-
646-
647/*!-
648 \fn QLineF::IntersectType QLineF::intersect(const QLineF &line, QPointF *intersectionPoint) const-
649-
650 Returns a value indicating whether or not \e this line intersects-
651 with the given \a line.-
652-
653 The actual intersection point is extracted to \a intersectionPoint-
654 (if the pointer is valid). If the lines are parallel, the-
655 intersection point is undefined.-
656*/-
657-
658QLineF::IntersectType QLineF::intersect(const QLineF &l, QPointF *intersectionPoint) const-
659{-
660 // ipmlementation is based on Graphics Gems III's "Faster Line Segment Intersection"-
661 const QPointF a = pt2 - pt1;-
662 const QPointF b = l.pt1 - l.pt2;-
663 const QPointF c = pt1 - l.pt1;-
664-
665 const qreal denominator = a.y() * b.x() - a.x() * b.y();-
666 if (denominator == 0 || !qt_is_finite(denominator))
denominator == 0Description
TRUEevaluated 3700 times by 9 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsItem
  • tst_QGraphicsScene
  • tst_QGraphicsView
  • tst_QLine
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
FALSEevaluated 53468 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
!qt_is_finite(denominator)Description
TRUEnever evaluated
FALSEevaluated 53468 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
0-53468
667 return NoIntersection;
executed 3700 times by 9 tests: return NoIntersection;
Executed by:
  • tst_QCheckBox
  • tst_QGraphicsItem
  • tst_QGraphicsScene
  • tst_QGraphicsView
  • tst_QLine
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
3700
668-
669 const qreal reciprocal = 1 / denominator;-
670 const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal;-
671 if (intersectionPoint)
intersectionPointDescription
TRUEevaluated 53468 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
FALSEnever evaluated
0-53468
672 *intersectionPoint = pt1 + a * na;
executed 53468 times by 15 tests: *intersectionPoint = pt1 + a * na;
Executed by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
53468
673-
674 if (na < 0 || na > 1)
na < 0Description
TRUEevaluated 36 times by 6 tests
Evaluated by:
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QTouchEvent
  • tst_QTreeWidget
FALSEevaluated 53432 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
na > 1Description
TRUEevaluated 26230 times by 14 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
FALSEevaluated 27202 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
36-53432
675 return UnboundedIntersection;
executed 26266 times by 14 tests: return UnboundedIntersection;
Executed by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
26266
676-
677 const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal;-
678 if (nb < 0 || nb > 1)
nb < 0Description
TRUEnever evaluated
FALSEevaluated 27202 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
nb > 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLine
FALSEevaluated 27201 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
0-27202
679 return UnboundedIntersection;
executed 1 time by 1 test: return UnboundedIntersection;
Executed by:
  • tst_QLine
1
680-
681 return BoundedIntersection;
executed 27201 times by 15 tests: return BoundedIntersection;
Executed by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
27201
682}-
683-
684/*!-
685 \fn void QLineF::translate(const QPointF &offset)-
686-
687 Translates this line by the given \a offset.-
688*/-
689-
690/*!-
691 \fn void QLineF::translate(qreal dx, qreal dy)-
692 \overload-
693-
694 Translates this line the distance specified by \a dx and \a dy.-
695*/-
696-
697/*!-
698 \fn QLineF QLineF::translated(const QPointF &offset) const-
699-
700 \since 4.4-
701-
702 Returns this line translated by the given \a offset.-
703*/-
704-
705/*!-
706 \fn QLineF QLineF::translated(qreal dx, qreal dy) const-
707 \overload-
708 \since 4.4-
709-
710 Returns this line translated the distance specified by \a dx and \a dy.-
711*/-
712-
713/*!-
714 \fn void QLineF::setP1(const QPointF &p1)-
715 \since 4.4-
716-
717 Sets the starting point of this line to \a p1.-
718-
719 \sa setP2(), p1()-
720*/-
721-
722-
723/*!-
724 \fn void QLineF::setP2(const QPointF &p2)-
725 \since 4.4-
726-
727 Sets the end point of this line to \a p2.-
728-
729 \sa setP1(), p2()-
730*/-
731-
732-
733/*!-
734 \fn void QLineF::setPoints(const QPointF &p1, const QPointF &p2)-
735 \since 4.4-
736-
737 Sets the start point of this line to \a p1 and the end point of this line to \a p2.-
738-
739 \sa setP1(), setP2(), p1(), p2()-
740*/-
741-
742-
743/*!-
744 \fn void QLineF::setLine(qreal x1, qreal y1, qreal x2, qreal y2)-
745 \since 4.4-
746-
747 Sets this line to the start in \a x1, \a y1 and end in \a x2, \a y2.-
748-
749 \sa setP1(), setP2(), p1(), p2()-
750*/-
751-
752/*!-
753 \fn qreal QLineF::angleTo(const QLineF &line) const-
754-
755 \since 4.4-
756-
757 Returns the angle (in degrees) from this line to the given \a-
758 line, taking the direction of the lines into account. If the lines-
759 do not intersect within their range, it is the intersection point of-
760 the extended lines that serves as origin (see-
761 QLineF::UnboundedIntersection).-
762-
763 The returned value represents the number of degrees you need to add-
764 to this line to make it have the same angle as the given \a line,-
765 going counter-clockwise.-
766-
767 \sa intersect()-
768*/-
769qreal QLineF::angleTo(const QLineF &l) const-
770{-
771 if (isNull() || l.isNull())
isNull()Description
TRUEnever evaluated
FALSEevaluated 52787 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
l.isNull()Description
TRUEnever evaluated
FALSEevaluated 52787 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
0-52787
772 return 0;
never executed: return 0;
0
773-
774 const qreal a1 = angle();-
775 const qreal a2 = l.angle();-
776-
777 const qreal delta = a2 - a1;-
778 const qreal delta_normalized = delta < 0 ? delta + 360 : delta;
delta < 0Description
TRUEevaluated 19559 times by 10 tests
Evaluated by:
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
FALSEevaluated 33228 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
19559-33228
779-
780 if (qFuzzyCompare(delta, qreal(360)))
qFuzzyCompare(...a, qreal(360))Description
TRUEnever evaluated
FALSEevaluated 52787 times by 15 tests
Evaluated by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
0-52787
781 return 0;
never executed: return 0;
0
782 else-
783 return delta_normalized;
executed 52787 times by 15 tests: return delta_normalized;
Executed by:
  • tst_QCheckBox
  • tst_QGraphicsEffectSource
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsSceneIndex
  • tst_QGraphicsView
  • tst_QGraphicsWidget
  • tst_QLine
  • tst_QMdiSubWindow
  • tst_QPainter
  • tst_QPainterPath
  • tst_QTouchEvent
  • tst_QTreeView
  • tst_QTreeWidget
52787
784}-
785-
786/*!-
787 \fn qreal QLineF::angle(const QLineF &line) const-
788-
789 \obsolete-
790-
791 Returns the angle (in degrees) between this line and the given \a-
792 line, taking the direction of the lines into account. If the lines-
793 do not intersect within their range, it is the intersection point of-
794 the extended lines that serves as origin (see-
795 QLineF::UnboundedIntersection).-
796-
797 \table-
798 \row-
799 \li \inlineimage qlinef-angle-identicaldirection.png-
800 \li \inlineimage qlinef-angle-oppositedirection.png-
801 \endtable-
802-
803 When the lines are parallel, this function returns 0 if they have-
804 the same direction; otherwise it returns 180.-
805-
806 \sa intersect()-
807*/-
808qreal QLineF::angle(const QLineF &l) const-
809{-
810 if (isNull() || l.isNull())
isNull()Description
TRUEnever evaluated
FALSEevaluated 183 times by 1 test
Evaluated by:
  • tst_QLine
l.isNull()Description
TRUEnever evaluated
FALSEevaluated 183 times by 1 test
Evaluated by:
  • tst_QLine
0-183
811 return 0;
never executed: return 0;
0
812 qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());-
813 qreal rad = 0;-
814 // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)-
815 if (cos_line >= -1.0 && cos_line <= 1.0) rad = qAcos( cos_line );
executed 182 times by 1 test: rad = qAcos( cos_line );
Executed by:
  • tst_QLine
cos_line >= -1.0Description
TRUEevaluated 183 times by 1 test
Evaluated by:
  • tst_QLine
FALSEnever evaluated
cos_line <= 1.0Description
TRUEevaluated 182 times by 1 test
Evaluated by:
  • tst_QLine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLine
0-183
816 return rad * 360 / M_2PI;
executed 183 times by 1 test: return rad * 360 / 6.28318530717958647692528676655900576;
Executed by:
  • tst_QLine
183
817}-
818-
819-
820#ifndef QT_NO_DEBUG_STREAM-
821QDebug operator<<(QDebug dbg, const QLineF &p)-
822{-
823 QDebugStateSaver saver(dbg);-
824 dbg.nospace() << "QLineF(" << p.p1() << ',' << p.p2() << ')';-
825 return dbg;
executed 2 times by 2 tests: return dbg;
Executed by:
  • tst_QDebug
  • tst_QVariant
2
826}-
827#endif-
828-
829#ifndef QT_NO_DATASTREAM-
830/*!-
831 \relates QLineF-
832-
833 Writes the given \a line to the given \a stream and returns a-
834 reference to the stream.-
835-
836 \sa {Serializing Qt Data Types}-
837*/-
838-
839QDataStream &operator<<(QDataStream &stream, const QLineF &line)-
840{-
841 stream << line.p1() << line.p2();-
842 return stream;
executed 3 times by 2 tests: return stream;
Executed by:
  • tst_QMetaType
  • tst_QVariant
3
843}-
844-
845/*!-
846 \relates QLineF-
847-
848 Reads a line from the given \a stream into the given \a line and-
849 returns a reference to the stream.-
850-
851 \sa {Serializing Qt Data Types}-
852*/-
853-
854QDataStream &operator>>(QDataStream &stream, QLineF &line)-
855{-
856 QPointF start, end;-
857 stream >> start;-
858 stream >> end;-
859 line = QLineF(start, end);-
860-
861 return stream;
executed 7 times by 2 tests: return stream;
Executed by:
  • tst_QMetaType
  • tst_QVariant
7
862}-
863-
864#endif // QT_NO_DATASTREAM-
865-
866QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9