Describe the bug
_calculate_event_row_col() in xrspatial/viewshed.py ends with an internal corruption guard:
if abs(x - event_col > 1) or abs(y - event_row > 1):
raise ValueError("_calculate_event_row_col()")
Operator precedence binds > before abs(), so this evaluates as abs((x - event_col) > 1): abs() applied to a boolean comparison result, which is always 0 or 1. The guard is meant to assert that the computed (x, y) stays within one cell of (event_col, event_row), but it never actually checks that.
The function is @ngjit-compiled, so the dead guard is silent at runtime. Normal output is unaffected because the algorithm already keeps results within one cell, but the guard does not do its job.
Expected behavior
The comparison should sit outside abs() so the guard raises when the computed neighbour drifts more than one cell from the event cell:
if abs(x - event_col) > 1 or abs(y - event_row) > 1:
raise ValueError("_calculate_event_row_col()")
Additional context
Every branch of the function assigns x to event_col, event_col + 1, or event_col - 1, and likewise for y relative to event_row. The corrected guard holds for all valid inputs and will not fire spuriously. Pure internal bug fix, no public API change.
Describe the bug
_calculate_event_row_col()inxrspatial/viewshed.pyends with an internal corruption guard:Operator precedence binds
>beforeabs(), so this evaluates asabs((x - event_col) > 1):abs()applied to a boolean comparison result, which is always 0 or 1. The guard is meant to assert that the computed(x, y)stays within one cell of(event_col, event_row), but it never actually checks that.The function is
@ngjit-compiled, so the dead guard is silent at runtime. Normal output is unaffected because the algorithm already keeps results within one cell, but the guard does not do its job.Expected behavior
The comparison should sit outside
abs()so the guard raises when the computed neighbour drifts more than one cell from the event cell:Additional context
Every branch of the function assigns
xtoevent_col,event_col + 1, orevent_col - 1, and likewise foryrelative toevent_row. The corrected guard holds for all valid inputs and will not fire spuriously. Pure internal bug fix, no public API change.