LineIteratorTest.cpp
Go to the documentation of this file.
1 /*
2  * LineIteratorTest.cpp
3  *
4  * Created on: Sep 14, 2016
5  * Author: Dominic Jud
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
11 
12 // gtest
13 #include <gtest/gtest.h>
14 
15 // Limits
16 #include <cfloat>
17 
18 using namespace grid_map;
19 
20 TEST(LineIterator, StartOutsideMap)
21 {
22  GridMap map( { "types" });
23  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
24 
25  LineIterator iterator(map, Position(2.0, 2.0), Position(0.0, 0.0));
26 
27  EXPECT_FALSE(iterator.isPastEnd());
28  EXPECT_EQ(2, (*iterator)(0));
29  EXPECT_EQ(0, (*iterator)(1));
30 
31  ++iterator;
32  EXPECT_FALSE(iterator.isPastEnd());
33  EXPECT_EQ(3, (*iterator)(0));
34  EXPECT_EQ(1, (*iterator)(1));
35 
36  ++iterator;
37  EXPECT_FALSE(iterator.isPastEnd());
38  EXPECT_EQ(4, (*iterator)(0));
39  EXPECT_EQ(2, (*iterator)(1));
40 
41  ++iterator;
42  EXPECT_TRUE(iterator.isPastEnd());
43 }
44 
45 TEST(LineIterator, EndOutsideMap)
46 {
47  GridMap map( { "types" });
48  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
49 
50  LineIterator iterator(map, Position(0.0, 0.0), Position(9.0, 6.0));
51 
52  EXPECT_FALSE(iterator.isPastEnd());
53  EXPECT_EQ(4, (*iterator)(0));
54  EXPECT_EQ(2, (*iterator)(1));
55 
56  ++iterator;
57  EXPECT_FALSE(iterator.isPastEnd());
58  EXPECT_EQ(3, (*iterator)(0));
59  EXPECT_EQ(1, (*iterator)(1));
60 
61  ++iterator;
62  EXPECT_FALSE(iterator.isPastEnd());
63  EXPECT_EQ(2, (*iterator)(0));
64  EXPECT_EQ(1, (*iterator)(1));
65 
66  ++iterator;
67  EXPECT_FALSE(iterator.isPastEnd());
68  ++iterator;
69  EXPECT_FALSE(iterator.isPastEnd());
70  ++iterator;
71  EXPECT_TRUE(iterator.isPastEnd());
72 }
73 
74 TEST(LineIterator, StartAndEndOutsideMap)
75 {
76  GridMap map( { "types" });
77  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
78 
79  LineIterator iterator(map, Position(-7.0, -9.0), Position(8.0, 8.0));
80 
81  EXPECT_FALSE(iterator.isPastEnd());
82  EXPECT_EQ(5, (*iterator)(0));
83  EXPECT_EQ(4, (*iterator)(1));
84 
85  ++iterator;
86  EXPECT_FALSE(iterator.isPastEnd());
87  EXPECT_EQ(4, (*iterator)(0));
88  EXPECT_EQ(3, (*iterator)(1));
89 
90  ++iterator;
91  EXPECT_FALSE(iterator.isPastEnd());
92  EXPECT_EQ(3, (*iterator)(0));
93  EXPECT_EQ(2, (*iterator)(1));
94 
95  ++iterator;
96  ++iterator;
97  ++iterator;
98  EXPECT_TRUE(iterator.isPastEnd());
99 }
100 
101 TEST(LineIterator, StartAndEndOutsideMapWithoutIntersectingMap)
102 {
103  GridMap map( { "types" });
104  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
105 
106  LineIterator iterator(map, Position(-8.0, 8.0), Position(8.0, 8.0));
107 
108  EXPECT_TRUE(iterator.isPastEnd());
109 }
110 
111 TEST(LineIterator, MovedMap)
112 {
113  GridMap map( { "types" });
114  map.setGeometry(Length(7.0, 5.0), 1.0, Position(0.0, 0.0));
115  map.move(Position(2.0, 2.0));
116 
117  LineIterator iterator(map, Position(0.0, 0.0), Position(2.0, 2.0));
118  Position point;
119 
120  EXPECT_FALSE(iterator.isPastEnd());
121  map.getPosition(*iterator, point);
122  EXPECT_EQ(0, point.x());
123  EXPECT_EQ(0, point.y());
124 
125  ++iterator;
126  EXPECT_FALSE(iterator.isPastEnd());
127  map.getPosition(*iterator, point);
128  EXPECT_EQ(1, point.x());
129  EXPECT_EQ(1, point.y());
130 
131  ++iterator;
132  EXPECT_FALSE(iterator.isPastEnd());
133  map.getPosition(*iterator, point);
134  EXPECT_EQ(2, point.x());
135  EXPECT_EQ(2, point.y());
136 
137  ++iterator;
138  EXPECT_TRUE(iterator.isPastEnd());
139 }
140 
141 TEST(LineIterator, StartAndEndOutsideMovedMap)
142 {
143  GridMap map( { "types" });
144  map.setGeometry(Length(7.0, 5.0), 1.0, Position(0.0, 0.0));
145  map.move(Position(2.0, 2.0));
146 
147  LineIterator iterator(map, Position(0.0, 0.0), Position(8.0, 8.0));
148  Position point;
149 
150  EXPECT_FALSE(iterator.isPastEnd());
151  map.getPosition(*iterator, point);
152  EXPECT_EQ(0, point.x());
153  EXPECT_EQ(0, point.y());
154 
155  ++iterator;
156  map.getPosition(*iterator, point);
157  EXPECT_EQ(1, point.x());
158  EXPECT_EQ(1, point.y());
159  //
160  ++iterator;
161  map.getPosition(*iterator, point);
162  EXPECT_EQ(2, point.x());
163  EXPECT_EQ(2, point.y());
164  //
165  ++iterator;
166  map.getPosition(*iterator, point);
167  EXPECT_EQ(3, point.x());
168  EXPECT_EQ(3, point.y());
169 
170  ++iterator;
171  map.getPosition(*iterator, point);
172  EXPECT_EQ(4, point.x());
173  EXPECT_EQ(4, point.y());
174 
175  ++iterator;
176  EXPECT_TRUE(iterator.isPastEnd());
177 }
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:51
TEST(LineIterator, StartOutsideMap)
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
bool isPastEnd() const


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:08