diff options
Diffstat (limited to 'src/corelib/tools/qline.h')
-rw-r--r-- | src/corelib/tools/qline.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index d4f62024d1..b2f8f491ed 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -378,10 +378,11 @@ Q_DECL_CONSTEXPR inline QPointF QLineF::center() const inline void QLineF::setLength(qreal len) { - if (isNull()) - return; - QLineF v = unitVector(); - pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); + const qreal oldLength = length(); + // Scale len by dx() / length() and dy() / length(), two O(1) quantities, + // rather than scaling dx() and dy() by len / length(), which might overflow. + if (oldLength > 0) + pt2 = QPointF(pt1.x() + len * (dx() / oldLength), pt1.y() + len * (dy() / oldLength)); } Q_DECL_CONSTEXPR inline QPointF QLineF::pointAt(qreal t) const |