Skip to content

Commit 7fa3f6c

Browse files
committed
Fix pyright by cleaning A* pathing annotations and imports
1 parent 564227d commit 7fa3f6c

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

arcade/paths.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
from __future__ import annotations
66

77
import math
8-
from typing import cast
98

109
from arcade import Sprite, SpriteList, check_for_collision_with_list, get_sprites_at_point
1110
from arcade.math import get_distance, lerp_2d
12-
from arcade.types import Point, Point2
11+
from arcade.types import Point2
1312

1413
__all__ = ["AStarBarrierList", "astar_calculate_path", "has_line_of_sight"]
1514

@@ -33,13 +32,13 @@ def _spot_is_blocked(position: Point2, moving_sprite: Sprite, blocking_sprites:
3332
return len(hit_list) > 0
3433

3534

36-
def _heuristic(start: Point, goal: Point) -> float:
35+
def _heuristic(start: Point2, goal: Point2) -> float:
3736
"""
3837
Returns a heuristic value for the passed points.
3938
4039
Args:
41-
start (Point): The 1st point to compare
42-
goal (Point): The 2nd point to compare
40+
start (Point2): The 1st point to compare
41+
goal (Point2): The 2nd point to compare
4342
4443
Returns:
4544
float: The heuristic of the 2 points
@@ -102,7 +101,7 @@ def __init__(
102101
else:
103102
self.movement_directions = (1, 0), (-1, 0), (0, 1), (0, -1) # type: ignore
104103

105-
def get_vertex_neighbours(self, pos: Point) -> list[tuple[float, float]]:
104+
def get_vertex_neighbours(self, pos: Point2) -> list[tuple[float, float]]:
106105
"""
107106
Return neighbors for this point according to ``self.movement_directions``
108107
@@ -123,7 +122,7 @@ def get_vertex_neighbours(self, pos: Point) -> list[tuple[float, float]]:
123122
n.append((x2, y2))
124123
return n
125124

126-
def move_cost(self, a: Point, b: Point) -> float:
125+
def move_cost(self, a: Point2, b: Point2) -> float:
127126
"""
128127
Returns a float of the cost to move
129128
@@ -224,12 +223,12 @@ def _AStarSearch(start: Point2, end: Point2, graph: _AStarGraph) -> list[Point2]
224223
return None
225224

226225

227-
def _collapse(pos: Point, grid_size: float):
226+
def _collapse(pos: Point2, grid_size: float) -> tuple[int, int]:
228227
"""Makes Point pos smaller by grid_size"""
229228
return int(pos[0] // grid_size), int(pos[1] // grid_size)
230229

231230

232-
def _expand(pos: Point, grid_size: float):
231+
def _expand(pos: Point2, grid_size: float) -> tuple[int, int]:
233232
"""Makes Point pos larger by grid_size"""
234233
return int(pos[0] * grid_size), int(pos[1] * grid_size)
235234

@@ -329,11 +328,11 @@ def recalculate(self):
329328

330329

331330
def astar_calculate_path(
332-
start_point: Point,
333-
end_point: Point,
331+
start_point: Point2,
332+
end_point: Point2,
334333
astar_barrier_list: AStarBarrierList,
335334
diagonal_movement: bool = True,
336-
) -> list[Point] | None:
335+
) -> list[Point2] | None:
337336
"""
338337
Calculates the path using AStarSearch Algorithm and returns the path
339338
@@ -371,13 +370,13 @@ def astar_calculate_path(
371370

372371
# Currently 'result' is in grid locations. We need to convert them to pixel
373372
# locations.
374-
revised_result = [_expand(p, grid_size) for p in result]
375-
return cast(list[Point], revised_result)
373+
revised_result: list[Point2] = [_expand(p, grid_size) for p in result]
374+
return revised_result
376375

377376

378377
def has_line_of_sight(
379-
observer: Point,
380-
target: Point,
378+
observer: Point2,
379+
target: Point2,
381380
walls: SpriteList,
382381
max_distance: float = float("inf"),
383382
check_resolution: int = 2,
@@ -429,7 +428,7 @@ def has_line_of_sight(
429428

430429

431430
# NOTE: Rewrite this
432-
# def dda_step(start: Point, end: Point):
431+
# def dda_step(start: Point2, end: Point2):
433432
# """
434433
# Bresenham's line algorithm
435434

0 commit comments

Comments
 (0)