00001 #include "Logger.h"
00002 #include "MainWindow.h"
00003 #include "mmsubs.h"
00004 #include <qmath.h>
00005 #include <QtTest/QtTest>
00006 #include "Spline.h"
00007 #include "SplinePair.h"
00008 #include "Test/TestProjectedPoint.h"
00009
00010 QTEST_MAIN (TestProjectedPoint)
00011
00012 using namespace std;
00013
00014 const double PI = 3.1415926535;
00015 const double RADIANS_TO_DEGREES = 180.0 / PI;
00016
00017 TestProjectedPoint::TestProjectedPoint(QObject *parent) :
00018 QObject(parent)
00019 {
00020 }
00021
00022 void TestProjectedPoint::cleanupTestCase ()
00023 {
00024
00025 }
00026
00027 void TestProjectedPoint::initTestCase ()
00028 {
00029 const QString NO_ERROR_REPORT_LOG_FILE;
00030 const QString NO_REGRESSION_OPEN_FILE;
00031 const bool NO_GNUPLOT_LOG_FILES = false;
00032 const bool NO_REGRESSION_IMPORT = false;
00033 const bool DEBUG_FLAG = false;
00034 const QStringList NO_LOAD_STARTUP_FILES;
00035
00036 initializeLogging ("engauge_test",
00037 "engauge_test.log",
00038 DEBUG_FLAG);
00039
00040 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
00041 NO_REGRESSION_OPEN_FILE,
00042 NO_GNUPLOT_LOG_FILES,
00043 NO_REGRESSION_IMPORT,
00044 NO_LOAD_STARTUP_FILES);
00045 w.show ();
00046 }
00047
00048 void TestProjectedPoint::testProjectedPoints ()
00049 {
00050 double radiusCircle = 1.0, radiusProjection = 2.0 * radiusCircle;
00051 double xToProjectRight = radiusProjection, yToProjectRight = 0.0;
00052 double xToProjectUp = 0.0, yToProjectUp = 2.0 * radiusCircle;
00053 double xProjectionRight, yProjectionRight, projectedDistanceOutsideLineRight;
00054 double xProjectionUp, yProjectionUp, projectedDistanceOutsideLineUp;
00055 double distanceToLine;
00056
00057
00058
00059 int angleStep = 13;
00060
00061
00062 int angleCriticalRight = (int) (0.5 + qAcos (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
00063 int angleCriticalUp = (int) (0.5 + qAsin (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
00064
00065 for (int angle = 0; angle <= 360; angle += angleStep) {
00066
00067 double xStart = radiusCircle * cos (angle * PI / 180.0);
00068 double yStart = radiusCircle * sin (angle * PI / 180.0);
00069 double xStop = -1.0 * xStart;
00070 double yStop = -1.0 * yStart;
00071
00072 double xMin = qMin (xStart, xStop);
00073 double yMin = qMin (yStart, yStop);
00074 double xMax = qMax (xStart, xStop);
00075 double yMax = qMax (yStart, yStop);
00076
00077
00078 projectPointOntoLine (xToProjectRight,
00079 yToProjectRight,
00080 xStart,
00081 yStart,
00082 xStop,
00083 yStop,
00084 &xProjectionRight,
00085 &yProjectionRight,
00086 &projectedDistanceOutsideLineRight,
00087 &distanceToLine);
00088
00089
00090
00091 if ((angleCriticalRight <= angle && angle <= 180 - angleCriticalRight) ||
00092 (180 + angleCriticalRight <= angle && angle <= 360 - angleCriticalRight)) {
00093
00094 QVERIFY (projectedDistanceOutsideLineRight == 0);
00095 } else {
00096 QVERIFY (projectedDistanceOutsideLineRight != 0);
00097 }
00098 QVERIFY (xMin <= xProjectionRight);
00099 QVERIFY (yMin <= yProjectionRight);
00100 QVERIFY (xProjectionRight <= xMax);
00101 QVERIFY (yProjectionRight <= yMax);
00102
00103
00104 projectPointOntoLine (xToProjectUp,
00105 yToProjectUp,
00106 xStart,
00107 yStart,
00108 xStop,
00109 yStop,
00110 &xProjectionUp,
00111 &yProjectionUp,
00112 &projectedDistanceOutsideLineUp,
00113 &distanceToLine);
00114
00115
00116
00117 if ((angle <= angleCriticalUp) ||
00118 (180 - angleCriticalUp <= angle && angle <= 180 + angleCriticalUp) ||
00119 (360 - angleCriticalUp <= angle)) {
00120
00121 QVERIFY (projectedDistanceOutsideLineUp == 0);
00122 } else {
00123 QVERIFY (projectedDistanceOutsideLineUp != 0);
00124 }
00125 QVERIFY (xMin <= xProjectionUp);
00126 QVERIFY (yMin <= yProjectionUp);
00127 QVERIFY (xProjectionUp <= xMax);
00128 QVERIFY (yProjectionUp <= yMax);
00129 }
00130 }