|
qHexWalker 0.0.1
Hexagonal Grid Pathfinding & Maze Visualization on Interactive Maps
|
Bidirectional A* pathfinding algorithm for H3 hexagonal cells. More...
#include <astar.h>
Inheritance diagram for H3AStar:
Collaboration diagram for H3AStar:Classes | |
| struct | H3IndexHash |
| Hash function for H3Index in unordered containers. More... | |
| struct | Node |
| Internal node structure for A* priority queue. More... | |
Public Member Functions | |
| H3AStar (QObject *parent=nullptr) | |
| Constructs an H3AStar pathfinder. | |
| ~H3AStar () override | |
| Destructor. | |
| std::vector< H3Index > | findShortestPath (H3Index start, H3Index end) |
| Finds the shortest path between two H3 cells. | |
| void | setBlockedCells (const std::unordered_set< H3Index > &blocked) |
| Sets cells that cannot be traversed (obstacles). | |
Public Attributes | |
| : void newCell(H3Index h3Index) | |
Private Member Functions | |
| std::vector< H3Index > | findPathAtResolution3 (H3Index start, H3Index end, const LatLng &endCoord) |
| Finds path at resolution 3 using bidirectional A*. | |
| std::vector< H3Index > | refineEndSegmentGradual (H3Index prevInPath, H3Index parentEnd, H3Index originalEnd, int endRes) |
| Refines path segment near the end point to target resolution. | |
| std::vector< H3Index > | refineStartSegmentGradual (H3Index originalStart, H3Index nextInPath, int startRes) const |
| Refines path segment near the start point to target resolution. | |
| std::vector< H3Index > | refinePath (const std::vector< H3Index > &pathRes3, H3Index originalStart, H3Index originalEnd, int startRes, int endRes) |
| Refines entire coarse path to target resolution. | |
| std::vector< H3Index > | findLocalPathAtResolution (H3Index start, H3Index end, H3Index limitParent) const |
| Finds local path within a parent cell boundary. | |
Static Private Member Functions | |
| static H3Index | findBoundaryCellInDirection (const std::vector< H3Index > &cells, H3Index from, H3Index direction) |
| Finds boundary cell in a direction for path refinement. | |
| static std::vector< H3Index > | getChildrenAtResolution (H3Index parent, int resolution) |
| Gets all children of a cell at specified resolution. | |
| static std::array< H3Index, MAX_NEIGHBORS > | getNeighbors (H3Index cell) |
| Gets the 6 neighbors of a hexagonal cell. | |
| static double | getDistanceBetweenCells (H3Index cell1, H3Index cell2) |
| Calculates geographic distance between two cells. | |
| static double | heuristic (H3Index cell, const LatLng &targetCoord) |
| Heuristic function for A* (distance to target). | |
| static std::vector< H3Index > | reconstructPath (const std::unordered_map< H3Index, H3Index, H3IndexHash > &previous, H3Index start, H3Index end) |
| Reconstructs path from the visited nodes map. | |
| static H3Index | cellToParentRes3 (H3Index index) |
| Converts any cell to its parent at resolution 3. | |
| static H3Index | cellToChildRes3 (H3Index index) |
| Converts resolution 3 cell to child at original resolution. | |
Private Attributes | |
| std::unordered_set< H3Index > | blockedCells {} |
| Set of blocked (impassable) cells. | |
Static Private Attributes | |
| static constexpr uint16_t | MAX_CELLS_RES_3 {41'162} |
| Maximum number of cells at resolution 3 (~41K cells globally). | |
| static constexpr int | MAX_NEIGHBORS {6} |
| Maximum neighbors for a hexagonal cell (always 6). | |
Bidirectional A* pathfinding algorithm for H3 hexagonal cells.
The H3AStar class provides an efficient pathfinding implementation that:
Where b = branching factor (6 for hexagons), d = path depth
|
explicit |
|
overridedefault |
Destructor.
|
staticprivate |
|
staticprivate |
Converts any cell to its parent at resolution 3.
Definition at line 573 of file astar.cpp.
Referenced by findShortestPath().
Here is the caller graph for this function:
|
staticprivate |
Finds boundary cell in a direction for path refinement.
Definition at line 448 of file astar.cpp.
Referenced by refineEndSegmentGradual(), and refineStartSegmentGradual().
Here is the caller graph for this function:
|
private |
Finds local path within a parent cell boundary.
Definition at line 256 of file astar.cpp.
References blockedCells, H3AStar::Node::cell, getDistanceBetweenCells(), getNeighbors(), heuristic(), MAX_CELLS_RES_3, and reconstructPath().
Referenced by refineEndSegmentGradual(), and refineStartSegmentGradual().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Finds path at resolution 3 using bidirectional A*.
| start | Start cell (will be converted to res 3). |
| end | End cell (will be converted to res 3). |
| endCoord | Geographic coordinates of end point for heuristic. |
Definition at line 74 of file astar.cpp.
References blockedCells, H3AStar::Node::cell, getDistanceBetweenCells(), getNeighbors(), and heuristic().
Referenced by findShortestPath().
Here is the call graph for this function:
Here is the caller graph for this function:| std::vector< H3Index > H3AStar::findShortestPath | ( | H3Index | start, |
| H3Index | end | ||
| ) |
Finds the shortest path between two H3 cells.
Uses bidirectional A* search with hierarchical resolution refinement:
| start | The starting H3 cell index. |
| end | The destination H3 cell index. |
Definition at line 12 of file astar.cpp.
References blockedCells, cellToParentRes3(), ConversionError, CoordinateError, findPathAtResolution3(), InvalidCell, refinePath(), and SameStartEnd.
Referenced by H3_VIEWER::H3Worker::doWork().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Gets all children of a cell at specified resolution.
| parent | Parent cell index. |
| resolution | Target resolution. |
Definition at line 485 of file astar.cpp.
Referenced by refineEndSegmentGradual(), and refineStartSegmentGradual().
Here is the caller graph for this function:
|
staticprivate |
Calculates geographic distance between two cells.
| cell1 | First cell index. |
| cell2 | Second cell index. |
Definition at line 525 of file astar.cpp.
Referenced by findLocalPathAtResolution(), and findPathAtResolution3().
Here is the caller graph for this function:
|
staticprivate |
Gets the 6 neighbors of a hexagonal cell.
| cell | The cell to get neighbors for. |
Definition at line 504 of file astar.cpp.
Referenced by findLocalPathAtResolution(), and findPathAtResolution3().
Here is the caller graph for this function:
|
staticprivate |
Heuristic function for A* (distance to target).
| cell | Current cell. |
| targetCoord | Target coordinates. |
Definition at line 542 of file astar.cpp.
Referenced by findLocalPathAtResolution(), and findPathAtResolution3().
Here is the caller graph for this function:
|
staticprivate |
Reconstructs path from the visited nodes map.
| previous | Map of cell -> previous cell in path. |
| start | Start cell. |
| end | End cell. |
Definition at line 551 of file astar.cpp.
Referenced by findLocalPathAtResolution().
Here is the caller graph for this function:
|
private |
Refines path segment near the end point to target resolution.
| prevInPath | Previous cell in the coarse path. |
| parentEnd | Parent cell at resolution 3. |
| originalEnd | Original end cell at target resolution. |
| endRes | Target resolution. |
Definition at line 322 of file astar.cpp.
References findBoundaryCellInDirection(), findLocalPathAtResolution(), and getChildrenAtResolution().
Referenced by refinePath().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Refines entire coarse path to target resolution.
| pathRes3 | Coarse path at resolution 3. |
| originalStart | Original start cell. |
| originalEnd | Original end cell. |
| startRes | Start cell resolution. |
| endRes | End cell resolution. |
Definition at line 413 of file astar.cpp.
References refineEndSegmentGradual(), and refineStartSegmentGradual().
Referenced by findShortestPath().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Refines path segment near the start point to target resolution.
| originalStart | Original start cell at target resolution. |
| nextInPath | Next cell in the coarse path. |
| startRes | Target resolution. |
Definition at line 373 of file astar.cpp.
References findBoundaryCellInDirection(), findLocalPathAtResolution(), and getChildrenAtResolution().
Referenced by refinePath().
Here is the call graph for this function:
Here is the caller graph for this function:| void H3AStar::setBlockedCells | ( | const std::unordered_set< H3Index > & | blocked | ) |
Sets cells that cannot be traversed (obstacles).
Call this method before findShortestPath() to define obstacles such as maze walls.
| blocked | Set of H3 cell indices that are impassable. |
Definition at line 10 of file astar.cpp.
References blockedCells.
Referenced by H3_VIEWER::H3Worker::setWalls().
Here is the caller graph for this function:
|
private |
Set of blocked (impassable) cells.
Definition at line 130 of file astar.h.
Referenced by findLocalPathAtResolution(), findPathAtResolution3(), findShortestPath(), and setBlockedCells().
|
staticconstexprprivate |
Maximum number of cells at resolution 3 (~41K cells globally).
Definition at line 99 of file astar.h.
Referenced by findLocalPathAtResolution().
|
staticconstexprprivate |