File indexing completed on 2024-04-28 15:11:58

0001 /*
0002     SPDX-FileCopyrightText: 2023 Hy Murveit <hy@murveit.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006     Test for rectangleoverlap.cpp
0007 */
0008 
0009 #include "testrectangleoverlap.h"
0010 #include "auxiliary/rectangleoverlap.h"
0011 
0012 #include <QTest>
0013 
0014 TestRectangleOverlap::TestRectangleOverlap(QObject * parent): QObject(parent)
0015 {
0016 }
0017 
0018 void TestRectangleOverlap::testBasic_data()
0019 {
0020 #if QT_VERSION < 0x050900
0021     QSKIP("Skipping fixture-based test on old QT version.");
0022 #else
0023     QTest::addColumn<double>("refCenterX");
0024     QTest::addColumn<double>("refCenterY");
0025     QTest::addColumn<int>("refWidth");
0026     QTest::addColumn<int>("refHeight");
0027     QTest::addColumn<double>("refRotation");
0028     QTest::addColumn<double>("testCenterX");
0029     QTest::addColumn<double>("testCenterY");
0030     QTest::addColumn<int>("testWidth");
0031     QTest::addColumn<int>("testHeight");
0032     QTest::addColumn<double>("testRotation");
0033     QTest::addColumn<bool>("isOverlapped");
0034 
0035     //                     center   width height  angle     center   width height  angle   overlaps
0036     QTest::newRow("") << 2.0 << 4.5 << 2 << 2 <<   0.0 << 2.0 << 6.0 << 4 << 2 <<  45.0 << true;
0037     QTest::newRow("") << 1.0 << 1.0 << 1 << 1 <<   0.0 << 5.0 << 5.0 << 1 << 1 <<   0.0 << false;
0038     QTest::newRow("") << 4.0 << 4.0 << 4 << 4 <<   0.0 << 7.0 << 4.0 << 4 << 4 <<   0.0 << true;
0039     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 <<  45.0 << 6.0 << 4.0 << 2 << 2 <<   0.0 << false;
0040     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 <<  20.0 << 6.0 << 4.0 << 4 << 2 <<  20.0 << false;
0041     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 << -70.0 << 6.0 << 4.0 << 4 << 2 << -70.0 << true;
0042     QTest::newRow("") << 4.0 << 7.0 << 4 << 2 << -70.0 << 6.0 << 4.0 << 4 << 2 << -70.0 << true;
0043     QTest::newRow("") << 4.0 << 8.0 << 4 << 2 << -70.0 << 6.0 << 4.0 << 4 << 2 << -70.0 << false;
0044     QTest::newRow("") << 5.0 << 7.0 << 4 << 2 <<   0.0 << 5.0 << 4.0 << 2 << 2 <<  45.0 << false;
0045     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 <<  45.0 << 6.0 << 5.0 << 2 << 2 <<   0.0 << true;
0046     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 <<  45.0 << 6.0 << 5.0 << 2 << 2 <<  45.0 << false;
0047     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 <<  45.0 << 6.0 << 5.0 << 2 << 2 <<  35.0 << true;
0048     QTest::newRow("") << 5.0 << 5.0 << 2 << 2 <<   0.0 << 5.0 << 5.0 << 4 << 4 <<   0.0 << true;
0049     QTest::newRow("") << 5.0 << 5.0 << 4 << 4 <<   0.0 << 5.0 << 5.0 << 2 << 2 <<   0.0 << true;
0050     QTest::newRow("") << 4.0 << 6.0 << 4 << 2 <<  30.0 << 6.0 << 5.0 << 2 << 2 <<  60.0 << true;
0051     QTest::newRow("") << 6.0 << 4.0 << 2 << 2 <<   0.0 << 4.0 << 6.0 << 4 << 2 <<  45.0 << false;
0052     QTest::newRow("") << 6.0 << 4.0 << 2 << 2 <<   0.0 << 2.0 << 6.0 << 4 << 2 <<  45.0 << false;
0053     QTest::newRow("") << 2.0 << 0.6 << 2 << 2 <<   0.0 << 2.0 << 6.0 << 4 << 2 <<  45.0 << false;
0054 #endif
0055 }
0056 
0057 void TestRectangleOverlap::testBasic()
0058 {
0059 #if QT_VERSION < 0x050900
0060     QSKIP("Skipping fixture-based test on old QT version.");
0061 #else
0062     QFETCH(double, refCenterX);
0063     QFETCH(double, refCenterY);
0064     QFETCH(int, refWidth);
0065     QFETCH(int, refHeight);
0066     QFETCH(double, refRotation);
0067 
0068     QFETCH(double, testCenterX);
0069     QFETCH(double, testCenterY);
0070     QFETCH(int, testWidth);
0071     QFETCH(int, testHeight);
0072     QFETCH(double, testRotation);
0073 
0074     QFETCH(bool, isOverlapped);
0075 
0076     const RectangleOverlap overlap(QPointF(refCenterX, refCenterY), refWidth, refHeight, refRotation);
0077     const bool result = overlap.intersects(QPointF(testCenterX, testCenterY), testWidth, testHeight, testRotation);
0078 
0079     QVERIFY(result == isOverlapped);
0080 #endif
0081 }
0082 
0083 QTEST_GUILESS_MAIN(TestRectangleOverlap)