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