File indexing completed on 2024-12-08 12:11:20

0001 /*
0002     SPDX-FileCopyrightText: 2016 Akarsh Simha <akarsh.simha@kdemail.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 /* Project Includes */
0008 #include "test_poleaxis.h"
0009 #include "ksnumbers.h"
0010 #include "time/kstarsdatetime.h"
0011 #include "auxiliary/dms.h"
0012 #include "Options.h"
0013 #include <libnova/libnova.h>
0014 
0015 TestPoleAxis::TestPoleAxis() : QObject()
0016 {
0017 }
0018 
0019 TestPoleAxis::~TestPoleAxis()
0020 {
0021 }
0022 
0023 void TestPoleAxis::compare(Rotations::V3 v, double x, double y, double z)
0024 {
0025     QVERIFY2(std::fabs(v.x() - x) < 0.00001,
0026              qPrintable(QString("dc.x %1, x %2 error %3").arg(v.x()).arg(x).arg(((v.x() - x) * 3600.0), 6, 'f', 1)));
0027     QVERIFY2(std::fabs(v.y() - y) < 0.00001,
0028              qPrintable(QString("dc.y %1, y %2 error %3").arg(v.y()).arg(y).arg(((v.y() - y) * 3600.0), 6, 'f', 1)));
0029     QVERIFY2(std::fabs(v.z() - z) < 0.00001,
0030              qPrintable(QString("dc.z %1, z %2 error %3").arg(v.z()).arg(z).arg(((v.z() - z) * 3600.0), 6, 'f', 1)));
0031 }
0032 
0033 void TestPoleAxis::compare(double a, double e, QString msg)
0034 {
0035     QVERIFY2(std::fabs(a - e) < 0.0003,
0036              qPrintable(QString("%1: actual %2, expected %3 error %4").arg(msg).arg(a).arg(e).arg(((a - e) * 3600.0), 6, 'f', 1)));
0037 }
0038 
0039 
0040 void TestPoleAxis::testDirCos_data()
0041 {
0042     QTest::addColumn<double>("Ha");
0043     QTest::addColumn<double>("Dec");
0044     QTest::addColumn<double>("X");
0045     QTest::addColumn<double>("Y");
0046     QTest::addColumn<double>("Z");
0047 
0048     QTest::newRow("HaDec0") << 0.0 << 0.0  << 1.0 << 0.0 << 0.0;
0049     QTest::newRow("Ha0Dec45") << 0.0 << 45.0  << 0.707107 << 0.0 << 0.707107;
0050     QTest::newRow("Ha6Dec45") << 6.0 << 45.0 << 0.0 << 0.707107 << 0.707107;
0051     QTest::newRow("Ha-6Dec45") << -6.0 << 45.0 << 0.0 << -0.707107 << 0.707107;
0052     QTest::newRow("at Pole") << 0.0 << 90.0 << 0.0 << 0.0 << 1.0;
0053     QTest::newRow("near S Pole") << -3.0 << -85.0 << 0.0616284 << -0.0616284 << -0.996195;
0054 }
0055 
0056 void TestPoleAxis::testDirCos()
0057 {
0058     dms h;
0059     dms d;
0060     QFETCH(double, Ha);
0061     QFETCH(double, Dec);
0062     h.setH(Ha);
0063     d.setD(Dec);
0064 
0065 
0066     Rotations::V3 dc;
0067     dc = PoleAxis::dirCos(h, d);
0068 
0069 
0070     QFETCH(double, X);
0071     QFETCH(double, Y);
0072     QFETCH(double, Z);
0073 
0074     compare(dc, X, Y, Z);
0075 
0076     SkyPoint sp(Ha, Dec);
0077     dc = PoleAxis::dirCos(sp);
0078     compare(dc.length(), 1.0, "length");
0079     compare(dc, X, Y, Z);
0080 }
0081 
0082 void TestPoleAxis::testPriSec_data()
0083 {
0084     testDirCos_data();
0085 }
0086 
0087 void TestPoleAxis::testPriSec()
0088 {
0089     QFETCH(double, Ha);
0090     QFETCH(double, Dec);
0091     QFETCH(double, X);
0092     QFETCH(double, Y);
0093     QFETCH(double, Z);
0094     Rotations::V3 dc(X, Y, Z);
0095     dms p = PoleAxis::primary(dc);
0096     compare(p.HoursHa(), Ha, "Ha");
0097     compare(PoleAxis::secondary(dc).Degrees(), Dec, "Dec");
0098 }
0099 
0100 
0101 void TestPoleAxis::testPoleAxis_data()
0102 {
0103     QTest::addColumn<double>("Ha1");
0104     QTest::addColumn<double>("Dec1");
0105     QTest::addColumn<double>("Ha2");
0106     QTest::addColumn<double>("Dec2");
0107     QTest::addColumn<double>("Ha3");
0108     QTest::addColumn<double>("Dec3");
0109     QTest::addColumn<double>("X");
0110     QTest::addColumn<double>("Y");
0111     QTest::addColumn<double>("Z");
0112 
0113     QTest::newRow("Ha-606Dec0") << -6.0 << 0.0 << 0.0 << 0.0  << 6.0 << 0.0  << 0.0 << 0.0 << 1.0;
0114     QTest::newRow("Ha20-2Dec89") << 2.0 << 89.0 << 0.0 << 89.0  << -2.0 << 89.0  << 0.0 << 0.0 << -1.0;
0115     QTest::newRow("Ha0-22Dec89v") << 0.0 << 89.0 << -2.0 << 89.1  << 2.0 << 88.9  << -0.0006 << -0.003386 << -0.99999;
0116     QTest::newRow("Ha2-20Dec-89") << 2.0 << -89.0  << -2.0 << -89.0 << 0.0 << -89.0  << 0.0 << 0.0 << 1.0;
0117     QTest::newRow("Ha20-2Dec89") << 2.0 << 89.0  << 0.0 << 89.0 << -2.0 << 88.0  << 0.05633683 << 0.0150954 << 0.998298;
0118     // failure cases, 2 or more points the same should ruturn a null matrix
0119     QTest::newRow("Ha000Dec0") << 0.0 << 0.0 << 0.0 << 0.0  << 0.0 << 0.0  << 0.0 << 0.0 << 0.0;
0120     QTest::newRow("Ha100Dec0") << 1.0 << 0.0 << 0.0 << 0.0  << 0.0 << 0.0  << 0.0 << 0.0 << 0.0;
0121     QTest::newRow("Ha110Dec0") << 1.0 << 0.0 << 1.0 << 0.0  << 0.0 << 0.0  << 0.0 << 0.0 << 0.0;
0122     QTest::newRow("Ha011Dec0") << 0.0 << 0.0 << 1.0 << 0.0  << 1.0 << 0.0  << 0.0 << 0.0 << 0.0;
0123 }
0124 
0125 void TestPoleAxis::testPoleAxis()
0126 {
0127     QFETCH(double, Ha1);
0128     QFETCH(double, Dec1);
0129     QFETCH(double, Ha2);
0130     QFETCH(double, Dec2);
0131     QFETCH(double, Ha3);
0132     QFETCH(double, Dec3);
0133 
0134     QFETCH(double, X);
0135     QFETCH(double, Y);
0136     QFETCH(double, Z);
0137 
0138     SkyPoint p1(Ha1, Dec1);
0139     SkyPoint p2(Ha2, Dec2);
0140     SkyPoint p3(Ha3, Dec3);
0141 
0142 
0143     Rotations::V3 pa = PoleAxis::poleAxis(p1, p2, p3);
0144 
0145     compare(pa.x(), X, "X");
0146     compare(pa.y(), Y, "Y");
0147     compare(pa.z(), Z, "Z");
0148 }
0149 
0150 QTEST_GUILESS_MAIN(TestPoleAxis)