Skip to content

stop rejecting grid index 0 in set_value_from_xy_pos and set_value_from_xy_index#1386

Open
HrachShah wants to merge 1 commit into
AtsushiSakai:masterfrom
HrachShah:fix/grid-map-set-pos-allow-zero-index
Open

stop rejecting grid index 0 in set_value_from_xy_pos and set_value_from_xy_index#1386
HrachShah wants to merge 1 commit into
AtsushiSakai:masterfrom
HrachShah:fix/grid-map-set-pos-allow-zero-index

Conversation

@HrachShah

Copy link
Copy Markdown

GridMap.set_value_from_xy_pos used if (not x_ind) or (not y_ind): to bail out for out-of-bounds coordinates, but not 0 is True in Python, so the valid grid index 0 was always rejected. The same guard in set_value_from_xy_index also returned return False, False (a 2-tuple) from the None-guard branch while the other branches returned a plain bool, so any caller that did flag = set_value_from_xy_index(...); if flag: ... would silently get False from if (False, False): for an out-of-bounds call (which is what we want), but more importantly the set_value_from_xy_pos wrapper was throwing away values at index 0.

Swapped both guards to if (x_ind is None) or (y_ind is None):, made set_value_from_xy_index's None-branch return a plain False to match the other branches, and added a regression test in tests/test_grid_map_lib.py that sets a value at (0, 0) and confirms it lands in grid_map.data[0].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant