summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-09-11 18:02:50 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-09-11 18:02:50 +0200
commitf3f153ad0fb35aae25cdd7f7071d3bbd892db9f6 (patch)
tree318505efd1b3ba0ec20a75edaba62f518e8bfd2a
parenteb3f2bbd5b62063397d3ed4b4c6da2016e6efe8c (diff)
add failing test
-rw-r--r--src/path-search.cpp9
-rw-r--r--src/path-search.hpp2
-rw-r--r--test/path-search.cpp12
3 files changed, 16 insertions, 7 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp
index 11fddce1..1f9b5bf9 100644
--- a/src/path-search.cpp
+++ b/src/path-search.cpp
@@ -54,9 +54,8 @@ bool search::sample_rtree_1(chunk& c, Vector2 min, Vector2 max, object_id own_id
return is_passable;
}
-bool search::sample_rtree(world& w, chunk_coords_ ch0, Vector2 center, Vector2 size, object_id own_id)
+bool search::sample_rtree(world& w, chunk_coords_ ch0, Vector2 min, Vector2 max, object_id own_id)
{
- const auto min = center - size*.5f, max = min + size;
if (auto* c = w.at(ch0))
// it's not correct to return true if c == nullptr
// because neighbors can still contain bounding boxes for that tile
@@ -85,10 +84,12 @@ bool search::sample_rtree(world& w, chunk_coords_ ch0, Vector2 center, Vector2 s
return true;
}
-bool search::sample_rtree(world& w, global_coords coord, Vector2b offset, Vector2ub size, object_id own_id)
+bool search::sample_rtree(world& w, global_coords coord, Vector2b offset, Vector2ub size_, object_id own_id)
{
auto center = iTILE_SIZE2 * Vector2i(coord.local()) + Vector2i(offset);
- return sample_rtree(w, coord, Vector2(center), Vector2(size), own_id);
+ auto size = Vector2(size_);
+ auto min = Vector2(center) - size*.5f, max = min + size;
+ return sample_rtree(w, coord, min, max, own_id);
}
auto search::make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, rotation r) -> bbox
diff --git a/src/path-search.hpp b/src/path-search.hpp
index f044a381..cb58f531 100644
--- a/src/path-search.hpp
+++ b/src/path-search.hpp
@@ -87,7 +87,7 @@ public:
Optional<search_result> operator()(world& w, const object& obj, global_coords to, Vector2b to_offset);
static bool sample_rtree_1(chunk& c, Vector2 min, Vector2 max, object_id own_id);
- static bool sample_rtree(world& w, chunk_coords_ ch0, Vector2 center, Vector2 size, object_id own_id);
+ static bool sample_rtree(world& w, chunk_coords_ ch0, Vector2 min, Vector2 max, object_id own_id);
static bool sample_rtree(world& w, global_coords coord, Vector2b offset, Vector2ub size, object_id own_id);
static bbox make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, rotation r);
diff --git a/test/path-search.cpp b/test/path-search.cpp
index 15d1e359..f968e0c5 100644
--- a/test/path-search.cpp
+++ b/test/path-search.cpp
@@ -16,6 +16,10 @@ void test_bbox()
return search::sample_rtree_1(c, bb.min, bb.max, (object_id)-1);
};
+ constexpr auto sample2 = [](world& w, chunk_coords_ ch, search::bbox bb) {
+ return search::sample_rtree(w, ch, bb.min, bb.max, (object_id)-1);
+ };
+
constexpr auto bbox = [](Vector2i coord, rotation r) {
return search::make_neighbor_tile_bbox(coord, {}, r);
};
@@ -24,17 +28,21 @@ void test_bbox()
const auto table = loader.scenery("table1");
{
+ using enum rotation;
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};
- using enum rotation;
-
fm_assert( !sample(c12, bbox({0, 0}, N)) );
fm_assert( sample(c12, bbox({0, 0}, E)) );
fm_assert( sample(c12, bbox({0, 0}, S)) );
fm_assert( sample(c12, bbox({0, 0}, W)) );
+
+ fm_assert( sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, W)) );
+ fm_assert( sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, E)) );
+ fm_assert( sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, N)) );
+ fm_assert( !sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, S)) );
}
// todo use test chunk
}