Engauge Digitizer  2
 All Classes Functions Variables Typedefs Enumerations 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 NO_RESET = false;
34  const bool NO_EXPORT_ONLY = false;
35  const bool NO_EXTRACT_IMAGE_ONLY = false;
36  const QString NO_EXTRACT_IMAGE_EXTENSION;
37  const bool DEBUG_FLAG = false;
38  const QStringList NO_LOAD_STARTUP_FILES;
39  const QStringList NO_COMMAND_LINE;
40 
41  initializeLogging ("engauge_test",
42  "engauge_test.log",
43  DEBUG_FLAG);
44 
45  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
46  NO_REGRESSION_OPEN_FILE,
47  NO_REGRESSION_IMPORT,
48  NO_GNUPLOT_LOG_FILES,
49  NO_RESET,
50  NO_EXPORT_ONLY,
51  NO_EXTRACT_IMAGE_ONLY,
52  NO_EXTRACT_IMAGE_EXTENSION,
53  NO_LOAD_STARTUP_FILES,
54  NO_COMMAND_LINE);
55  w.show ();
56 }
57 
58 void TestProjectedPoint::testProjectedPoints ()
59 {
60  double radiusCircle = 1.0, radiusProjection = 2.0 * radiusCircle;
61  double xToProjectRight = radiusProjection, yToProjectRight = 0.0;
62  double xToProjectUp = 0.0, yToProjectUp = 2.0 * radiusCircle;
63  double xProjectionRight, yProjectionRight, projectedDistanceOutsideLineRight;
64  double xProjectionUp, yProjectionUp, projectedDistanceOutsideLineUp;
65  double distanceToLine; // Ignored
66 
67  // To prevent ambiguity at multiples of angleCriticalRight and angleCriticalUp, the angle step is NOT a factor of the
68  // critical angles
69  int angleStep = 13;
70 
71  // Critical angle in degrees
72  int angleCriticalRight = (int) (0.5 + qAcos (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
73  int angleCriticalUp = (int) (0.5 + qAsin (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
74 
75  for (int angle = 0; angle <= 360; angle += angleStep) {
76 
77  double xStart = radiusCircle * cos (angle * PI / 180.0);
78  double yStart = radiusCircle * sin (angle * PI / 180.0);
79  double xStop = -1.0 * xStart;
80  double yStop = -1.0 * yStart;
81 
82  double xMin = qMin (xStart, xStop);
83  double yMin = qMin (yStart, yStop);
84  double xMax = qMax (xStart, xStop);
85  double yMax = qMax (yStart, yStop);
86 
87  // Project point on right
88  projectPointOntoLine (xToProjectRight,
89  yToProjectRight,
90  xStart,
91  yStart,
92  xStop,
93  yStop,
94  &xProjectionRight,
95  &yProjectionRight,
96  &projectedDistanceOutsideLineRight,
97  &distanceToLine);
98 
99  // If and only if angle is between angleCritical to 180 - angleCritical, and
100  // 180 + angleCritical to 360 - angleCritical will there be a projection inside the line
101  if ((angleCriticalRight <= angle && angle <= 180 - angleCriticalRight) ||
102  (180 + angleCriticalRight <= angle && angle <= 360 - angleCriticalRight)) {
103 
104  QVERIFY ((projectedDistanceOutsideLineRight == 0));
105  } else {
106  QVERIFY ((projectedDistanceOutsideLineRight != 0));
107  }
108  QVERIFY ((xMin <= xProjectionRight));
109  QVERIFY ((yMin <= yProjectionRight));
110  QVERIFY ((xProjectionRight <= xMax));
111  QVERIFY ((yProjectionRight <= yMax));
112 
113  // Project point that is up
114  projectPointOntoLine (xToProjectUp,
115  yToProjectUp,
116  xStart,
117  yStart,
118  xStop,
119  yStop,
120  &xProjectionUp,
121  &yProjectionUp,
122  &projectedDistanceOutsideLineUp,
123  &distanceToLine);
124 
125  // If and only if angle is between -angleCritical to angleCritical, and
126  // 180 - angleCritical to 180 + angleCritical will there be a projection inside the line
127  if ((angle <= angleCriticalUp) ||
128  (180 - angleCriticalUp <= angle && angle <= 180 + angleCriticalUp) ||
129  (360 - angleCriticalUp <= angle)) {
130 
131  QVERIFY ((projectedDistanceOutsideLineUp == 0));
132  } else {
133  QVERIFY ((projectedDistanceOutsideLineUp != 0));
134  }
135  QVERIFY ((xMin <= xProjectionUp));
136  QVERIFY ((yMin <= yProjectionUp));
137  QVERIFY ((xProjectionUp <= xMax));
138  QVERIFY ((yProjectionUp <= yMax));
139  }
140 }
Unit test of spline library.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:91