diff options
Diffstat (limited to 'src/corelib/tools/qline.h')
-rw-r--r-- | src/corelib/tools/qline.h | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index 2b687c1a0a..b2f8f491ed 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -378,12 +378,11 @@ Q_DECL_CONSTEXPR inline QPointF QLineF::center() const inline void QLineF::setLength(qreal len) { - if (isNull()) - return; - Q_ASSERT(length() > 0); - const QLineF v = unitVector(); - len /= v.length(); // In case it's not quite exactly 1. - pt2 = QPointF(pt1.x() + len * v.dx(), pt1.y() + len * v.dy()); + 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 |