Engauge Digitizer 2
Loading...
Searching...
No Matches
TestProjectedPoint.cpp
Go to the documentation of this file.
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"
9
10QTEST_MAIN (TestProjectedPoint)
11
12using namespace std;
13
14const double PI = 3.1415926535;
15const double RADIANS_TO_DEGREES = 180.0 / PI;
16
18 QObject(parent)
19{
20}
21
22void TestProjectedPoint::cleanupTestCase ()
23{
24
25}
26
27void TestProjectedPoint::initTestCase ()
28{
29 const bool NO_DROP_REGRESSION = false;
30 const QString NO_ERROR_REPORT_LOG_FILE;
31 const QString NO_REGRESSION_OPEN_FILE;
32 const bool NO_GNUPLOT_LOG_FILES = false;
33 const bool NO_REGRESSION_IMPORT = false;
34 const bool NO_RESET = false;
35 const bool NO_EXPORT_ONLY = false;
36 const bool NO_EXTRACT_IMAGE_ONLY = false;
37 const QString NO_EXTRACT_IMAGE_EXTENSION;
38 const bool DEBUG_FLAG = false;
39 const QStringList NO_LOAD_STARTUP_FILES;
40 const QStringList NO_COMMAND_LINE;
41
42 initializeLogging ("engauge_test",
43 "engauge_test.log",
45
46 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
51 NO_RESET,
57 w.show ();
58}
59
60void TestProjectedPoint::testProjectedPoints ()
61{
62 double radiusCircle = 1.0, radiusProjection = 2.0 * radiusCircle;
63 double xToProjectRight = radiusProjection, yToProjectRight = 0.0;
64 double xToProjectUp = 0.0, yToProjectUp = 2.0 * radiusCircle;
65 double xProjectionRight, yProjectionRight, projectedDistanceOutsideLineRight;
66 double xProjectionUp, yProjectionUp, projectedDistanceOutsideLineUp;
67 double distanceToLine; // Ignored
68
69 // To prevent ambiguity at multiples of angleCriticalRight and angleCriticalUp, the angle step is NOT a factor of the
70 // critical angles
71 int angleStep = 13;
72
73 // Critical angle in degrees
74 int angleCriticalRight = qFloor (0.5 + qAcos (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
75 int angleCriticalUp = qFloor (0.5 + qAsin (radiusCircle / radiusProjection) * RADIANS_TO_DEGREES);
76
77 for (int angle = 0; angle <= 360; angle += angleStep) {
78
79 double xStart = radiusCircle * cos (angle * PI / 180.0);
80 double yStart = radiusCircle * sin (angle * PI / 180.0);
81 double xStop = -1.0 * xStart;
82 double yStop = -1.0 * yStart;
83
84 double xMin = qMin (xStart, xStop);
85 double yMin = qMin (yStart, yStop);
86 double xMax = qMax (xStart, xStop);
87 double yMax = qMax (yStart, yStop);
88
89 // Project point on right
90 projectPointOntoLine (xToProjectRight,
91 yToProjectRight,
92 xStart,
93 yStart,
94 xStop,
95 yStop,
96 &xProjectionRight,
97 &yProjectionRight,
98 &projectedDistanceOutsideLineRight,
99 &distanceToLine);
100
101 // If and only if angle is between angleCritical to 180 - angleCritical, and
102 // 180 + angleCritical to 360 - angleCritical will there be a projection inside the line
103 if ((angleCriticalRight <= angle && angle <= 180 - angleCriticalRight) ||
104 (180 + angleCriticalRight <= angle && angle <= 360 - angleCriticalRight)) {
105
106 QVERIFY ((projectedDistanceOutsideLineRight == 0));
107 } else {
108 QVERIFY ((projectedDistanceOutsideLineRight != 0));
109 }
110 QVERIFY ((xMin <= xProjectionRight));
111 QVERIFY ((yMin <= yProjectionRight));
112 QVERIFY ((xProjectionRight <= xMax));
113 QVERIFY ((yProjectionRight <= yMax));
114
115 // Project point that is up
116 projectPointOntoLine (xToProjectUp,
117 yToProjectUp,
118 xStart,
119 yStart,
120 xStop,
121 yStop,
122 &xProjectionUp,
123 &yProjectionUp,
124 &projectedDistanceOutsideLineUp,
125 &distanceToLine);
126
127 // If and only if angle is between -angleCritical to angleCritical, and
128 // 180 - angleCritical to 180 + angleCritical will there be a projection inside the line
129 if ((angle <= angleCriticalUp) ||
130 (180 - angleCriticalUp <= angle && angle <= 180 + angleCriticalUp) ||
131 (360 - angleCriticalUp <= angle)) {
132
133 QVERIFY ((projectedDistanceOutsideLineUp == 0));
134 } else {
135 QVERIFY ((projectedDistanceOutsideLineUp != 0));
136 }
137 QVERIFY ((xMin <= xProjectionUp));
138 QVERIFY ((yMin <= yProjectionUp));
139 QVERIFY ((xProjectionUp <= xMax));
140 QVERIFY ((yProjectionUp <= yMax));
141 }
142}
const double PI
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition Logger.cpp:21
const bool NO_EXPORT_ONLY
const QStringList NO_COMMAND_LINE
const QString NO_EXTRACT_IMAGE_EXTENSION
const QString NO_ERROR_REPORT_LOG_FILE
const bool NO_GNUPLOT_LOG_FILES
const QString NO_REGRESSION_OPEN_FILE
const QStringList NO_LOAD_STARTUP_FILES
const bool NO_REGRESSION_IMPORT
const bool NO_EXTRACT_IMAGE_ONLY
const bool NO_DROP_REGRESSION
const bool DEBUG_FLAG
const double RADIANS_TO_DEGREES
Unit test of spline library.
TestProjectedPoint(QObject *parent=0)
Single constructor.
void projectPointOntoLine(double xToProject, double yToProject, double xStart, double yStart, double xStop, double yStop, double *xProjection, double *yProjection, double *projectedDistanceOutsideLine, double *distanceToLine)
Find the projection of a point onto a line segment such that the line through the point and its proje...
Definition mmsubs.cpp:211