Engauge Digitizer
2
Main Page
Classes
Files
File List
File Members
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
bool
NO_GNUPLOT_LOG_FILES =
false
;
27
const
bool
DEBUG_FLAG =
false
;
28
const
QStringList NO_LOAD_STARTUP_FILES;
29
30
initializeLogging (
"engauge_test"
,
31
"engauge_test.log"
,
32
DEBUG_FLAG);
33
34
MainWindow
w (NO_ERROR_REPORT_LOG_FILE,
35
NO_GNUPLOT_LOG_FILES,
36
NO_LOAD_STARTUP_FILES);
37
w.show ();
38
}
39
40
void
TestSpline::testSplinesAsControlPoints ()
41
{
42
const
int
T_START = 1, T_STOP = 7;
43
const
double
SPLINE_EPSILON = 0.01;
44
const
int
NUM_T = 60;
45
46
bool
success =
true
;
47
48
vector<double> t;
49
vector<SplinePair> xy;
50
51
// Independent variable must be evenly spaced
52
t.push_back (T_START);
53
t.push_back (2);
54
t.push_back (3);
55
t.push_back (4);
56
t.push_back (5);
57
t.push_back (6);
58
t.push_back (T_STOP);
59
60
// Simple curve, with x values tweaked slightly (from even spacing) to make the test data more stressing
61
xy.push_back (
SplinePair
(1, 0.22));
62
xy.push_back (
SplinePair
(1.8, 0.04));
63
xy.push_back (
SplinePair
(3.2, -0.13));
64
xy.push_back (
SplinePair
(4.3, -0.17));
65
xy.push_back (
SplinePair
(5, -0.04));
66
xy.push_back (
SplinePair
(5.8, 0.09));
67
xy.push_back (
SplinePair
(7, 0.11));
68
69
Spline
s (t, xy);
70
71
for
(
int
i = 0; i <= NUM_T; i++) {
72
double
t = T_START + (double) i * (T_STOP - T_START) / (double) NUM_T;
73
SplinePair
spCoeff = s.interpolateCoeff (t);
74
SplinePair
spBezier = s.interpolateControlPoints (t);
75
76
double
xCoeff = spCoeff.
x
();
77
double
yCoeff = spCoeff.
y
();
78
double
xControl = spBezier.
x
();
79
double
yControl = spBezier.
y
();
80
81
if
(qAbs (xCoeff - xControl) > SPLINE_EPSILON) {
82
success =
false
;
83
}
84
85
if
(qAbs (yCoeff - yControl) > SPLINE_EPSILON) {
86
success =
false
;
87
}
88
}
89
90
QVERIFY (success);
91
}
Spline
Cubic interpolation given independent and dependent value vectors.
Definition:
Spline.h:15
std
SplinePair::y
double y() const
Get method for y.
Definition:
SplinePair.cpp:65
SplinePair::x
double x() const
Get method for x.
Definition:
SplinePair.cpp:60
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:66
SplinePair
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition:
SplinePair.h:5
Generated on Mon Feb 15 2016 14:26:00 for Engauge Digitizer by
1.8.10