diff --git a/pathfinding3d/core/diagonal_movement.py b/pathfinding3d/core/diagonal_movement.py index 831f957..a4b8d7f 100644 --- a/pathfinding3d/core/diagonal_movement.py +++ b/pathfinding3d/core/diagonal_movement.py @@ -1,4 +1,5 @@ class DiagonalMovement: + """Enum for diagonal movement""" always = 1 never = 2 if_at_most_one_obstacle = 3 diff --git a/pathfinding3d/core/grid.py b/pathfinding3d/core/grid.py index 5811486..a841824 100644 --- a/pathfinding3d/core/grid.py +++ b/pathfinding3d/core/grid.py @@ -42,7 +42,7 @@ def build_nodes( Returns ------- - List + List[List[List[GridNode]]] A list of list of lists containing the nodes in the grid. """ nodes: List = [] @@ -67,6 +67,9 @@ def build_nodes( class Grid: + """ + A grid represents the map (as 3d-list of nodes). + """ def __init__( self, width: int = 0, @@ -77,7 +80,7 @@ def __init__( inverse: bool = False, ): """ - A grid represents the map (as 3d-list of nodes). + Create a new grid. Parameters ---------- @@ -115,6 +118,14 @@ def _validate_dimensions(self, width: int, height: int, depth: int, matrix: Matr return width, height, depth def is_valid_grid(self) -> bool: + """ + Check if grid is valid + + Returns + ------- + bool + True, if grid is valid + """ return self.width > 0 and self.height > 0 and self.depth > 0 def node(self, x: int, y: int, z: int) -> Optional[GridNode]: @@ -247,8 +258,8 @@ def neighbors( Returns ------- - list - list of neighbor nodes + List[GridNode] + list of all neighbors """ x, y, z = node.x, node.y, node.z diff --git a/pathfinding3d/core/node.py b/pathfinding3d/core/node.py index bf66f24..c663b8c 100644 --- a/pathfinding3d/core/node.py +++ b/pathfinding3d/core/node.py @@ -4,6 +4,28 @@ @dataclasses.dataclass class Node: + """ + Basic node class, saves calculated values for pathfinding + + Attributes + ---------- + h : float + The cost from this node to the goal (for A* including the heuristic). + g : float + The cost from the start node to this node. + f : float + The overall cost for a path using this node (f = g + h). + opened : int + The number of times this node has been opened. + closed : bool + Whether this node is closed. + parent : Optional[Node] + The parent node of this node. + retain_count : int + Used for recursion tracking of IDA*. + tested : bool + Used for IDA* and Jump-Point-Search. + """ __slots__ = ["h", "g", "f", "opened", "closed", "parent", "retain_count", "tested"] def __init__(self): @@ -41,8 +63,24 @@ def cleanup(self): @dataclasses.dataclass class GridNode(Node): """ - basic node, saves X, Y and Z coordinates on some grid and determine if - it is walkable. + Basic node in a grid. + + Attributes + ---------- + x : int + The x coordinate of the node. + y : int + The y coordinate of the node. + z : int + The z coordinate of the node. + walkable : bool + Whether this node can be walked through. + weight : float + The weight of the node. + grid_id : Optional[int] + The id of the grid this node belongs to. + connections : Optional[List] + The connections of this node. """ # Coordinates @@ -64,8 +102,6 @@ class GridNode(Node): connections: Optional[List] = None - identifier: Optional[Tuple] = None - def __post_init__(self): super().__init__() # for heap @@ -81,6 +117,14 @@ def __iter__(self): yield self.grid_id def connect(self, other_node: "GridNode"): + """ + Connect this node to another node. + + Parameters + ---------- + other_node : GridNode + The node to connect to. + """ if not self.connections: self.connections = [other_node] else: diff --git a/pathfinding3d/core/world.py b/pathfinding3d/core/world.py index 0f033fb..aac91aa 100644 --- a/pathfinding3d/core/world.py +++ b/pathfinding3d/core/world.py @@ -6,7 +6,18 @@ # a world connects grids but can have multiple grids. class World: + """ + A world connects grids but can have multiple grids. + """ def __init__(self, grids: Dict[int, Grid]): + """ + Initialize a new world. + + Parameters + ---------- + grids : Dict[int, Grid] + grids in this world + """ self.grids = grids def neighbors(self, node: GridNode, diagonal_movement: int) -> List[GridNode]: