I think this could be simplify

```
if np.all(dx < 0):
    direction = -1
else:
    raise ValueError("...")
```