BaseDistance_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Ingo Kresse <kresse@in.tum.de>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 
31 #include <vector>
32 #include <algorithm> //random_shuffle
33 #include <math.h>
34 #include <stdio.h>
35 
36 #include <assert.h>
37 
38 #include "BaseDistance.h"
39 
40 #define Vector2 BaseDistance::Vector2
41 
43 {
44  std::vector<Vector2> points;
45  Vector2 n;
46  double d, eps=0.00001;
47 
48  BaseDistance tester;
49  tester.setFootprint(0.8, -0.3, 0.5, -0.7, 0.1);
50 
51  // edge cases
52  points.push_back(Vector2(3.2f, 0.0f));
53  d = tester.distance(points, &n);
54  assert((d-2.4)<eps && n.x == 3.2f && n.y == 0.0f);
55 
56  points.push_back(Vector2(0.0f, 2.8f));
57  d = tester.distance(points, &n);
58  assert((d-2.3 < eps) && n.x == 0.0f && n.y == 2.8f);
59 
60  points.push_back(Vector2(0.0f, -2.9f));
61  d = tester.distance(points, &n);
62  assert((d-2.2 < eps) && n.x == 0.0f && n.y == -2.9f);
63 
64  points.push_back(Vector2(-2.4f, 0.0f));
65  d = tester.distance(points, &n);
66  assert((d-2.1 < eps) && n.x == -2.4f && n.y == 0.0f);
67 
68 
69  // corner cases
70  points.push_back(Vector2(1.76f, 1.6f));
71  d = tester.distance(points, &n);
72  assert((d-1.46 < eps) && n.x == 1.76f && n.y == 1.6f);
73 
74  points.push_back(Vector2(-1.18f, 1.55f));
75  d = tester.distance(points, &n);
76  assert((d-1.37 < eps) && n.x == -1.18f && n.y == 1.55f);
77 
78  points.push_back(Vector2(-1.05f, -1.7f));
79  d = tester.distance(points, &n);
80  assert((d-1.25 < eps) && n.x == -1.05f && n.y == -1.7f);
81 
82  points.push_back(Vector2(0.95f, -1.82f));
83  d = tester.distance(points, &n);
84  assert((d-1.13 < eps) && n.x == 0.95f && n.y == -1.82f);
85 
86 
87  // check if the order matters - it should not.
88  for(int i=0; i < 1000; i++) {
89  std::random_shuffle(points.begin(), points.end());
90  d = tester.distance(points, &n);
91  assert((d-1.13 < eps) && n.x == 0.95f && n.y == -1.82f);
92  }
93  return true;
94 }
95 
96 int main(int argc, char *argv[])
97 {
98  ros::init(argc, argv, "BaseDistance_test");
99  distance_test();
100 }
d
bool distance_test()
#define Vector2
f
double distance(std::vector< Vector2 > &points, Vector2 *nearest, double dx=0, double dy=0, double dth=0)
Calculates the distance to closest of points from nearest footprint wall The distance is calculated n...
void setFootprint(double front, double rear, double left, double right, double tolerance)
Sets front_, rear_, left_, right_, tolerance_, and early_reject_distance_.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char *argv[])


nav_pcontroller
Author(s): Ingo Kresse
autogenerated on Thu Jun 6 2019 19:20:56