Skip to content

Add bound checks for bilinear interpolation #459

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions grid_map_core/src/GridMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Posit

getIndex(position, indices[0]);
getPosition(indices[0], point);
if (!checkIfIndexInRange(indices[0], size_)) {
return false;
}

if (position.x() >= point.x()) {
indices[1] = indices[0] + Index(-1, 0); // Second point is above first point.
Expand All @@ -790,6 +793,9 @@ bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Posit
indices[1] = indices[0] + Index(+1, 0);
idxTempDir = false;
}
if (!checkIfIndexInRange(indices[1], size_)) {
return false;
}
if (position.y() >= point.y()) {
indices[2] = indices[0] + Index(0, -1); // Third point is right of first point.
if (idxTempDir) {
Expand Down Expand Up @@ -818,6 +824,10 @@ bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Posit
idxShift[3] = 0;
}
}
if (!checkIfIndexInRange(indices[2], size_)) {
return false;
}

indices[3].x() = indices[1].x();
indices[3].y() = indices[2].y();

Expand Down