📄 qline.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qline.h"#include "qdebug.h"#include "qdatastream.h"#include <private/qnumeric_p.h>#include <math.h>/*! \class QLine \ingroup multimedia \brief The QLine class provides a two-dimensional vector using integer precision. A QLine describes a finite length line (or a line segment) on a two-dimensional surface. The start and end points of the line are specified using integer point accuracy for coordinates. Use the QLineF constructor to retrieve a floating point copy. \table \row \o \inlineimage qline-point.png \o \inlineimage qline-coordinates.png \endtable The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line. Use isNull() to determine whether the QLine represents a valid line or a null line. Finally, the line can be translated a given offset using the translate() function. \sa QLineF, QPolygon, QRect*//*! \fn QLine::QLine() Constructs a null line.*//*! \fn QLine::QLine(const QPoint &p1, const QPoint &p2) Constructs a line object that represents the line between \a p1 and \a p2.*//*! \fn QLine::QLine(int x1, int y1, int x2, int y2) Constructs a line object that represents the line between (\a x1, \a y1) and (\a x2, \a y2).*//*! \fn bool QLine::isNull() const Returns true if the line is not set up with valid start and end point; otherwise returns false.*//*! \fn QPoint QLine::p1() const Returns the line's start point. \sa x1(), y1(), p2()*//*! \fn QPoint QLine::p2() const Returns the line's end point. \sa x2(), y2(), p1()*//*! \fn int QLine::x1() const Returns the x-coordinate of the line's start point. \sa p1()*//*! \fn int QLine::y1() const Returns the y-coordinate of the line's start point. \sa p1()*//*! \fn int QLine::x2() const Returns the x-coordinate of the line's end point. \sa p2()*//*! \fn int QLine::y2() const Returns the y-coordinate of the line's end point. \sa p2()*//*! \fn int QLine::dx() const Returns the horizontal component of the line's vector. \sa dy()*//*! \fn int QLine::dy() const Returns the vertical component of the line's vector. \sa dx()*//*! \fn bool QLine::operator!=(const QLine &line) const Returns true if the given \a line is not the same as \e this line. A line is different from another line if any of their start or end points differ, or the internal order of the points is different.*//*! \fn bool QLine::operator==(const QLine &line) const Returns true if the given \a line is the same as \e this line. A line is identical to another line if the start and end points are identical, and the internal order of the points is the same.*//*! \fn void QLine::translate(const QPoint &offset) Translates this line by the given \a offset.*//*! \fn void QLine::translate(int dx, int dy) \overload Translates this line the distance specified by \a dx and \a dy.*/#ifndef QT_NO_DEBUG_STREAMQDebug operator<<(QDebug d, const QLine &p){ d << "QLine(" << p.p1() << "," << p.p2() << ")"; return d;}#endif#ifndef QT_NO_DATASTREAM/*! \relates QLine Writes the given \a line to the given \a stream and returns a reference to the stream. \sa {Format of the QDataStream Operators}*/QDataStream &operator<<(QDataStream &stream, const QLine &line){ stream << line.p1() << line.p2(); return stream;}/*! \relates QLine Reads a line from the given \a stream into the given \a line and returns a reference to the stream. \sa {Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &stream, QLine &line){ QPoint p1, p2; stream >> p1; stream >> p2; line = QLine(p1, p2); return stream;}#endif // QT_NO_DATASTREAM#ifndef M_2PI#define M_2PI 6.28318530717958647692528676655900576#endif/*! \class QLineF \ingroup multimedia \brief The QLineF class provides a two-dimensional vector using floating point precision. A QLineF describes a finite length line (or line segment) on a two-dimensional surface. QLineF defines the start and end points of the line using floating point accuracy for coordinates. Use the toLine() function to retrieve an integer based copy of this line. \table \row \o \inlineimage qline-point.png \o \inlineimage qline-coordinates.png \endtable The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line, respectively. The line's length can be retrieved using the length() function, and altered using the setLength() function. Use the isNull() function to determine whether the QLineF represents a valid line or a null line. The intersect() function determines the IntersectType for this line and a given line, while the angle() function returns the angle between the lines. In addition, the unitVector() function returns a line that has the same starting point as this line, but with a length of only 1, while the normalVector() function returns a line that is perpendicular to this line with the same starting point and length. Finally, the line can be translated a given offset using the translate() function, and can be traversed using the pointAt() function. \sa QLine, QPolygonF, QRectF*//*! \enum QLineF::IntersectType Describes the intersection between two lines. \table \row \o \inlineimage qlinef-unbounded.png \o \inlineimage qlinef-bounded.png \row \o QLineF::UnboundedIntersection \o QLineF::BoundedIntersection \endtable \value NoIntersection Indicates that the lines do not intersect; i.e. they are parallel. \value UnboundedIntersection The two lines intersect, but not within the range defined by their lengths. This will be the case if the lines are not parallel. \value BoundedIntersection The two lines intersect with each other within the start and end points of each line. \sa intersect()*//*! \fn QLineF::QLineF() Constructs a null line.*//*! \fn QLineF::QLineF(const QPointF &p1, const QPointF &p2) Constructs a line object that represents the line between \a p1 and \a p2.*//*! \fn QLineF::QLineF(qreal x1, qreal y1, qreal x2, qreal y2) Constructs a line object that represents the line between (\a x1, \a y1) and (\a x2, \a y2).*//*! \fn QLineF::QLineF(const QLine &line) Construct a QLineF object from the given integer-based \a line. \sa toLine()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -