tools/qline.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3QDebug operator<<(QDebug d, const QLine &p) -
4{ -
5 d << "QLine(" << p.p1() << ',' << p.p2() << ')'; -
6 return d;
executed: return d;
Execution Count:1
1
7} -
8QDataStream &operator<<(QDataStream &stream, const QLine &line) -
9{ -
10 stream << line.p1() << line.p2(); -
11 return stream;
executed: return stream;
Execution Count:3
3
12} -
13QDataStream &operator>>(QDataStream &stream, QLine &line) -
14{ -
15 QPoint p1, p2; -
16 stream >> p1; -
17 stream >> p2; -
18 line = QLine(p1, p2); -
19 -
20 return stream;
executed: return stream;
Execution Count:7
7
21} -
22qreal QLineF::length() const -
23{ -
24 qreal x = pt2.x() - pt1.x(); -
25 qreal y = pt2.y() - pt1.y(); -
26 return qSqrt(x*x + y*y);
executed: return qSqrt(x*x + y*y);
Execution Count:28476
28476
27} -
28qreal QLineF::angle() const -
29{ -
30 const qreal dx = pt2.x() - pt1.x(); -
31 const qreal dy = pt2.y() - pt1.y(); -
32 -
33 const qreal theta = qAtan2(-dy, dx) * 360.0 / 6.28318530717958647692528676655900576; -
34 -
35 const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
evaluated: theta < 0
TRUEFALSE
yes
Evaluation Count:3739
yes
Evaluation Count:4367
3739-4367
36 -
37 if (qFuzzyCompare(theta_normalized, qreal(360)))
evaluated: qFuzzyCompare(theta_normalized, qreal(360))
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8104
2-8104
38 return qreal(0);
executed: return qreal(0);
Execution Count:2
2
39 else -
40 return theta_normalized;
executed: return theta_normalized;
Execution Count:8104
8104
41} -
42void QLineF::setAngle(qreal angle) -
43{ -
44 const qreal angleR = angle * 6.28318530717958647692528676655900576 / 360.0; -
45 const qreal l = length(); -
46 -
47 const qreal dx = qCos(angleR) * l; -
48 const qreal dy = -qSin(angleR) * l; -
49 -
50 pt2.rx() = pt1.x() + dx; -
51 pt2.ry() = pt1.y() + dy; -
52}
executed: }
Execution Count:1804
1804
53QLineF QLineF::fromPolar(qreal length, qreal angle) -
54{ -
55 const qreal angleR = angle * 6.28318530717958647692528676655900576 / 360.0; -
56 return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
executed: return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
Execution Count:4169
4169
57} -
58 -
59 -
60 -
61 -
62 -
63 -
64 -
65QLineF QLineF::unitVector() const -
66{ -
67 qreal x = pt2.x() - pt1.x(); -
68 qreal y = pt2.y() - pt1.y(); -
69 -
70 qreal len = qSqrt(x*x + y*y); -
71 QLineF f(p1(), QPointF(pt1.x() + x/len, pt1.y() + y/len)); -
72 -
73 -
74 -
75 -
76 -
77 -
78 return f;
executed: return f;
Execution Count:36455
36455
79} -
80QLineF::IntersectType QLineF::intersect(const QLineF &l, QPointF *intersectionPoint) const -
81{ -
82 -
83 const QPointF a = pt2 - pt1; -
84 const QPointF b = l.pt1 - l.pt2; -
85 const QPointF c = pt1 - l.pt1; -
86 -
87 const qreal denominator = a.y() * b.x() - a.x() * b.y(); -
88 if (denominator == 0 || !qt_is_finite(denominator))
evaluated: denominator == 0
TRUEFALSE
yes
Evaluation Count:3431
yes
Evaluation Count:3407
partially evaluated: !qt_is_finite(denominator)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3407
0-3431
89 return NoIntersection;
executed: return NoIntersection;
Execution Count:3431
3431
90 -
91 const qreal reciprocal = 1 / denominator; -
92 const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal; -
93 if (intersectionPoint)
partially evaluated: intersectionPoint
TRUEFALSE
yes
Evaluation Count:3407
no
Evaluation Count:0
0-3407
94 *intersectionPoint = pt1 + a * na;
executed: *intersectionPoint = pt1 + a * na;
Execution Count:3407
3407
95 -
96 if (na < 0 || na > 1)
evaluated: na < 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:3402
evaluated: na > 1
TRUEFALSE
yes
Evaluation Count:1201
yes
Evaluation Count:2201
5-3402
97 return UnboundedIntersection;
executed: return UnboundedIntersection;
Execution Count:1206
1206
98 -
99 const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal; -
100 if (nb < 0 || nb > 1)
partially evaluated: nb < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2201
evaluated: nb > 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2200
0-2201
101 return UnboundedIntersection;
executed: return UnboundedIntersection;
Execution Count:1
1
102 -
103 return BoundedIntersection;
executed: return BoundedIntersection;
Execution Count:2200
2200
104} -
105qreal QLineF::angleTo(const QLineF &l) const -
106{ -
107 if (isNull() || l.isNull())
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2781
partially evaluated: l.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2781
0-2781
108 return 0;
never executed: return 0;
0
109 -
110 const qreal a1 = angle(); -
111 const qreal a2 = l.angle(); -
112 -
113 const qreal delta = a2 - a1; -
114 const qreal delta_normalized = delta < 0 ? delta + 360 : delta;
evaluated: delta < 0
TRUEFALSE
yes
Evaluation Count:821
yes
Evaluation Count:1960
821-1960
115 -
116 if (qFuzzyCompare(delta, qreal(360)))
partially evaluated: qFuzzyCompare(delta, qreal(360))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2781
0-2781
117 return 0;
never executed: return 0;
0
118 else -
119 return delta_normalized;
executed: return delta_normalized;
Execution Count:2781
2781
120} -
121qreal QLineF::angle(const QLineF &l) const -
122{ -
123 if (isNull() || l.isNull())
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:183
partially evaluated: l.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:183
0-183
124 return 0;
never executed: return 0;
0
125 qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length()); -
126 qreal rad = 0; -
127 -
128 if (cos_line >= -1.0 && cos_line <= 1.0) rad = qAcos( cos_line );
executed: rad = qAcos( cos_line );
Execution Count:182
partially evaluated: cos_line >= -1.0
TRUEFALSE
yes
Evaluation Count:183
no
Evaluation Count:0
evaluated: cos_line <= 1.0
TRUEFALSE
yes
Evaluation Count:182
yes
Evaluation Count:1
0-183
129 return rad * 360 / 6.28318530717958647692528676655900576;
executed: return rad * 360 / 6.28318530717958647692528676655900576;
Execution Count:183
183
130} -
131 -
132 -
133 -
134QDebug operator<<(QDebug d, const QLineF &p) -
135{ -
136 d << "QLineF(" << p.p1() << ',' << p.p2() << ')'; -
137 return d;
executed: return d;
Execution Count:1
1
138} -
139QDataStream &operator<<(QDataStream &stream, const QLineF &line) -
140{ -
141 stream << line.p1() << line.p2(); -
142 return stream;
executed: return stream;
Execution Count:3
3
143} -
144QDataStream &operator>>(QDataStream &stream, QLineF &line) -
145{ -
146 QPointF start, end; -
147 stream >> start; -
148 stream >> end; -
149 line = QLineF(start, end); -
150 -
151 return stream;
executed: return stream;
Execution Count:7
7
152} -
153 -
154 -
155 -
156 -
157 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial