16 #include <gtest/gtest.h> 25 using namespace Eigen;
29 Eigen::Array2i submapTopLeftIndex(3, 1);
30 Eigen::Array2i submapBufferSize(3, 2);
32 Eigen::Array2i submapIndex;
35 types.push_back(
"type");
37 map.
setGeometry(Array2d(8.1, 5.1), 1.0, Vector2d(0.0, 0.0));
39 SubmapIterator iterator(map, submapTopLeftIndex, submapBufferSize);
42 EXPECT_EQ(submapTopLeftIndex(0), (*iterator)(0));
43 EXPECT_EQ(submapTopLeftIndex(1), (*iterator)(1));
49 EXPECT_EQ(3, (*iterator)(0));
50 EXPECT_EQ(2, (*iterator)(1));
56 EXPECT_EQ(4, (*iterator)(0));
57 EXPECT_EQ(1, (*iterator)(1));
63 EXPECT_EQ(4, (*iterator)(0));
64 EXPECT_EQ(2, (*iterator)(1));
70 EXPECT_EQ(5, (*iterator)(0));
71 EXPECT_EQ(1, (*iterator)(1));
77 EXPECT_EQ(5, (*iterator)(0));
78 EXPECT_EQ(2, (*iterator)(1));
84 EXPECT_EQ(5, (*iterator)(0));
85 EXPECT_EQ(2, (*iterator)(1));
91 Eigen::Array2i submapTopLeftIndex(6, 3);
92 Eigen::Array2i submapBufferSize(2, 4);
94 Eigen::Array2i submapIndex;
97 types.push_back(
"type");
102 SubmapIterator iterator(map, submapTopLeftIndex, submapBufferSize);
105 EXPECT_EQ(submapTopLeftIndex(0), (*iterator)(0));
106 EXPECT_EQ(submapTopLeftIndex(1), (*iterator)(1));
112 EXPECT_EQ(6, (*iterator)(0));
113 EXPECT_EQ(4, (*iterator)(1));
119 EXPECT_EQ(6, (*iterator)(0));
120 EXPECT_EQ(0, (*iterator)(1));
126 EXPECT_EQ(6, (*iterator)(0));
127 EXPECT_EQ(1, (*iterator)(1));
133 EXPECT_EQ(7, (*iterator)(0));
134 EXPECT_EQ(3, (*iterator)(1));
140 EXPECT_EQ(7, (*iterator)(0));
141 EXPECT_EQ(4, (*iterator)(1));
147 EXPECT_EQ(7, (*iterator)(0));
148 EXPECT_EQ(0, (*iterator)(1));
154 EXPECT_EQ(7, (*iterator)(0));
155 EXPECT_EQ(1, (*iterator)(1));
161 EXPECT_EQ(7, (*iterator)(0));
162 EXPECT_EQ(1, (*iterator)(1));
203 auto& layer = map.get(
"layer");
206 for (
size_t colIndex = 0; colIndex < layer.cols(); colIndex++) {
207 layer.col(colIndex).setConstant(colIndex);
210 std::cout <<
"(4,7) contains " << map.at(
"layer", {4, 7}) << std::endl;
215 auto checkCorrectValues = [](std::array<double, 4> given) {
216 int countOnes = 0, countTwos = 0;
217 for (
auto& value : given) {
218 if (std::abs(value - 1.0) < 1e-6) {
220 }
else if (std::abs(value - 2.0) < 1e-6) {
223 FAIL() <<
"Submap iterator returned unexpected value.";
226 EXPECT_EQ(countOnes, 2);
227 EXPECT_EQ(countTwos, 2);
230 std::array<double, 4> returnedSequence;
231 returnedSequence.fill(0);
233 for (
size_t submapIndex = 0; submapIndex < 4; submapIndex++) {
234 returnedSequence.at(submapIndex) = map.at(
"layer", *iterator);
238 checkCorrectValues(returnedSequence);
242 returnedSequence.fill(0);
243 for (
size_t submapIndex = 0; submapIndex < 4; submapIndex++) {
244 if (submapIndex == 2) {
248 returnedSequence.at(submapIndex) = map.at(
"layer", *iterator);
251 checkCorrectValues(returnedSequence);
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
TEST(SubmapIterator, Simple)
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
const Index & getSubmapIndex() const