Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | Related Functions | List of all members
QLineF Class Reference

The QLineF class provides a two-dimensional vector using floating point precision. More...

#include <qline.h>

Public Types

enum  IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection }
 Describes the intersection between two lines. More...
 

Public Functions

qreal angle () const
 Returns the angle of the line in degrees. More...
 
qreal angle (const QLineF &l) const
 Returns the angle (in degrees) between this line and the given line, taking the direction of the lines into account. More...
 
qreal angleTo (const QLineF &l) const
 Returns the angle (in positive degrees) from this line to the given line, taking the direction of the lines into account. More...
 
qreal dx () const
 Returns the horizontal component of the line's vector. More...
 
qreal dy () const
 Returns the vertical component of the line's vector. More...
 
IntersectType intersect (const QLineF &l, QPointF *intersectionPoint) const
 Returns a value indicating whether or not this line intersects with the given line. More...
 
bool isNull () const
 Returns true if the line is not set up with valid start and end point; otherwise returns false. More...
 
qreal length () const
 Returns the length of the line. More...
 
QLineF normalVector () const
 Returns a line that is perpendicular to this line with the same starting point and length. More...
 
bool operator!= (const QLineF &d) const
 Returns true if the given line is not the same as this line. More...
 
bool operator== (const QLineF &d) const
 Returns true if the given line is the same as this line. More...
 
QPointF p1 () const
 Returns the line's start point. More...
 
QPointF p2 () const
 Returns the line's end point. More...
 
QPointF pointAt (qreal t) const
 Returns the point at the parameterized position specified by t. More...
 
 QLineF ()
 Constructs a null line. More...
 
 QLineF (const QPointF &pt1, const QPointF &pt2)
 Constructs a line object that represents the line between p1 and p2. More...
 
 QLineF (qreal x1, qreal y1, qreal x2, qreal y2)
 Constructs a line object that represents the line between (x1, y1) and (x2, y2). More...
 
 QLineF (const QLine &line)
 Construct a QLineF object from the given integer-based line. More...
 
void setAngle (qreal angle)
 Sets the angle of the line to the given angle (in degrees). More...
 
void setLength (qreal len)
 Sets the length of the line to the given length. More...
 
void setLine (qreal x1, qreal y1, qreal x2, qreal y2)
 Sets this line to the start in x1, y1 and end in x2, y2. More...
 
void setP1 (const QPointF &p1)
 Sets the starting point of this line to p1. More...
 
void setP2 (const QPointF &p2)
 Sets the end point of this line to p2. More...
 
void setPoints (const QPointF &p1, const QPointF &p2)
 Sets the start point of this line to p1 and the end point of this line to p2. More...
 
QLine toLine () const
 Returns an integer based copy of this line. More...
 
void translate (const QPointF &p)
 Translates this line by the given offset. More...
 
void translate (qreal dx, qreal dy)
 Translates this line the distance specified by dx and dy. More...
 
QLineF translated (const QPointF &p) const
 Returns this line translated by the given offset. More...
 
QLineF translated (qreal dx, qreal dy) const
 Returns this line translated the distance specified by dx and dy. More...
 
QLineF unitVector () const
 Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0. More...
 
qreal x1 () const
 Returns the x-coordinate of the line's start point. More...
 
qreal x2 () const
 Returns the x-coordinate of the line's end point. More...
 
qreal y1 () const
 Returns the y-coordinate of the line's start point. More...
 
qreal y2 () const
 Returns the y-coordinate of the line's end point. More...
 

Static Public Functions

static QLineF fromPolar (qreal length, qreal angle)
 Returns a QLineF with the given length and angle. More...
 

Properties

QPointF pt1
 
QPointF pt2
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QLineF &line)
 Writes the given line to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QLineF &line)
 Reads a line from the given stream into the given line and returns a reference to the stream. More...
 

Detailed Description

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.

qline-point.png
qline-coordinates.png

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. Similarly, angle() and setAngle() are respectively used for retrieving and altering the angle of the line. 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.

See also
QLine, QPolygonF, QRectF

Definition at line 212 of file qline.h.

Enumerations

◆ IntersectType

Describes the intersection between two lines.

qlinef-unbounded.png
qlinef-bounded.png
QLineF::UnboundedIntersection QLineF::BoundedIntersection
  • NoIntersection Indicates that the lines do not intersect; i.e. they are parallel.
  • 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.

intersect() will also return this value if the intersect point is within the start and end point of only one of the lines.

  • BoundedIntersection The two lines intersect with each other within the start and end points of each line.
See also
intersect()
Enumerator
NoIntersection 
BoundedIntersection 
UnboundedIntersection 

Definition at line 215 of file qline.h.

Constructors and Destructors

◆ QLineF() [1/4]

QLineF::QLineF ( )
inline

Constructs a null line.

Definition at line 280 of file qline.h.

Referenced by fromPolar(), normalVector(), operator>>(), and translated().

281 {
282 }

◆ QLineF() [2/4]

QLineF::QLineF ( const QPointF pt1,
const QPointF pt2 
)
inline

Constructs a line object that represents the line between p1 and p2.

Definition at line 284 of file qline.h.

285  : pt1(apt1), pt2(apt2)
286 {
287 }
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ QLineF() [3/4]

QLineF::QLineF ( qreal  x1,
qreal  y1,
qreal  x2,
qreal  y2 
)
inline

Constructs a line object that represents the line between (x1, y1) and (x2, y2).

Definition at line 289 of file qline.h.

290  : pt1(x1pos, y1pos), pt2(x2pos, y2pos)
291 {
292 }
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ QLineF() [4/4]

QLineF::QLineF ( const QLine line)
inline

Construct a QLineF object from the given integer-based line.

See also
toLine()

Definition at line 220 of file qline.h.

220 : pt1(line.p1()), pt2(line.p2()) { }
QPoint p1() const
Returns the line&#39;s start point.
Definition: qline.h:132
QPoint p2() const
Returns the line&#39;s end point.
Definition: qline.h:137
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

Functions

◆ angle() [1/2]

qreal QLineF::angle ( ) const

Returns the angle of the line in degrees.

Since
4.4

The return value will be in the range of values from 0.0 up to but not including 360.0. The angles are measured counter-clockwise from a point on the x-axis to the right of the origin (x > 0).

See also
setAngle()

Definition at line 719 of file qline.cpp.

Referenced by adapted_angle_on_x(), QPainterPath::angleAtPercent(), angleTo(), and QDeclarativePinchArea::updatePinch().

720 {
721  const qreal dx = pt2.x() - pt1.x();
722  const qreal dy = pt2.y() - pt1.y();
723 
724  const qreal theta = q_rad2deg(qAtan2(-dy, dx));
725 
726  const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
727 
728  if (qFuzzyCompare(theta_normalized, qreal(360)))
729  return qreal(0);
730  else
731  return theta_normalized;
732 }
double qreal
Definition: qglobal.h:1193
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
qreal dy() const
Returns the vertical component of the line&#39;s vector.
Definition: qline.h:329
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static qreal q_rad2deg(qreal x)
Definition: qline.cpp:385
QPointF pt1
Definition: qline.h:272
qreal qAtan2(qreal x, qreal y)
Definition: qmath.h:189
qreal dx() const
Returns the horizontal component of the line&#39;s vector.
Definition: qline.h:324
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ angle() [2/2]

qreal QLineF::angle ( const QLineF line) const

Returns the angle (in degrees) between this line and the given line, taking the direction of the lines into account.

If the lines do not intersect within their range, it is the intersection point of the extended lines that serves as origin (see QLineF::UnboundedIntersection).

qlinef-angle-identicaldirection.png
qlinef-angle-oppositedirection.png

When the lines are parallel, this function returns 0 if they have the same direction; otherwise it returns 180.

See also
intersect()

Definition at line 993 of file qline.cpp.

994 {
995  if (isNull() || l.isNull())
996  return 0;
997  qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());
998  qreal rad = 0;
999  // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)
1000  if (cos_line >= qreal(-1.0) && cos_line <= qreal(1.0)) rad = qAcos( cos_line );
1001  return q_rad2deg(rad);
1002 }
double qreal
Definition: qglobal.h:1193
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
qreal dy() const
Returns the vertical component of the line&#39;s vector.
Definition: qline.h:329
static qreal q_rad2deg(qreal x)
Definition: qline.cpp:385
qreal dx() const
Returns the horizontal component of the line&#39;s vector.
Definition: qline.h:324
qreal qAcos(qreal v)
Definition: qmath.h:141
QFactoryLoader * l
bool isNull() const
Returns true if the line is not set up with valid start and end point; otherwise returns false...
Definition: qline.cpp:517

◆ angleTo()

qreal QLineF::angleTo ( const QLineF line) const

Returns the angle (in positive degrees) from this line to the given line, taking the direction of the lines into account.

Since
4.4

If the lines do not intersect within their range, it is the intersection point of the extended lines that serves as origin (see QLineF::UnboundedIntersection).

The returned value represents the number of degrees you need to add to this line to make it have the same angle as the given line, going counter-clockwise.

See also
intersect()

Definition at line 951 of file qline.cpp.

952 {
953  if (isNull() || l.isNull())
954  return 0;
955 
956  const qreal a1 = angle();
957  const qreal a2 = l.angle();
958 
959  const qreal delta = a2 - a1;
960  const qreal delta_normalized = delta < 0 ? delta + 360 : delta;
961 
962  if (qFuzzyCompare(delta, qreal(360)))
963  return 0;
964  else
965  return delta_normalized;
966 }
double qreal
Definition: qglobal.h:1193
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
qreal angle() const
Returns the angle of the line in degrees.
Definition: qline.cpp:719
QFactoryLoader * l
bool isNull() const
Returns true if the line is not set up with valid start and end point; otherwise returns false...
Definition: qline.cpp:517

◆ dx()

qreal QLineF::dx ( ) const
inline

Returns the horizontal component of the line's vector.

Return value is positive if x2() >= x1() and negative if x2() < x1().

See also
dy(), pointAt()

Definition at line 324 of file qline.h.

Referenced by angle(), QStroker::joinPoints(), QBezier::midTangent(), normalVector(), qt_stroke_side(), setAngle(), and setLength().

325 {
326  return pt2.x() - pt1.x();
327 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ dy()

qreal QLineF::dy ( ) const
inline

Returns the vertical component of the line's vector.

Return value is positive if y2() >= y1() and negative if y2() < y1().

See also
dx(), pointAt()

Definition at line 329 of file qline.h.

Referenced by adapted_angle_on_x(), angle(), QStroker::joinPoints(), QBezier::midTangent(), normalVector(), qt_stroke_side(), setAngle(), and setLength().

330 {
331  return pt2.y() - pt1.y();
332 }
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ fromPolar()

QLineF QLineF::fromPolar ( qreal  length,
qreal  angle 
)
static

Returns a QLineF with the given length and angle.

Since
4.4

The first point of the line will be on the origin.

Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

Definition at line 774 of file qline.cpp.

775 {
776  const qreal angleR = q_deg2rad(angle);
777  return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
778 }
double qreal
Definition: qglobal.h:1193
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
qreal qSin(qreal v)
Definition: qmath.h:93
static qreal q_deg2rad(qreal x)
Definition: qline.cpp:380
qreal angle() const
Returns the angle of the line in degrees.
Definition: qline.cpp:719
QLineF()
Constructs a null line.
Definition: qline.h:280
qreal qCos(qreal v)
Definition: qmath.h:109

◆ intersect()

QLineF::IntersectType QLineF::intersect ( const QLineF line,
QPointF intersectionPoint 
) const

Returns a value indicating whether or not this line intersects with the given line.

The actual intersection point is extracted to intersectionPoint (if the pointer is valid). If the lines are parallel, the intersection point is undefined.

Definition at line 813 of file qline.cpp.

Referenced by QStroker::joinPoints().

814 {
815  // ipmlementation is based on Graphics Gems III's "Faster Line Segment Intersection"
816  const QPointF a = pt2 - pt1;
817  const QPointF b = l.pt1 - l.pt2;
818  const QPointF c = pt1 - l.pt1;
819 
820  const qreal denominator = a.y() * b.x() - a.x() * b.y();
821  if (denominator == 0 || !qt_is_finite(denominator))
822  return NoIntersection;
823 
824  const qreal reciprocal = 1 / denominator;
825  const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal;
826  if (intersectionPoint)
827  *intersectionPoint = pt1 + a * na;
828 
829  if (na < 0 || na > 1)
830  return UnboundedIntersection;
831 
832  const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal;
833  if (nb < 0 || nb > 1)
834  return UnboundedIntersection;
835 
836  return BoundedIntersection;
837 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
long ASN1_INTEGER_get ASN1_INTEGER * a
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt1
Definition: qline.h:272
QFactoryLoader * l
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ isNull()

bool QLineF::isNull ( ) const

Returns true if the line is not set up with valid start and end point; otherwise returns false.

Definition at line 517 of file qline.cpp.

Referenced by angle(), angleTo(), QBezier::endTangent(), setLength(), and QBezier::startTangent().

518 {
519  return (qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y())) ? true : false;
520 }
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ length()

qreal QLineF::length ( ) const

Returns the length of the line.

See also
setLength()

Definition at line 698 of file qline.cpp.

Referenced by QBezier::addIfClose(), angle(), bezierAtT(), QStroker::joinPoints(), nextBezier(), QPainterPath::percentAtLength(), qt_radial_gradient_adapt_focal_point(), QRasterPaintEnginePrivate::rasterizeLine_dashed(), setAngle(), QRasterPaintEngine::stroke(), and unitVector().

699 {
700  qreal x = pt2.x() - pt1.x();
701  qreal y = pt2.y() - pt1.y();
702  return qSqrt(x*x + y*y);
703 }
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ normalVector()

QLineF QLineF::normalVector ( ) const
inline

Returns a line that is perpendicular to this line with the same starting point and length.

qlinef-normalvector.png
See also
unitVector()

Definition at line 334 of file qline.h.

Referenced by qt_stroke_side(), and shift().

335 {
336  return QLineF(p1(), p1() + QPointF(dy(), -dx()));
337 }
QPointF p1() const
Returns the line&#39;s start point.
Definition: qline.h:314
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal dy() const
Returns the vertical component of the line&#39;s vector.
Definition: qline.h:329
qreal dx() const
Returns the horizontal component of the line&#39;s vector.
Definition: qline.h:324
QLineF()
Constructs a null line.
Definition: qline.h:280

◆ operator!=()

bool QLineF::operator!= ( const QLineF line) const
inline

Returns true if the given line is not the same as this line.

A line is different from another line if their start or end points differ, or the internal order of the points is different.

Definition at line 267 of file qline.h.

267 { return !(*this == d); }
double d
Definition: qnumeric_p.h:62

◆ operator==()

bool QLineF::operator== ( const QLineF line) const
inline

Returns true if the given line is the same as 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.

Definition at line 404 of file qline.h.

405 {
406  return pt1 == d.pt1 && pt2 == d.pt2;
407 }
double d
Definition: qnumeric_p.h:62
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ p1()

QPointF QLineF::p1 ( ) const
inline

◆ p2()

QPointF QLineF::p2 ( ) const
inline

◆ pointAt()

QPointF QLineF::pointAt ( qreal  t) const
inline

Returns the point at the parameterized position specified by t.

The function returns the line's start point if t = 0, and its end point if t = 1.

See also
dx(), dy()

Definition at line 368 of file qline.h.

369 {
370  qreal vx = pt2.x() - pt1.x();
371  qreal vy = pt2.y() - pt1.y();
372  return QPointF(pt1.x() + vx * t, pt1.y() + vy * t);
373 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ setAngle()

void QLineF::setAngle ( qreal  angle)

Sets the angle of the line to the given angle (in degrees).

Since
4.4

This will change the position of the second point of the line such that the line has the given angle.

Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

See also
angle()

Definition at line 749 of file qline.cpp.

750 {
751  const qreal angleR = q_deg2rad(angle);
752  const qreal l = length();
753 
754  const qreal dx = qCos(angleR) * l;
755  const qreal dy = -qSin(angleR) * l;
756 
757  pt2.rx() = pt1.x() + dx;
758  pt2.ry() = pt1.y() + dy;
759 }
double qreal
Definition: qglobal.h:1193
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
qreal dy() const
Returns the vertical component of the line&#39;s vector.
Definition: qline.h:329
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
QPointF pt1
Definition: qline.h:272
qreal qSin(qreal v)
Definition: qmath.h:93
static qreal q_deg2rad(qreal x)
Definition: qline.cpp:380
qreal angle() const
Returns the angle of the line in degrees.
Definition: qline.cpp:719
qreal dx() const
Returns the horizontal component of the line&#39;s vector.
Definition: qline.h:324
QFactoryLoader * l
QPointF pt2
Definition: qline.h:272
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal qCos(qreal v)
Definition: qmath.h:109

◆ setLength()

void QLineF::setLength ( qreal  length)
inline

Sets the length of the line to the given length.

QLineF will move the end point - p2() - of the line to give the line its new length. If the given length is negative the angle() is also changed.

If the line is a null line, the length will remain zero regardless of the length specified.

See also
length(), isNull()

Definition at line 360 of file qline.h.

Referenced by QStroker::joinPoints(), qt_radial_gradient_adapt_focal_point(), qt_stroke_side(), and QRasterPaintEnginePrivate::rasterizeLine_dashed().

361 {
362  if (isNull())
363  return;
364  QLineF v = unitVector();
365  pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len);
366 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal dy() const
Returns the vertical component of the line&#39;s vector.
Definition: qline.h:329
QLineF unitVector() const
Returns the unit vector for this line, i.e a line starting at the same point as this line with a leng...
Definition: qline.cpp:786
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QPointF pt1
Definition: qline.h:272
qreal dx() const
Returns the horizontal component of the line&#39;s vector.
Definition: qline.h:324
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool isNull() const
Returns true if the line is not set up with valid start and end point; otherwise returns false...
Definition: qline.cpp:517

◆ setLine()

void QLineF::setLine ( qreal  x1,
qreal  y1,
qreal  x2,
qreal  y2 
)
inline

Sets this line to the start in x1, y1 and end in x2, y2.

Since
4.4
See also
setP1(), setP2(), p1(), p2()

Definition at line 397 of file qline.h.

398 {
399  pt1 = QPointF(aX1, aY1);
400  pt2 = QPointF(aX2, aY2);
401 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ setP1()

void QLineF::setP1 ( const QPointF p1)
inline

Sets the starting point of this line to p1.

Since
4.4
See also
setP2(), p1()

Definition at line 381 of file qline.h.

Referenced by QRasterPaintEnginePrivate::rasterizeLine_dashed().

382 {
383  pt1 = aP1;
384 }
QPointF pt1
Definition: qline.h:272

◆ setP2()

void QLineF::setP2 ( const QPointF p2)
inline

Sets the end point of this line to p2.

Since
4.4
See also
setP1(), p2()

Definition at line 386 of file qline.h.

387 {
388  pt2 = aP2;
389 }
QPointF pt2
Definition: qline.h:272

◆ setPoints()

void QLineF::setPoints ( const QPointF p1,
const QPointF p2 
)
inline

Sets the start point of this line to p1 and the end point of this line to p2.

Since
4.4
See also
setP1(), setP2(), p1(), p2()

Definition at line 391 of file qline.h.

392 {
393  pt1 = aP1;
394  pt2 = aP2;
395 }
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ toLine()

QLine QLineF::toLine ( ) const
inline

Returns an integer based copy of this line.

Note that the returned line's start and end points are rounded to the nearest integer.

See also
QLineF()

Definition at line 375 of file qline.h.

376 {
377  return QLine(pt1.toPoint(), pt2.toPoint());
378 }
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
QPointF pt1
Definition: qline.h:272
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
QPointF pt2
Definition: qline.h:272

◆ translate() [1/2]

void QLineF::translate ( const QPointF p)
inline

Translates this line by the given offset.

Definition at line 339 of file qline.h.

Referenced by QPainter::drawLines(), drawTextItemDecoration(), QStroker::joinPoints(), qt_stroke_side(), and translate().

340 {
341  pt1 += point;
342  pt2 += point;
343 }
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272

◆ translate() [2/2]

void QLineF::translate ( qreal  dx,
qreal  dy 
)
inline

Translates this line the distance specified by dx and dy.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 345 of file qline.h.

346 {
347  this->translate(QPointF(adx, ady));
348 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void translate(const QPointF &p)
Translates this line by the given offset.
Definition: qline.h:339

◆ translated() [1/2]

QLineF QLineF::translated ( const QPointF offset) const
inline

Returns this line translated by the given offset.

Since
4.4

Definition at line 350 of file qline.h.

Referenced by translated().

351 {
352  return QLineF(pt1 + p, pt2 + p);
353 }
QPointF pt1
Definition: qline.h:272
QPointF pt2
Definition: qline.h:272
QLineF()
Constructs a null line.
Definition: qline.h:280

◆ translated() [2/2]

QLineF QLineF::translated ( qreal  dx,
qreal  dy 
) const
inline

Returns this line translated the distance specified by dx and dy.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.4

Definition at line 355 of file qline.h.

356 {
357  return translated(QPointF(adx, ady));
358 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QLineF translated(const QPointF &p) const
Returns this line translated by the given offset.
Definition: qline.h:350

◆ unitVector()

QLineF QLineF::unitVector ( ) const

Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0.

See also
normalVector()

Definition at line 786 of file qline.cpp.

Referenced by setLength(), and shift().

787 {
788  qreal x = pt2.x() - pt1.x();
789  qreal y = pt2.y() - pt1.y();
790 
791  qreal len = qSqrt(x*x + y*y);
792  QLineF f(p1(), QPointF(pt1.x() + x/len, pt1.y() + y/len));
793 
794 #ifndef QT_NO_DEBUG
795  if (qAbs(f.length() - 1) >= 0.001)
796  qWarning("QLine::unitVector: New line does not have unit length");
797 #endif
798 
799  return f;
800 }
double qreal
Definition: qglobal.h:1193
QPointF p1() const
Returns the line&#39;s start point.
Definition: qline.h:314
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QPointF pt1
Definition: qline.h:272
Q_CORE_EXPORT void qWarning(const char *,...)
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ x1()

qreal QLineF::x1 ( ) const
inline

Returns the x-coordinate of the line's start point.

See also
p1()

Definition at line 294 of file qline.h.

Referenced by clipLine(), QX11PaintEngine::drawLines(), QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QStroker::joinPoints(), QTransform::map(), and qt_stroke_side().

295 {
296  return pt1.x();
297 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt1
Definition: qline.h:272

◆ x2()

qreal QLineF::x2 ( ) const
inline

Returns the x-coordinate of the line's end point.

See also
p2()

Definition at line 304 of file qline.h.

Referenced by clipLine(), QX11PaintEngine::drawLines(), QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QStroker::joinPoints(), QTransform::map(), and qt_stroke_side().

305 {
306  return pt2.x();
307 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF pt2
Definition: qline.h:272

◆ y1()

qreal QLineF::y1 ( ) const
inline

Returns the y-coordinate of the line's start point.

See also
p1()

Definition at line 299 of file qline.h.

Referenced by clipLine(), QX11PaintEngine::drawLines(), QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QStroker::joinPoints(), QTransform::map(), and qt_stroke_side().

300 {
301  return pt1.y();
302 }
QPointF pt1
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ y2()

qreal QLineF::y2 ( ) const
inline

Returns the y-coordinate of the line's end point.

See also
p2()

Definition at line 309 of file qline.h.

Referenced by clipLine(), QX11PaintEngine::drawLines(), QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QStroker::joinPoints(), QTransform::map(), and qt_stroke_side().

310 {
311  return pt2.y();
312 }
QPointF pt2
Definition: qline.h:272
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

Friends and Related Functions

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QLineF line 
)
related

Writes the given line to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1026 of file qline.cpp.

Referenced by operator==().

1027 {
1028  stream << line.p1() << line.p2();
1029  return stream;
1030 }
QPointF p1() const
Returns the line&#39;s start point.
Definition: qline.h:314
static FILE * stream
QPointF p2() const
Returns the line&#39;s end point.
Definition: qline.h:319

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QLineF line 
)
related

Reads a line from the given stream into the given line and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1044 of file qline.cpp.

Referenced by operator==().

1045 {
1046  QPointF start, end;
1047  stream >> start;
1048  stream >> end;
1049  line = QLineF(start, end);
1050 
1051  return stream;
1052 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static FILE * stream
QLineF()
Constructs a null line.
Definition: qline.h:280
static const KeyPair *const end

Properties

◆ pt1

QPointF QLineF::pt1
private

◆ pt2

QPointF QLineF::pt2
private

The documentation for this class was generated from the following files: