Engauge Digitizer
2
Test
TestSpline.cpp
1
#include "Logger.h"
2
#include "MainWindow.h"
3
#include <qmath.h>
4
#include <QtTest/QtTest>
5
#include "Spline.h"
6
#include "SplinePair.h"
7
#include "Test/TestSpline.h"
8
9
QTEST_MAIN (
TestSpline
)
10
11
using namespace
std
;
12
13
TestSpline::TestSpline
(QObject *parent) :
14
QObject(parent)
15
{
16
}
17
18
void
TestSpline::cleanupTestCase ()
19
{
20
21
}
22
23
void
TestSpline::initTestCase ()
24
{
25
const
QString NO_ERROR_REPORT_LOG_FILE;
26
const
QString NO_REGRESSION_OPEN_FILE;
27
const
bool
NO_GNUPLOT_LOG_FILES =
false
;
28
const
bool
NO_REGRESSION_IMPORT =
false
;
29
const
bool
NO_RESET =
false
;
30
const
bool
DEBUG_FLAG =
false
;
31
const
QStringList NO_LOAD_STARTUP_FILES;
32
33
initializeLogging (
"engauge_test"
,
34
"engauge_test.log"
,
35
DEBUG_FLAG);
36
37
MainWindow
w (NO_ERROR_REPORT_LOG_FILE,
38
NO_REGRESSION_OPEN_FILE,
39
NO_GNUPLOT_LOG_FILES,
40
NO_REGRESSION_IMPORT,
41
NO_RESET,
42
NO_LOAD_STARTUP_FILES);
43
w.show ();
44
}
45
46
void
TestSpline::testSplinesAsControlPoints ()
47
{
48
const
int
T_START = 1, T_STOP = 7;
49
const
double
SPLINE_EPSILON = 0.01;
50
const
int
NUM_T = 60;
51
52
bool
success =
true
;
53
54
vector<double> t;
55
vector<SplinePair> xy;
56
57
// Independent variable must be evenly spaced
58
t.push_back (T_START);
59
t.push_back (2);
60
t.push_back (3);
61
t.push_back (4);
62
t.push_back (5);
63
t.push_back (6);
64
t.push_back (T_STOP);
65
66
// Simple curve, with x values tweaked slightly (from even spacing) to make the test data more stressing
67
xy.push_back (
SplinePair
(1, 0.22));
68
xy.push_back (
SplinePair
(1.8, 0.04));
69
xy.push_back (
SplinePair
(3.2, -0.13));
70
xy.push_back (
SplinePair
(4.3, -0.17));
71
xy.push_back (
SplinePair
(5, -0.04));
72
xy.push_back (
SplinePair
(5.8, 0.09));
73
xy.push_back (
SplinePair
(7, 0.11));
74
75
Spline
s (t, xy);
76
77
for
(
int
i = 0; i <= NUM_T; i++) {
78
double
t = T_START + (double) i * (T_STOP - T_START) / (double) NUM_T;
79
SplinePair
spCoeff = s.
interpolateCoeff
(t);
80
SplinePair
spBezier = s.
interpolateControlPoints
(t);
81
82
double
xCoeff = spCoeff.
x
();
83
double
yCoeff = spCoeff.
y
();
84
double
xControl = spBezier.
x
();
85
double
yControl = spBezier.
y
();
86
87
if
(qAbs (xCoeff - xControl) > SPLINE_EPSILON) {
88
success =
false
;
89
}
90
91
if
(qAbs (yCoeff - yControl) > SPLINE_EPSILON) {
92
success =
false
;
93
}
94
}
95
96
QVERIFY (success);
97
}
Spline::interpolateControlPoints
SplinePair interpolateControlPoints(double t) const
Return interpolated y for specified x, for testing.
Definition:
Spline.cpp:179
Spline
Cubic interpolation given independent and dependent value vectors.
Definition:
Spline.h:21
Spline::interpolateCoeff
SplinePair interpolateCoeff(double t) const
Return interpolated y for specified x.
Definition:
Spline.cpp:166
SplinePair::y
double y() const
Get method for y.
Definition:
SplinePair.cpp:71
std
TestSpline::TestSpline
TestSpline(QObject *parent=0)
Single constructor.
Definition:
TestSpline.cpp:13
SplinePair::x
double x() const
Get method for x.
Definition:
SplinePair.cpp:66
TestSpline
Unit test of spline library.
Definition:
TestSpline.h:7
MainWindow
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition:
MainWindow.h:89
SplinePair
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition:
SplinePair.h:11
Generated on Sat Oct 21 2017 12:50:41 for Engauge Digitizer by
1.8.13