summaryrefslogtreecommitdiffstats
path: root/core/math/a_star_grid_2d.h
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2023-02-28 12:30:10 +0300
committerDanil Alexeev <danil@alexeev.xyz>2023-04-26 09:29:33 +0300
commit76ee3d4f3103fe824d7c59893782a54c2173b3a0 (patch)
treeaaa40d1e387ee51dbbb97a898f9c6c507ab7c501 /core/math/a_star_grid_2d.h
parent45cd5dcad39274da18440d6ea3c2121bec248eaa (diff)
downloadredot-engine-76ee3d4f3103fe824d7c59893782a54c2173b3a0.tar.gz
Allow negative coordinates in `AStarGrid2D`
Diffstat (limited to 'core/math/a_star_grid_2d.h')
-rw-r--r--core/math/a_star_grid_2d.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h
index e4e62ec360..50df58e0e9 100644
--- a/core/math/a_star_grid_2d.h
+++ b/core/math/a_star_grid_2d.h
@@ -58,7 +58,7 @@ public:
};
private:
- Size2i size;
+ Rect2i region;
Vector2 offset;
Size2 cell_size = Size2(1, 1);
bool dirty = false;
@@ -107,21 +107,21 @@ private:
private: // Internal routines.
_FORCE_INLINE_ bool _is_walkable(int64_t p_x, int64_t p_y) const {
- if (p_x >= 0 && p_y >= 0 && p_x < size.width && p_y < size.height) {
- return !points[p_y][p_x].solid;
+ if (region.has_point(Vector2i(p_x, p_y))) {
+ return !points[p_y - region.position.y][p_x - region.position.x].solid;
}
return false;
}
_FORCE_INLINE_ Point *_get_point(int64_t p_x, int64_t p_y) {
- if (p_x >= 0 && p_y >= 0 && p_x < size.width && p_y < size.height) {
- return &points[p_y][p_x];
+ if (region.has_point(Vector2i(p_x, p_y))) {
+ return &points[p_y - region.position.y][p_x - region.position.x];
}
return nullptr;
}
_FORCE_INLINE_ Point *_get_point_unchecked(int64_t p_x, int64_t p_y) {
- return &points[p_y][p_x];
+ return &points[p_y - region.position.y][p_x - region.position.x];
}
void _get_nbors(Point *p_point, LocalVector<Point *> &r_nbors);
@@ -138,6 +138,9 @@ protected:
GDVIRTUAL2RC(real_t, _compute_cost, Vector2i, Vector2i)
public:
+ void set_region(const Rect2i &p_region);
+ Rect2i get_region() const;
+
void set_size(const Size2i &p_size);
Size2i get_size() const;