Skip to content
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
4 changes: 2 additions & 2 deletions Mapping/grid_map_lib/grid_map_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def set_value_from_xy_pos(self, x_pos, y_pos, val):

x_ind, y_ind = self.get_xy_index_from_xy_pos(x_pos, y_pos)

if (not x_ind) or (not y_ind):
if (x_ind is None) or (y_ind is None):
return False # NG

flag = self.set_value_from_xy_index(x_ind, y_ind, val)
Expand All @@ -118,7 +118,7 @@ def set_value_from_xy_index(self, x_ind, y_ind, val):
"""

if (x_ind is None) or (y_ind is None):
return False, False
return False

grid_ind = int(y_ind * self.width + x_ind)

Expand Down
19 changes: 18 additions & 1 deletion tests/test_grid_map_lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from Mapping.grid_map_lib.grid_map_lib import GridMap
from Mapping.grid_map_lib.grid_map_lib import GridMap, FloatGrid
import conftest
import numpy as np

Expand Down Expand Up @@ -36,5 +36,22 @@ def test_xy_and_grid_index_conversion():
assert y_ind == y_ind_2


def test_set_xy_pos_at_origin_index():
# Regression: the guard used to be `if (not x_ind) or (not y_ind):`
# which rejected the valid grid index 0 (since `not 0` is True in
# Python). Setting a value at the (0, 0) cell must succeed and the
# return value must be a plain `True` (not the tuple `(False, False)`
# that the previous None-guard returned).
grid_map = GridMap(4, 4, 1.0, 2.0, 2.0) # left_lower = (0, 0)
ok = grid_map.set_value_from_xy_index(0, 0, FloatGrid(0.5))
assert ok is True
assert grid_map.data[0].get_float_data() == 0.5

# And the higher-level pos API should accept the (0, 0) cell.
ok = grid_map.set_value_from_xy_pos(0.5, 0.5, FloatGrid(0.7))
assert ok is True
assert grid_map.data[0].get_float_data() == 0.7


if __name__ == '__main__':
conftest.run_this_test(__file__)