diff options
Diffstat (limited to 'src/corelib/tools/qline.cpp')
-rw-r--r-- | src/corelib/tools/qline.cpp | 127 |
1 files changed, 60 insertions, 67 deletions
diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index ebcbba0195..e313b06aa9 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -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 #include "qline.h" @@ -50,6 +14,9 @@ QT_BEGIN_NAMESPACE \class QLine \inmodule QtCore \ingroup painting + \compares equality + \compareswith equality QLineF + \endcompareswith \brief The QLine class provides a two-dimensional vector using integer precision. @@ -169,18 +136,18 @@ QT_BEGIN_NAMESPACE */ /*! - \fn bool QLine::operator!=(const QLine &line) const + \fn bool QLine::operator!=(const QLine &lhs, const QLine &rhs) - Returns \c true if the given \a line is not the same as \e this line. + Returns \c true if the line \a lhs is not the same as line \a rhs. A line is different from another line if any of their start or end points differ, or the internal order of the points is different. */ /*! - \fn bool QLine::operator==(const QLine &line) const + \fn bool QLine::operator==(const QLine &lhs, const QLine &rhs) - Returns \c true if the given \a line is the same as \e this line. + Returns \c true if the line \a lhs is the same as line \a rhs. 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. @@ -263,6 +230,15 @@ QT_BEGIN_NAMESPACE \sa setP1(), setP2(), p1(), p2() */ +/*! + \fn QLine::toLineF() const + \since 6.4 + + Returns this line as a line with floating point accuracy. + + \sa QLineF::toLine() +*/ + #ifndef QT_NO_DEBUG_STREAM @@ -315,6 +291,9 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) \class QLineF \inmodule QtCore \ingroup painting + \compares equality + \compareswith equality QLine + \endcompareswith \brief The QLineF class provides a two-dimensional vector using floating point precision. @@ -322,7 +301,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) 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 + the toLine() function to retrieve an integer-based copy of this line. \table @@ -366,7 +345,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) /*! \typealias QLineF::IntersectType - \obsolete Use QLineF::IntersectionType instead. + \deprecated Use QLineF::IntersectionType instead. */ /*! @@ -423,7 +402,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) Construct a QLineF object from the given integer-based \a line. - \sa toLine() + \sa toLine(), QLine::toLineF() */ /*! @@ -458,12 +437,12 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) /*! \fn QLine QLineF::toLine() const - Returns an integer based copy of this line. + Returns an integer-based copy of this line. Note that the returned line's start and end points are rounded to the nearest integer. - \sa QLineF() + \sa QLineF(), QLine::toLineF() */ /*! \fn qreal QLineF::x1() const @@ -516,13 +495,11 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) /*! \fn void QLineF::setLength(qreal length) - Sets the length of the line to the given \a length. QLineF will - move the end point - p2() - of the line to give the line its new length. - - A null line will not be rescaled. For non-null lines with very short lengths - (represented by denormal floating-point values), results may be imprecise. + Sets the length of the line to the given finite \a length. QLineF will move + the end point - p2() - of the line to give the line its new length, unless + length() was previously zero, in which case no scaling is attempted. - \sa length(), isNull(), unitVector() + \sa length(), unitVector() */ /*! @@ -537,18 +514,18 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) */ /*! - \fn bool QLineF::operator!=(const QLineF &line) const + \fn bool QLineF::operator!=(const QLineF &lhs, const QLineF &rhs) - Returns \c true if the given \a line is not the same as \e this line. + Returns \c true if the line \a lhs is not the same as line \a rhs. A line is different from another line if their start or end points differ, or the internal order of the points is different. */ /*! - \fn bool QLineF::operator==(const QLineF &line) const + \fn bool QLineF::operator==(const QLineF &lhs, const QLineF &rhs) - Returns \c true if the given \a line is the same as this line. + Returns \c true if the line \a lhs is the same as line \a rhs. 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. @@ -557,9 +534,8 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) /*! \fn qreal QLineF::pointAt(qreal t) const - Returns the point at the parameterized position specified by \a - t. The function returns the line's start point if t = 0, and its end - point if t = 1. + Returns the point at the position specified by finite parameter \a t. The + function returns the line's start point if t = 0, and its end point if t = 1. \sa dx(), dy() */ @@ -571,8 +547,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) */ qreal QLineF::length() const { - using std::hypot; - return hypot(dx(), dy()); + return qHypot(dx(), dy()); } /*! @@ -650,12 +625,11 @@ QLineF QLineF::fromPolar(qreal length, qreal angle) */ QLineF QLineF::unitVector() const { - qreal x = dx(); - qreal y = dy(); - using std::hypot; - qreal len = hypot(x, y); + const qreal x = dx(); + const qreal y = dy(); - QLineF f(p1(), QPointF(pt1.x() + x/len, pt1.y() + y/len)); + const qreal len = qHypot(x, y); + QLineF f(p1(), QPointF(pt1.x() + x / len, pt1.y() + y / len)); #ifndef QT_NO_DEBUG if (qAbs(f.length() - 1) >= 0.001) @@ -813,6 +787,25 @@ qreal QLineF::angleTo(const QLineF &l) const return delta_normalized; } +/*! + \fn bool QLineF::qFuzzyCompare(const QLineF &lhs, const QLineF &rhs) + \since 6.8 + + Returns \c true if line \a lhs is approximately equal to line \a rhs; + otherwise returns \c false. + + The lines are considered approximately equal if their start and end + points are approximately equal. +*/ + +/*! + \fn bool QLineF::qFuzzyIsNull(const QLineF &line) + \since 6.8 + + Returns \c true if the start point of line \a line is approximately + equal to its end point; otherwise returns \c false. +*/ + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QLineF &p) { |