summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2024-04-05 14:48:09 +0200
committerIvan Solovev <ivan.solovev@qt.io>2024-05-10 15:33:40 +0200
commit7072030d933e0575bab46994406530c8c1f81f5d (patch)
tree68ecd22e90b29aaeb94db7fb2f83a95cd7cf6851 /tests/auto/corelib/tools
parent2a847dd93b1b9cc363eefa27686d78a4bc399d1e (diff)
Fix QLineF::isNull behavior when handling zero points
QLineF::isNull was using qFuzzyCompare on the x and y components of its points, which was not working correctly if some of the components was equal to zero. The correct approach is to use qFuzzyIsNull togeter with qFuzzyCompare. This approach is already implemented in qFuzzyCompare() overload for QPointF, so just use it. Add unit-tests for QLine(F)::isNull. [ChangeLog][QtCore][QLineF] Fixed a bug when QLineF::isNull() returned incorrect result if the start or end point contained a zero component. Change-Id: I3cfe6406b1299de32fe82b1fcbfb0416f0eaac15 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qline/tst_qline.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp
index 80214707e4..3954cf5326 100644
--- a/tests/auto/corelib/tools/qline/tst_qline.cpp
+++ b/tests/auto/corelib/tools/qline/tst_qline.cpp
@@ -16,6 +16,9 @@ private slots:
void testComparison_data();
void testComparison();
+ void testIsNull_data();
+ void testIsNull();
+
void testIntersection();
void testIntersection_data();
@@ -46,6 +49,7 @@ private slots:
};
const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4;
+constexpr static qreal qreal_min = std::numeric_limits<qreal>::min();
void tst_QLine::testComparisonCompiles()
{
@@ -81,8 +85,6 @@ void tst_QLine::testComparison_data()
<< result << floatResult << mixedResult;
};
- constexpr static qreal qreal_min = std::numeric_limits<qreal>::min();
-
row(-1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, true, true, true);
row(-1.1, -0.9, 1.1, 0.9, -1.0, -1.0, 1.0, 1.0, true, false, false);
row(-1.0, -1.0, 1.0, 1.0, -0.9, -1.1, 0.9, 1.1, true, false, true);
@@ -114,6 +116,30 @@ void tst_QLine::testComparison()
QT_TEST_EQUALITY_OPS(l1f, l2, mixedResult);
}
+void tst_QLine::testIsNull_data()
+{
+ QTest::addColumn<QLineF>("lineF");
+ QTest::addColumn<bool>("result");
+ QTest::addColumn<bool>("floatResult");
+
+ QTest::newRow("non-null") << QLineF(1.0, 1.0, 2.0, 2.0) << false << false;
+ QTest::newRow("null") << QLineF(1.0, 1.0, 1.0, 1.0) << true << true;
+ QTest::newRow("null_int_non-null_float") << QLineF(1.0, 1.0, 1.1, 1.1) << true << false;
+ QTest::newRow("with_qreal_min") << QLineF(-qreal_min, qreal_min, 0.0, 0.0) << true << true;
+}
+
+void tst_QLine::testIsNull()
+{
+ QFETCH(QLineF, lineF);
+ QFETCH(bool, result);
+ QFETCH(bool, floatResult);
+
+ const QLine line = lineF.toLine();
+
+ QCOMPARE_EQ(line.isNull(), result);
+ QCOMPARE_EQ(lineF.isNull(), floatResult);
+}
+
void tst_QLine::testSet()
{
{