summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qline.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qline.h')
-rw-r--r--src/corelib/tools/qline.h62
1 files changed, 16 insertions, 46 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h
index e35de2af6d..e23ffbe9d5 100644
--- a/src/corelib/tools/qline.h
+++ b/src/corelib/tools/qline.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QLINE_H
#define QLINE_H
@@ -44,6 +8,7 @@
QT_BEGIN_NAMESPACE
+class QLineF;
/*******************************************************************************
* class QLine
@@ -86,10 +51,12 @@ public:
constexpr inline bool operator==(const QLine &d) const noexcept;
constexpr inline bool operator!=(const QLine &d) const noexcept { return !(*this == d); }
+ [[nodiscard]] constexpr inline QLineF toLineF() const noexcept;
+
private:
QPoint pt1, pt2;
};
-Q_DECLARE_TYPEINFO(QLine, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QLine, Q_PRIMITIVE_TYPE);
/*******************************************************************************
* class QLine inline members
@@ -274,7 +241,7 @@ public:
private:
QPointF pt1, pt2;
};
-Q_DECLARE_TYPEINFO(QLineF, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QLineF, Q_PRIMITIVE_TYPE);
/*******************************************************************************
* class QLineF inline members
@@ -372,12 +339,13 @@ 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());
+ Q_ASSERT(qIsFinite(len));
+ const qreal oldLength = length();
+ Q_ASSERT(qIsFinite(oldLength));
+ // 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));
}
constexpr inline QPointF QLineF::pointAt(qreal t) const
@@ -385,6 +353,8 @@ constexpr inline QPointF QLineF::pointAt(qreal t) const
return QPointF(pt1.x() + (pt2.x() - pt1.x()) * t, pt1.y() + (pt2.y() - pt1.y()) * t);
}
+constexpr inline QLineF QLine::toLineF() const noexcept { return *this; }
+
constexpr inline QLine QLineF::toLine() const
{
return QLine(pt1.toPoint(), pt2.toPoint());