QLineF Class
The QLineF class provides a two-dimensional vector using floating point precision. More…
| Header | #include <QLineF> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | IntersectionType |
Public Functions
| QLineF() | |
| QLineF(const QPointF &p1, const QPointF &p2) | |
| QLineF(double x1, double y1, double x2, double y2) | |
| QLineF(const QLine &l) | |
| bool | isNull() const |
| QPointF | p1() const |
| QPointF | p2() const |
| double | x1() const |
| double | y1() const |
| double | x2() const |
| double | y2() const |
| double | dx() const |
| double | dy() const |
| QPointF | center() const |
| double | length() const |
| void | setLength(double len) |
| double | angle() const |
| void | setAngle(double angle) |
| double | angleTo(const QLineF &o) const |
| QLineF | unitVector() const |
| QLineF | normalVector() const |
| QPointF | pointAt(double t) const |
| QLine | toLine() const |
| IntersectionType | intersects(const QLineF &l, QPointF *point = nullptr) const |
| void | setP1(const QPointF &p) |
| void | setP2(const QPointF &p) |
| void | setPoints(const QPointF &p, const QPointF &q) |
| void | setLine(double x1, double y1, double x2, double y2) |
| void | translate(const QPointF &p) |
| void | translate(double dx, double dy) |
| QLineF | translated(const QPointF &p) const |
| QLineF | translated(double dx, double dy) const |
Static Public Members
| QLineF | fromPolar(double length, double angle) |
Detailed Description
A QLineF describes a finite line (or line segment) by its two end points, stored as QPointF values. Angles are measured in degrees, counter-clockwise from the positive x axis; since the y axis points down, a positive angle turns the line upwards on screen.
Differences from Qt
Coordinates are always double, which is what qreal is in Nt.
Member Type Documentation
enum QLineF::IntersectionType
Describes the type of intersection found by intersects().
| Constant | Description |
|---|---|
QLineF::NoIntersection | The lines do not intersect, because they are parallel. |
QLineF::BoundedIntersection | The lines intersect at a point that lies within both line segments. |
QLineF::UnboundedIntersection | The lines would intersect if extended indefinitely, but the intersection point lies outside at least one of the segments. |
See also intersects().
Member Function Documentation
QLineF::QLineF()
Constructs a null line, with both end points at (0, 0).
See also isNull().
QLineF::QLineF(const QPointF &p1, const QPointF &p2)
Constructs a line object that represents the line between p1 and p2.
QLineF::QLineF(double x1, double y1, double x2, double y2)
Constructs a line object that represents the line between (x1, y1) and (x2, y2).
QLineF::QLineF(const QLine &l)
Construct a QLineF object from the given integer-based line l.
See also toLine().
double QLineF::angle() const
Returns the angle of the line in degrees, measured counter-clockwise from the positive x axis, in the range [0, 360).
See also setAngle() and angleTo().
double QLineF::angleTo(const QLineF &o) const
Returns the angle in degrees, in the range [0, 360), by which this line must be rotated counter-clockwise to have the direction of the o line. Returns 0 if either line is null.
See also angle().
QPointF QLineF::center() const
Returns the center point of this line, the midpoint between the end points.
double QLineF::dx() const
Returns the horizontal component of the line's vector, that is, x2() - x1().
See also dy().
double QLineF::dy() const
Returns the vertical component of the line's vector, that is, y2() - y1().
See also dx().
QLineF QLineF::fromPolar(double length, double angle)
Returns a QLineF with the given length and angle, starting at the origin.
The angle is in degrees, measured counter-clockwise from the positive x axis.
See also setLength() and setAngle().
IntersectionType QLineF::intersects(const QLineF &l, QPointF *point = nullptr) const
Returns a value indicating whether this line and the line l intersect, and if so how.
If the lines are not parallel and point is not nullptr, it is set to the intersection point, even when the intersection is unbounded. If the lines are parallel, point is left unchanged.
See also IntersectionType.
bool QLineF::isNull() const
Returns true if the start point equals the end point; otherwise returns false.
double QLineF::length() const
Returns the length of the line.
See also setLength().
QLineF QLineF::normalVector() const
Returns a line that is perpendicular to this line, starts at the same point and has the same length.
See also unitVector().
QPointF QLineF::p1() const
Returns the line's start point.
See also setP1(), x1(), y1() and p2().
QPointF QLineF::p2() const
Returns the line's end point.
See also setP2(), x2(), y2() and p1().
QPointF QLineF::pointAt(double t) const
Returns the point at the parameterized position t, where 0.0 is the start point, 1.0 is the end point, and other values lie on the extension of the line.
void QLineF::setAngle(double angle)
Sets the angle of the line to the given angle in degrees, measured counter-clockwise from the positive x axis. The start point and the length of the line are kept.
See also angle() and length().
void QLineF::setLength(double len)
Sets the length of the line to the given len, keeping the start point and the direction. Does nothing if the line has zero length.
See also length() and unitVector().
void QLineF::setLine(double x1, double y1, double x2, double y2)
Sets this line to the start point (x1, y1) and end point (x2, y2).
See also setP1(), setP2() and setPoints().
void QLineF::setP1(const QPointF &p)
Sets the start point of this line to p.
void QLineF::setP2(const QPointF &p)
Sets the end point of this line to p.
void QLineF::setPoints(const QPointF &p, const QPointF &q)
Sets the start point of this line to p and the end point to q.
See also setP1(), setP2() and setLine().
QLine QLineF::toLine() const
Returns an integer-based copy of this line, with the end points rounded to the nearest integer.
See also QLineF(const QLine &).
void QLineF::translate(const QPointF &p)
Translates this line by the given offset p.
See also translated().
void QLineF::translate(double dx, double dy)
This is an overloaded function.
Translates this line the distance specified by dx and dy.
QLineF QLineF::translated(const QPointF &p) const
Returns this line translated by the given offset p.
See also translate().
QLineF QLineF::translated(double dx, double dy) const
This is an overloaded function.
Returns this line translated the distance specified by dx and dy.
QLineF QLineF::unitVector() const
Returns the unit vector for this line, that is, a line starting at the same point with a length of 1.0 and the same direction. If this line has zero length, it is returned unchanged.
See also normalVector() and setLength().
double QLineF::x1() const
Returns the x coordinate of the line's start point.
double QLineF::x2() const
Returns the x coordinate of the line's end point.
double QLineF::y1() const
Returns the y coordinate of the line's start point.
double QLineF::y2() const
Returns the y coordinate of the line's end point.