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
15 QObject(parent)
16{
17}
18
19void TestProjectedPoint::cleanupTestCase ()
20{
21
22}
23
24void TestProjectedPoint::initTestCase ()
25{
26 const bool NO_DROP_REGRESSION = false;
27 const QString NO_ERROR_REPORT_LOG_FILE;
28 const QString NO_REGRESSION_OPEN_FILE;
29 const bool NO_GNUPLOT_LOG_FILES = false;
30 const bool NO_REGRESSION_IMPORT = false;
31 const bool NO_RESET = false;
32 const bool NO_EXPORT_ONLY = false;
33 const bool NO_EXTRACT_IMAGE_ONLY = false;
34 const QString NO_EXTRACT_IMAGE_EXTENSION;
35 const bool DEBUG_FLAG = false;
36 const QStringList NO_LOAD_STARTUP_FILES;
37 const QStringList NO_COMMAND_LINE;
38
39 initializeLogging ("engauge_test",
40 "engauge_test.log",
42
43 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
48 NO_RESET,
54 w.show ();
55}
56
57void TestProjectedPoint::testProjectedPoints ()
58{
59 double radiusCircle = 1.0, radiusProjection = 2.0 * radiusCircle;
60 double xToProjectRight = radiusProjection, yToProjectRight = 0.0;
61 double xToProjectUp = 0.0, yToProjectUp = 2.0 * radiusCircle;
62 double xProjectionRight, yProjectionRight, projectedDistanceOutsideLineRight;
63 double xProjectionUp, yProjectionUp, projectedDistanceOutsideLineUp;
64 double distanceToLine; // Ignored
65
66 // To prevent ambiguity at multiples of angleCriticalRight and angleCriticalUp, the angle step is NOT a factor of the
67 // critical angles
68 int angleStep = 13;
69
70 // Critical angle in degrees
71 int angleCriticalRight = qFloor (0.5 + qRadiansToDegrees (qAcos (radiusCircle / radiusProjection)));
72 int angleCriticalUp = qFloor (0.5 + qRadiansToDegrees (qAsin (radiusCircle / radiusProjection)));
73
74 for (int angle = 0; angle <= 360; angle += angleStep) {
75
76 double xStart = radiusCircle * cos (qDegreesToRadians ((double) angle));
77 double yStart = radiusCircle * sin (qDegreesToRadians ((double) angle));
78 double xStop = -1.0 * xStart;
79 double yStop = -1.0 * yStart;
80
81 double xMin = qMin (xStart, xStop);
82 double yMin = qMin (yStart, yStop);
83 double xMax = qMax (xStart, xStop);
84 double yMax = qMax (yStart, yStop);
85
86 // Project point on right
87 projectPointOntoLine (xToProjectRight,
88 yToProjectRight,
89 xStart,
90 yStart,
91 xStop,
92 yStop,
93 &xProjectionRight,
94 &yProjectionRight,
95 &projectedDistanceOutsideLineRight,
96 &distanceToLine);
97
98 // If and only if angle is between angleCritical to 180 - angleCritical, and
99 // 180 + angleCritical to 360 - angleCritical will there be a projection inside the line
100 if ((angleCriticalRight <= angle && angle <= 180 - angleCriticalRight) ||
101 (180 + angleCriticalRight <= angle && angle <= 360 - angleCriticalRight)) {
102
103 QVERIFY ((projectedDistanceOutsideLineRight == 0));
104 } else {
105 QVERIFY ((projectedDistanceOutsideLineRight != 0));
106 }
107 QVERIFY ((xMin <= xProjectionRight));
108 QVERIFY ((yMin <= yProjectionRight));
109 QVERIFY ((xProjectionRight <= xMax));
110 QVERIFY ((yProjectionRight <= yMax));
111
112 // Project point that is up
113 projectPointOntoLine (xToProjectUp,
114 yToProjectUp,
115 xStart,
116 yStart,
117 xStop,
118 yStop,
119 &xProjectionUp,
120 &yProjectionUp,
121 &projectedDistanceOutsideLineUp,
122 &distanceToLine);
123
124 // If and only if angle is between -angleCritical to angleCritical, and
125 // 180 - angleCritical to 180 + angleCritical will there be a projection inside the line
126 if ((angle <= angleCriticalUp) ||
127 (180 - angleCriticalUp <= angle && angle <= 180 + angleCriticalUp) ||
128 (360 - angleCriticalUp <= angle)) {
129
130 QVERIFY ((projectedDistanceOutsideLineUp == 0));
131 } else {
132 QVERIFY ((projectedDistanceOutsideLineUp != 0));
133 }
134 QVERIFY ((xMin <= xProjectionUp));
135 QVERIFY ((yMin <= yProjectionUp));
136 QVERIFY ((xProjectionUp <= xMax));
137 QVERIFY ((yProjectionUp <= yMax));
138 }
139}
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
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:251