Conversation
…dle cases with no movement (d0 == 0 and d1 == 0), vertical-only movement (d0 == 0), and horizontal-only movement (d1 == 0)
There was a problem hiding this comment.
Pull request overview
This PR updates calculate_all_coords(ends) to correctly handle edge cases where there is no movement or movement is purely vertical/horizontal, preventing invalid step sizes and division-by-zero in the line-generation logic.
Changes:
- Add an early return for the “no movement” case (
d0 == 0 and d1 == 0). - Add dedicated vertical-only (
d0 == 0) and horizontal-only (d1 == 0) coordinate generation paths. - Preserve the existing general-case line interpolation for diagonal movement.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
__init__.py
Outdated
| d0, d1 = np.diff(ends, axis=0)[0] | ||
|
|
||
| if d0 == 0 and d1 == 0: | ||
| return ends |
There was a problem hiding this comment.
In the d0 == 0 and d1 == 0 case, returning ends yields two identical points (shape (2, 2)), which then allows downstream logic (e.g., add_random_n_places in natural_mouse_movement) to introduce jitter/movement even though start==end. Consider returning a single-point path instead (e.g., just the start/end point) and cast to the same dtype as other branches (int32) for consistency.
| return ends | |
| # Start and end are the same point: return a single-point path as int32 for consistency. | |
| return ends[[0]].astype(np.int32, copy=False) |
…duplicate low level function SendInput
Update calculate_all_coords(ends) to handle cases with no movement (d0 == 0 and d1 == 0), vertical-only movement (d0 == 0), and horizontal-only movement (d1 == 0)