Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not iterate over the map when size is 0 #365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grid_map_core/src/iterators/GridMapIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GridMapIterator::GridMapIterator(const grid_map::GridMap& gridMap)
startIndex_ = gridMap.getStartIndex();
linearSize_ = size_.prod();
linearIndex_ = 0;
isPastEnd_ = false;
isPastEnd_ = linearSize_ > linearIndex_ ? false : true;
}

GridMapIterator::GridMapIterator(const GridMapIterator* other)
Expand Down
10 changes: 10 additions & 0 deletions grid_map_core/test/GridMapIteratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ TEST(GridMapIterator, LinearIndex)
EXPECT_TRUE(iterator.isPastEnd());
EXPECT_TRUE((map["layer"].array() == 1.0f).all());
}

TEST(GridMapIterator, GeometryIsNotSet)
{
grid_map::GridMap map;
grid_map::GridMapIterator iterator(map);

// If geometry of GridMap has not been set, bufferSize is by default (0,0).
// We cannot read GridMap's data as it's empty so GridMapIterator.isPastEnd() should return "true".
EXPECT_TRUE(iterator.isPastEnd());
}