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