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