diff options
author | Lorenz Haas <lorenz.haas@histomatics.de> | 2016-05-01 22:47:01 +0200 |
---|---|---|
committer | Lorenz Haas <lorenz.haas@histomatics.de> | 2016-05-27 08:49:44 +0000 |
commit | a7372fd79d9416d4b0de3d47ef869aff12048aa3 (patch) | |
tree | 8aeed4c5c5cf0aea1f1a87476eb750c5d9cfb187 /tests/auto/corelib/tools | |
parent | 72e084165e1e935e2ddf030481f18a77ea5b3cc2 (diff) |
Add QLineF::center() returning the point in the center of the line
[ChangeLog][QtCore][QLine/QLineF] Added center().
Change-Id: I6dcfa9e839190c0a4caf36fb6ecd01b37d65d274
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qline/tst_qline.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp index 3aee0ff17d..6e020ac35b 100644 --- a/tests/auto/corelib/tools/qline/tst_qline.cpp +++ b/tests/auto/corelib/tools/qline/tst_qline.cpp @@ -44,6 +44,12 @@ private slots: void testLength(); void testLength_data(); + void testCenter(); + void testCenter_data(); + + void testCenterF(); + void testCenterF_data(); + void testNormalVector(); void testNormalVector_data(); @@ -268,6 +274,77 @@ void tst_QLine::testLength() QCOMPARE(l.dy(), qreal(vy)); } +void tst_QLine::testCenter() +{ + QFETCH(int, x1); + QFETCH(int, y1); + QFETCH(int, x2); + QFETCH(int, y2); + QFETCH(int, centerX); + QFETCH(int, centerY); + + const QPoint c = QLine(x1, y1, x2, y2).center(); + QCOMPARE(centerX, c.x()); + QCOMPARE(centerY, c.y()); +} + +void tst_QLine::testCenter_data() +{ + QTest::addColumn<int>("x1"); + QTest::addColumn<int>("y1"); + QTest::addColumn<int>("x2"); + QTest::addColumn<int>("y2"); + QTest::addColumn<int>("centerX"); + QTest::addColumn<int>("centerY"); + + QTest::newRow("[0, 0]") << 0 << 0 << 0 << 0 << 0 << 0; + QTest::newRow("top") << 0 << 0 << 2 << 0 << 1 << 0; + QTest::newRow("right") << 0 << 0 << 0 << 2 << 0 << 1; + QTest::newRow("bottom") << 0 << 0 << -2 << 0 << -1 << 0; + QTest::newRow("left") << 0 << 0 << 0 << -2 << 0 << -1; + + QTest::newRow("precision+") << 0 << 0 << 1 << 1 << 0 << 0; + QTest::newRow("precision-") << -1 << -1 << 0 << 0 << 0 << 0; + + const int max = std::numeric_limits<int>::max(); + const int min = std::numeric_limits<int>::min(); + QTest::newRow("max") << max << max << max << max << max << max; + QTest::newRow("min") << min << min << min << min << min << min; + QTest::newRow("minmax") << min << min << max << max << 0 << 0; +} + +void tst_QLine::testCenterF() +{ + QFETCH(double, x1); + QFETCH(double, y1); + QFETCH(double, x2); + QFETCH(double, y2); + QFETCH(double, centerX); + QFETCH(double, centerY); + + const QPointF c = QLineF(x1, y1, x2, y2).center(); + QCOMPARE(centerX, c.x()); + QCOMPARE(centerY, c.y()); +} + +void tst_QLine::testCenterF_data() +{ + QTest::addColumn<double>("x1"); + QTest::addColumn<double>("y1"); + QTest::addColumn<double>("x2"); + QTest::addColumn<double>("y2"); + QTest::addColumn<double>("centerX"); + QTest::addColumn<double>("centerY"); + + QTest::newRow("[0, 0]") << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0; + QTest::newRow("top") << 0.0 << 0.0 << 1.0 << 0.0 << 0.5 << 0.0; + QTest::newRow("right") << 0.0 << 0.0 << 0.0 << 1.0 << 0.0 << 0.5; + QTest::newRow("bottom") << 0.0 << 0.0 << -1.0 << 0.0 << -0.5 << 0.0; + QTest::newRow("left") << 0.0 << 0.0 << 0.0 << -1.0 << 0.0 << -0.5; + + const double max = std::numeric_limits<qreal>::max(); + QTest::newRow("max") << max << max << max << max << max << max; +} void tst_QLine::testNormalVector_data() { |