QMarginsF: add qFuzzyCompare and qFuzzyIsNull overloads
[ChangeLog][QtCore][QMarginsF] Added qFuzzyCompare and qFuzzyIsNull overloads for QMarginsF Task-number: QTBUG-120308 Change-Id: I7c1ceaa9ba544458738b71bf326395eef59e7a54 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
eb178d3e51
commit
473d06970d
@ -754,6 +754,22 @@ QDebug operator<<(QDebug dbg, const QMargins &m)
|
||||
\sa QMarginsF(), QMargins::toMarginsF()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QMarginsF::qFuzzyCompare(const QMarginsF &lhs, const QMarginsF &rhs)
|
||||
\since 6.8
|
||||
|
||||
Returns \c true if \a lhs is approximately equal to \a rhs;
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QMarginsF::qFuzzyIsNull(const QMarginsF &margins)
|
||||
\since 6.8
|
||||
|
||||
Returns \c true if all components of margsins \a margins are
|
||||
approximately equal to zero; otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*****************************************************************************
|
||||
QMarginsF stream functions
|
||||
*****************************************************************************/
|
||||
|
@ -302,7 +302,7 @@ private:
|
||||
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_FLOAT_COMPARE
|
||||
friend constexpr bool comparesEqual(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
||||
friend constexpr bool qFuzzyCompare(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
||||
{
|
||||
return ((!lhs.m_left || !rhs.m_left) ? qFuzzyIsNull(lhs.m_left - rhs.m_left)
|
||||
: qFuzzyCompare(lhs.m_left, rhs.m_left))
|
||||
@ -314,6 +314,16 @@ private:
|
||||
: qFuzzyCompare(lhs.m_bottom, rhs.m_bottom));
|
||||
}
|
||||
QT_WARNING_POP
|
||||
friend constexpr bool qFuzzyIsNull(const QMarginsF &m) noexcept
|
||||
{
|
||||
return qFuzzyIsNull(m.m_left) && qFuzzyIsNull(m.m_top)
|
||||
&& qFuzzyIsNull(m.m_right) && qFuzzyIsNull(m.m_bottom);
|
||||
}
|
||||
|
||||
friend constexpr bool comparesEqual(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
||||
{
|
||||
return qFuzzyCompare(lhs, rhs);
|
||||
}
|
||||
Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QMarginsF)
|
||||
|
||||
friend constexpr bool comparesEqual(const QMarginsF &lhs, const QMargins &rhs) noexcept
|
||||
|
@ -48,6 +48,12 @@ private slots:
|
||||
void comparison_data();
|
||||
void comparison();
|
||||
|
||||
void fuzzyComparison_data();
|
||||
void fuzzyComparison();
|
||||
|
||||
void isNull_data();
|
||||
void isNull();
|
||||
|
||||
void getSetCheck();
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
void dataStreamCheck();
|
||||
@ -119,6 +125,45 @@ void tst_QMargins::comparison()
|
||||
QT_TEST_EQUALITY_OPS(lhs, rhsInt, mixedResult);
|
||||
}
|
||||
|
||||
void tst_QMargins::fuzzyComparison_data()
|
||||
{
|
||||
comparison_data();
|
||||
}
|
||||
|
||||
void tst_QMargins::fuzzyComparison()
|
||||
{
|
||||
QFETCH(const QMarginsF, lhs);
|
||||
QFETCH(const QMarginsF, rhs);
|
||||
QFETCH(const bool, floatResult);
|
||||
|
||||
QCOMPARE_EQ(qFuzzyCompare(lhs, rhs), floatResult);
|
||||
}
|
||||
|
||||
void tst_QMargins::isNull_data()
|
||||
{
|
||||
QTest::addColumn<QMarginsF>("margins");
|
||||
QTest::addColumn<bool>("result");
|
||||
|
||||
QTest::newRow("null") << QMarginsF(0.0, 0.0, 0.0, 0.0) << true;
|
||||
QTest::newRow("non_null_left") << QMarginsF(1.0, 0.0, 0.0, 0.0) << false;
|
||||
QTest::newRow("non_null_top") << QMarginsF(0.0, 0.5, 0.0, 0.0) << false;
|
||||
QTest::newRow("non_null_right") << QMarginsF(0.0, 0.0, -2.0, 0.0) << false;
|
||||
QTest::newRow("non_null_bottom") << QMarginsF(0.0, 0.0, 0.0, -0.6) << false;
|
||||
QTest::newRow("almost_null") << QMarginsF(qreal_min, -qreal_min, qreal_min, -qreal_min) << true;
|
||||
}
|
||||
|
||||
void tst_QMargins::isNull()
|
||||
{
|
||||
QFETCH(const QMarginsF, margins);
|
||||
QFETCH(const bool, result);
|
||||
|
||||
QCOMPARE_EQ(margins.isNull(), result);
|
||||
QCOMPARE_EQ(qFuzzyIsNull(margins), result);
|
||||
|
||||
const QMargins marginsInt = margins.toMargins();
|
||||
QCOMPARE_EQ(marginsInt.isNull(), result);
|
||||
}
|
||||
|
||||
// Testing get/set functions
|
||||
void tst_QMargins::getSetCheck()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user