Fixed SceneCoordinate::azimuthTo() angle calculation
[situare] / tests / coordinates / scenecoordinate / testscenecoordinate.cpp
index 2a261f8..d0e18d2 100644 (file)
 const double X = 12.345678;
 const double Y = -89.765432;
 
+const double ORIGIN = 1000;
+const double DELTA = 500;
+
 class TestSceneCoordinate : public QObject
 {
     Q_OBJECT
 
 private Q_SLOTS:
+    void azimuthTo();
+    void azimuthTo_data();
     void constructors();
     void conversion();
     void conversion_data();
@@ -53,6 +58,31 @@ namespace QTest {
     }
 }
 
+void TestSceneCoordinate::azimuthTo()
+{
+    QFETCH(SceneCoordinate, to);
+    QFETCH(qreal, expectedAzimuth);
+
+    SceneCoordinate from(ORIGIN, ORIGIN);
+
+    QCOMPARE(from.azimuthTo(to), expectedAzimuth);
+}
+
+void TestSceneCoordinate::azimuthTo_data()
+{
+    QTest::addColumn<SceneCoordinate>("to");
+    QTest::addColumn<qreal>("expectedAzimuth");
+
+    QTest::newRow("N") <<  SceneCoordinate(ORIGIN, ORIGIN - DELTA) << 0.0;
+    QTest::newRow("NE") <<  SceneCoordinate(ORIGIN + DELTA, ORIGIN - DELTA) << 45.0;
+    QTest::newRow("E") <<  SceneCoordinate(ORIGIN + DELTA, ORIGIN) << 90.0;
+    QTest::newRow("SE") <<  SceneCoordinate(ORIGIN + DELTA, ORIGIN + DELTA) << 135.0;
+    QTest::newRow("S") <<  SceneCoordinate(ORIGIN, ORIGIN + DELTA) << 180.0;
+    QTest::newRow("SW") <<  SceneCoordinate(ORIGIN - DELTA, ORIGIN + DELTA) << 225.0;
+    QTest::newRow("W") <<  SceneCoordinate(ORIGIN - DELTA, ORIGIN) << 270.0;
+    QTest::newRow("NW") <<  SceneCoordinate(ORIGIN - DELTA, ORIGIN - DELTA) << 315.0;
+}
+
 void TestSceneCoordinate::constructors()
 {
     SceneCoordinate coordinate;