-
Notifications
You must be signed in to change notification settings - Fork 9
/
tests.hpp
66 lines (62 loc) · 2.06 KB
/
tests.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef TESTS_HPP
#define TESTS_HPP
#include "pose.h"
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include "splines.hpp"
#include "arclength-param.hpp"
using namespace std;
// ONLY include in dialog.cpp
namespace Tests {
Pose randomPose() {
double x = (rand()/(double)RAND_MAX)*HALF_FIELD_MAXX;
x *= 2*(rand()%2)-1;
double y = (rand()/(double)RAND_MAX)*HALF_FIELD_MAXY;
y *= 2*(rand()%2)-1;
double theta = normalizeAngle((rand()/(double)RAND_MAX)*M_PI*2.);
return Pose(x, y, theta);
}
CubicSpline randomCubicSpline(int nCP) {
// create random start/ end pose
Pose start = randomPose(), end = randomPose();
// add nCP random midPoints;
vector<Pose> midPoints;
for (int i = 0; i < nCP; i++) {
midPoints.push_back(randomPose());
}
return CubicSpline(start, end, midPoints);
}
void arclengthParam_test(int nTests) {
// create a random spline
CubicSpline p = randomCubicSpline(2);
Integration::refreshMatrix();
//Integration::computeInverseBezierMatrices(p);
Integration::computeSplineApprox(p);
// call arclengthParam on some u values
double full = Integration::integrate(p, 0, 1);
int maxIter, maxIterSP, maxIterB;
maxIter=maxIterSP=maxIterB=0;
double avgIter, avgIterSP, avgIterB = 0;
for (int i = 0; i < nTests; i++) {
int iter;
double s = (full*i)/nTests;
double u = Integration::getArcLengthParam(p, s, full, &iter,2);
if (iter > maxIter)
maxIter = iter;
avgIter += iter;
u = Integration::getArcLengthParam(p, s, full, &iter,0);
if (iter > maxIterSP)
maxIterSP = iter;
avgIterSP += iter;
u = Integration::getArcLengthParam(p, s, full, &iter,1);
if (iter > maxIterB)
maxIterB = iter;
avgIterB += iter;
}
qDebug() << "maxIter = " << maxIter << ", avg = " << avgIter/nTests << "maxIterSP = " << maxIterSP << ", avgSP = " << avgIterSP/nTests
<< "maxIterB = " << maxIterB << ", avgB = " << avgIterB/nTests;
}
}
#endif // TESTS_HPP