Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <vector>
00032 #include <algorithm>
00033 #include <math.h>
00034 #include <stdio.h>
00035
00036 #include <assert.h>
00037
00038 #include "BaseDistance.h"
00039
00040 #define Vector2 BaseDistance::Vector2
00041
00042 bool distance_test()
00043 {
00044 std::vector<Vector2> points;
00045 Vector2 n;
00046 double d, eps=0.00001;
00047
00048 BaseDistance tester;
00049 tester.setFootprint(0.8, -0.3, 0.5, -0.7, 0.1);
00050
00051
00052 points.push_back(Vector2(3.2f, 0.0f));
00053 d = tester.distance(points, &n);
00054 assert((d-2.4)<eps && n.x == 3.2f && n.y == 0.0f);
00055
00056 points.push_back(Vector2(0.0f, 2.8f));
00057 d = tester.distance(points, &n);
00058 assert((d-2.3 < eps) && n.x == 0.0f && n.y == 2.8f);
00059
00060 points.push_back(Vector2(0.0f, -2.9f));
00061 d = tester.distance(points, &n);
00062 assert((d-2.2 < eps) && n.x == 0.0f && n.y == -2.9f);
00063
00064 points.push_back(Vector2(-2.4f, 0.0f));
00065 d = tester.distance(points, &n);
00066 assert((d-2.1 < eps) && n.x == -2.4f && n.y == 0.0f);
00067
00068
00069
00070 points.push_back(Vector2(1.76f, 1.6f));
00071 d = tester.distance(points, &n);
00072 assert((d-1.46 < eps) && n.x == 1.76f && n.y == 1.6f);
00073
00074 points.push_back(Vector2(-1.18f, 1.55f));
00075 d = tester.distance(points, &n);
00076 assert((d-1.37 < eps) && n.x == -1.18f && n.y == 1.55f);
00077
00078 points.push_back(Vector2(-1.05f, -1.7f));
00079 d = tester.distance(points, &n);
00080 assert((d-1.25 < eps) && n.x == -1.05f && n.y == -1.7f);
00081
00082 points.push_back(Vector2(0.95f, -1.82f));
00083 d = tester.distance(points, &n);
00084 assert((d-1.13 < eps) && n.x == 0.95f && n.y == -1.82f);
00085
00086
00087
00088 for(int i=0; i < 1000; i++) {
00089 std::random_shuffle(points.begin(), points.end());
00090 d = tester.distance(points, &n);
00091 assert((d-1.13 < eps) && n.x == 0.95f && n.y == -1.82f);
00092 }
00093 return true;
00094 }
00095
00096 int main(int argc, char *argv[])
00097 {
00098 ros::init(argc, argv, "BaseDistance_test");
00099 distance_test();
00100 }