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 NO_RESET = false;
00034 const bool DEBUG_FLAG = false;
00035 const QStringList NO_LOAD_STARTUP_FILES;
00036
00037 initializeLogging ("engauge_test",
00038 "engauge_test.log",
00039 DEBUG_FLAG);
00040
00041 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
00042 NO_REGRESSION_OPEN_FILE,
00043 NO_GNUPLOT_LOG_FILES,
00044 NO_REGRESSION_IMPORT,
00045 NO_RESET,
00046 NO_LOAD_STARTUP_FILES);
00047 w.show ();
00048 }
00049
00050 void TestProjectedPoint::testProjectedPoints ()
00051 {
00052 double radiusCircle = 1.0, radiusProjection = 2.0 * radiusCircle;
00053 double xToProjectRight = radiusProjection, yToProjectRight = 0.0;
00054 double xToProjectUp = 0.0, yToProjectUp = 2.0 * radiusCircle;
00055 double xProjectionRight, yProjectionRight, projectedDistanceOutsideLineRight;
00056 double xProjectionUp, yProjectionUp, projectedDistanceOutsideLineUp;
00057 double distanceToLine;
00058
00059
00060
00061 int angleStep = 13;
00062
00063
00064 int angleCriticalRight = (int) (0.5 + qAcos (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
00065 int angleCriticalUp = (int) (0.5 + qAsin (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
00066
00067 for (int angle = 0; angle <= 360; angle += angleStep) {
00068
00069 double xStart = radiusCircle * cos (angle * PI / 180.0);
00070 double yStart = radiusCircle * sin (angle * PI / 180.0);
00071 double xStop = -1.0 * xStart;
00072 double yStop = -1.0 * yStart;
00073
00074 double xMin = qMin (xStart, xStop);
00075 double yMin = qMin (yStart, yStop);
00076 double xMax = qMax (xStart, xStop);
00077 double yMax = qMax (yStart, yStop);
00078
00079
00080 projectPointOntoLine (xToProjectRight,
00081 yToProjectRight,
00082 xStart,
00083 yStart,
00084 xStop,
00085 yStop,
00086 &xProjectionRight,
00087 &yProjectionRight,
00088 &projectedDistanceOutsideLineRight,
00089 &distanceToLine);
00090
00091
00092
00093 if ((angleCriticalRight <= angle && angle <= 180 - angleCriticalRight) ||
00094 (180 + angleCriticalRight <= angle && angle <= 360 - angleCriticalRight)) {
00095
00096 QVERIFY (projectedDistanceOutsideLineRight == 0);
00097 } else {
00098 QVERIFY (projectedDistanceOutsideLineRight != 0);
00099 }
00100 QVERIFY (xMin <= xProjectionRight);
00101 QVERIFY (yMin <= yProjectionRight);
00102 QVERIFY (xProjectionRight <= xMax);
00103 QVERIFY (yProjectionRight <= yMax);
00104
00105
00106 projectPointOntoLine (xToProjectUp,
00107 yToProjectUp,
00108 xStart,
00109 yStart,
00110 xStop,
00111 yStop,
00112 &xProjectionUp,
00113 &yProjectionUp,
00114 &projectedDistanceOutsideLineUp,
00115 &distanceToLine);
00116
00117
00118
00119 if ((angle <= angleCriticalUp) ||
00120 (180 - angleCriticalUp <= angle && angle <= 180 + angleCriticalUp) ||
00121 (360 - angleCriticalUp <= angle)) {
00122
00123 QVERIFY (projectedDistanceOutsideLineUp == 0);
00124 } else {
00125 QVERIFY (projectedDistanceOutsideLineUp != 0);
00126 }
00127 QVERIFY (xMin <= xProjectionUp);
00128 QVERIFY (yMin <= yProjectionUp);
00129 QVERIFY (xProjectionUp <= xMax);
00130 QVERIFY (yProjectionUp <= yMax);
00131 }
00132 }