Skip to content

Improve robustness for line of sight function #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions arcade/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,14 @@ def has_line_of_sight(observer: Point,
"""
if max_distance <= 0:
raise ValueError("max_distance must be greater than zero")
if check_resolution <= 0:
raise ValueError("check_resolution must be greater than zero")

distance = get_distance(observer[0], observer[1],
target[0], target[1])
if distance == 0:
return False

steps = int(distance // check_resolution)
for step in range(steps + 1):
step_distance = step * check_resolution
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/paths/test_line_of_sight.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def test_line_of_sight(window):
result = arcade.has_line_of_sight(player.position, enemy.position, wall_list, 20)
assert not result

result = arcade.has_line_of_sight(enemy.position, enemy.position, wall_list)
assert result

wall = arcade.Sprite(":resources:images/tiles/grassCenter.png")
wall.center_x = 0
wall.center_y = 0
Expand Down