Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
TestProjectedPoint.cpp
1 #include "Logger.h"
2 #include "MainWindow.h"
3 #include "mmsubs.h"
4 #include <qmath.h>
5 #include <QtTest/QtTest>
6 #include "Spline.h"
7 #include "SplinePair.h"
8 #include "Test/TestProjectedPoint.h"
9 
10 QTEST_MAIN (TestProjectedPoint)
11 
12 using namespace std;
13 
14 const double PI = 3.1415926535;
15 const double RADIANS_TO_DEGREES = 180.0 / PI;
16 
18  QObject(parent)
19 {
20 }
21 
22 void TestProjectedPoint::cleanupTestCase ()
23 {
24 
25 }
26 
27 void TestProjectedPoint::initTestCase ()
28 {
29  const QString NO_ERROR_REPORT_LOG_FILE;
30  const QString NO_REGRESSION_OPEN_FILE;
31  const bool NO_GNUPLOT_LOG_FILES = false;
32  const bool NO_REGRESSION_IMPORT = false;
33  const bool DEBUG_FLAG = false;
34  const QStringList NO_LOAD_STARTUP_FILES;
35 
36  initializeLogging ("engauge_test",
37  "engauge_test.log",
38  DEBUG_FLAG);
39 
40  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
41  NO_REGRESSION_OPEN_FILE,
42  NO_GNUPLOT_LOG_FILES,
43  NO_REGRESSION_IMPORT,
44  NO_LOAD_STARTUP_FILES);
45  w.show ();
46 }
47 
48 void TestProjectedPoint::testProjectedPoints ()
49 {
50  double radiusCircle = 1.0, radiusProjection = 2.0 * radiusCircle;
51  double xToProjectRight = radiusProjection, yToProjectRight = 0.0;
52  double xToProjectUp = 0.0, yToProjectUp = 2.0 * radiusCircle;
53  double xProjectionRight, yProjectionRight, projectedDistanceOutsideLineRight;
54  double xProjectionUp, yProjectionUp, projectedDistanceOutsideLineUp;
55  double distanceToLine; // Ignored
56 
57  // To prevent ambiguity at multiples of angleCriticalRight and angleCriticalUp, the angle step is NOT a factor of the
58  // critical angles
59  int angleStep = 13;
60 
61  // Critical angle in degrees
62  int angleCriticalRight = (int) (0.5 + qAcos (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
63  int angleCriticalUp = (int) (0.5 + qAsin (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
64 
65  for (int angle = 0; angle <= 360; angle += angleStep) {
66 
67  double xStart = radiusCircle * cos (angle * PI / 180.0);
68  double yStart = radiusCircle * sin (angle * PI / 180.0);
69  double xStop = -1.0 * xStart;
70  double yStop = -1.0 * yStart;
71 
72  double xMin = qMin (xStart, xStop);
73  double yMin = qMin (yStart, yStop);
74  double xMax = qMax (xStart, xStop);
75  double yMax = qMax (yStart, yStop);
76 
77  // Project point on right
78  projectPointOntoLine (xToProjectRight,
79  yToProjectRight,
80  xStart,
81  yStart,
82  xStop,
83  yStop,
84  &xProjectionRight,
85  &yProjectionRight,
86  &projectedDistanceOutsideLineRight,
87  &distanceToLine);
88 
89  // If and only if angle is between angleCritical to 180 - angleCritical, and
90  // 180 + angleCritical to 360 - angleCritical will there be a projection inside the line
91  if ((angleCriticalRight <= angle && angle <= 180 - angleCriticalRight) ||
92  (180 + angleCriticalRight <= angle && angle <= 360 - angleCriticalRight)) {
93 
94  QVERIFY (projectedDistanceOutsideLineRight == 0);
95  } else {
96  QVERIFY (projectedDistanceOutsideLineRight != 0);
97  }
98  QVERIFY (xMin <= xProjectionRight);
99  QVERIFY (yMin <= yProjectionRight);
100  QVERIFY (xProjectionRight <= xMax);
101  QVERIFY (yProjectionRight <= yMax);
102 
103  // Project point that is up
104  projectPointOntoLine (xToProjectUp,
105  yToProjectUp,
106  xStart,
107  yStart,
108  xStop,
109  yStop,
110  &xProjectionUp,
111  &yProjectionUp,
112  &projectedDistanceOutsideLineUp,
113  &distanceToLine);
114 
115  // If and only if angle is between -angleCritical to angleCritical, and
116  // 180 - angleCritical to 180 + angleCritical will there be a projection inside the line
117  if ((angle <= angleCriticalUp) ||
118  (180 - angleCriticalUp <= angle && angle <= 180 + angleCriticalUp) ||
119  (360 - angleCriticalUp <= angle)) {
120 
121  QVERIFY (projectedDistanceOutsideLineUp == 0);
122  } else {
123  QVERIFY (projectedDistanceOutsideLineUp != 0);
124  }
125  QVERIFY (xMin <= xProjectionUp);
126  QVERIFY (yMin <= yProjectionUp);
127  QVERIFY (xProjectionUp <= xMax);
128  QVERIFY (yProjectionUp <= yMax);
129  }
130 }
Unit test of spline library.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:82