summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/path-search.cpp23
-rw-r--r--test/path-search.cpp21
2 files changed, 29 insertions, 15 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp
index 79ba5fa8..b8c7c023 100644
--- a/src/path-search.cpp
+++ b/src/path-search.cpp
@@ -62,14 +62,27 @@ bool search::sample_rtree(world& w, chunk_coords_ ch0, Vector2 center, Vector2 s
// because neighbors can still contain bounding boxes for that tile
if (!sample_rtree_1(*c, min, max, own_id))
return false;
- constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM;
+
for (auto nb : world::neighbor_offsets)
+ {
+ static_assert(iTILE_SIZE2.x() == iTILE_SIZE2.y());
+ constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
+ constexpr int bbox_max = 1 << sizeof(Vector2b().x())*8;
+ constexpr auto chunk_max = (chunk_size + Vector2i(bbox_max)).x();
+
+ const auto off = Vector2(nb)*Vector2(chunk_size);
+ const auto min_ = min + off, max_ = max + off;
+
+ const auto bmin = std::min({ min_.x(), min_.y(), max_.x(), max_.y() }),
+ bmax = std::max({ min_.x(), min_.y(), max_.x(), max_.y() });
+
+ if (bmin < -bbox_max || bmax > chunk_max)
+ continue;
+
if (auto* c2 = w.at(ch0 + Vector2i(nb)))
- {
- auto off = Vector2(nb)*chunk_size;
- if (!sample_rtree_1(*c2, min + off, max + off, own_id))
+ if (!sample_rtree_1(*c2, min_, max_, own_id))
return false;
- }
+ }
return true;
}
diff --git a/test/path-search.cpp b/test/path-search.cpp
index faa16a06..15d1e359 100644
--- a/test/path-search.cpp
+++ b/test/path-search.cpp
@@ -12,22 +12,23 @@ namespace {
void test_bbox()
{
- auto metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked);
- auto table = loader.scenery("table1");
+ constexpr auto sample = [](chunk& c, search::bbox bb) {
+ return search::sample_rtree_1(c, bb.min, bb.max, (object_id)-1);
+ };
+
+ constexpr auto bbox = [](Vector2i coord, rotation r) {
+ return search::make_neighbor_tile_bbox(coord, {}, r);
+ };
+
+ const auto metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked);
+ const auto table = loader.scenery("table1");
+
{
auto w = world();
auto& c12 = w[chunk_coords_{1, 2, 0}];
[[maybe_unused]] auto& c11 = w[chunk_coords_{1, 1, 0}];
c12[{0, 0}].wall_north() = {metal2, 0};
- constexpr auto sample = [](chunk& c, search::bbox bb) {
- return search::sample_rtree_1(c, bb.min, bb.max, (object_id)-1);
- };
-
- constexpr auto bbox = [](Vector2i coord, rotation r) {
- return search::make_neighbor_tile_bbox(coord, {}, r);
- };
-
using enum rotation;
fm_assert( !sample(c12, bbox({0, 0}, N)) );