21 [[nodiscard]] VIPRA_INLINE
auto node_count()
const noexcept ->
size_t
26 [[nodiscard]]
auto neighbors(VIPRA::idx gridIdx)
const noexcept
27 -> std::array<VIPRA::idx, 8>
29 assert(gridIdx < _grids.size());
31 std::array<VIPRA::idx, 8> neighbors{};
34 for (
bool neighbor : _grids[gridIdx].neighbors ) {
35 if ( ! neighbor || (neighbor_idx(gridIdx, nIdx) > _grids.size() ||
36 neighbor_idx(gridIdx, nIdx) < 0) ) {
37 neighbors[nIdx] = std::numeric_limits<VIPRA::idx>::max();
42 neighbors[nIdx] = neighbor_idx(gridIdx, nIdx);
49 [[nodiscard]] VIPRA_INLINE
auto pos(VIPRA::idx gridIdx)
const noexcept ->
VIPRA::f3d
51 assert(gridIdx < _grids.size());
52 return _positions[gridIdx];
63 auto const gridX =
static_cast<VIPRA::idx
>(std::floor(position.x / _gridSize));
64 auto const gridY =
static_cast<VIPRA::idx
>(std::floor(position.y / _gridSize));
66 return get_index(gridX, gridY);
70 VIPRA::size _xCount{};
71 VIPRA::size _yCount{};
72 VIPRA::f_pnt _gridSize{};
73 VIPRA::f_pnt _closestObstacle{};
75 std::vector<GridPoint> _grids;
76 std::vector<VIPRA::f3d> _positions;
78 void set_grid_counts(VIPRA::Modules::Map
const& map);
79 void construct_graph(VIPRA::Modules::Map
const& map);
80 void set_adjacents(VIPRA::idx currIdx);
82 [[nodiscard]]
auto neighbor_idx(VIPRA::idx gridIdx,
83 VIPRA::idx neighbor)
const noexcept -> VIPRA::idx
85 const int xCount =
static_cast<int>(_xCount);
86 const std::array<int, 8> deltaIdx = {
87 (-xCount - 1), -xCount, (-xCount + 1), -1, 1, (xCount - 1), xCount, (xCount + 1),
90 return gridIdx + deltaIdx[neighbor];
101 [[nodiscard]] VIPRA_INLINE
auto get_index(
102 VIPRA::size gridX, VIPRA::size gridY)
const noexcept -> VIPRA::idx
104 assert(gridX + (gridY * _xCount) < _grids.size());
105 return gridX + (gridY * _xCount);
109 PathingGraph(Modules::Map
const& map, VIPRA::f_pnt gridSize,
110 VIPRA::f_pnt closestObstacle)
111 : _gridSize(gridSize), _closestObstacle(closestObstacle)
113 construct_graph(map);
115 PathingGraph() =
default;
116 PathingGraph(
const PathingGraph&) =
default;
117 PathingGraph(PathingGraph&&) =
default;
118 auto operator=(
const PathingGraph&) -> PathingGraph& =
default;
119 auto operator=(PathingGraph&&) -> PathingGraph& =
default;
120 ~PathingGraph() =
default;