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