From 6068509d52f1327e7f35546b031293e182450ee5 Mon Sep 17 00:00:00 2001 From: Zo Bot Date: Sun, 21 Jun 2026 11:42:37 +0000 Subject: [PATCH] stop rejecting grid index 0 in set_value_from_xy_pos and set_value_from_xy_index --- Mapping/grid_map_lib/grid_map_lib.py | 4 ++-- tests/test_grid_map_lib.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Mapping/grid_map_lib/grid_map_lib.py b/Mapping/grid_map_lib/grid_map_lib.py index d08d8ec5ba..c06841527b 100644 --- a/Mapping/grid_map_lib/grid_map_lib.py +++ b/Mapping/grid_map_lib/grid_map_lib.py @@ -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) @@ -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) diff --git a/tests/test_grid_map_lib.py b/tests/test_grid_map_lib.py index 670b357ad3..d29330749a 100644 --- a/tests/test_grid_map_lib.py +++ b/tests/test_grid_map_lib.py @@ -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 @@ -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__)