summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-09-16 12:36:24 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-09-16 12:36:24 +0200
commit06e152c0985620a41535e48d2507a566ab532064 (patch)
tree0a9f1dc44a6c40c811ff2b16397dc1d2a642a7d3
parent4bb0637fe81d79bba0de34f72caa632d1da03424 (diff)
more path_search asserts
-rw-r--r--src/path-search.cpp7
-rw-r--r--test/path-search.cpp17
2 files changed, 20 insertions, 4 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp
index 652978d8..119a6e01 100644
--- a/src/path-search.cpp
+++ b/src/path-search.cpp
@@ -49,6 +49,7 @@ bool path_search::is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id ow
bool path_search::is_passable(world& w, chunk_coords_ ch0, Vector2 min, Vector2 max, object_id own_id)
{
+ fm_debug_assert(max >= min);
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
@@ -59,7 +60,7 @@ bool path_search::is_passable(world& w, chunk_coords_ ch0, Vector2 min, Vector2
{
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 bbox_max = -Vector2i(1 << sizeof(Vector2b().x())*8);
constexpr auto chunk_max = chunk_size + Vector2i(bbox_max);
const auto off = Vector2(nb)*Vector2(chunk_size);
@@ -67,7 +68,7 @@ bool path_search::is_passable(world& w, chunk_coords_ ch0, Vector2 min, Vector2
if (min_.x() > chunk_max.x() || min_.y() > chunk_max.y())
continue;
- if (max_.x() < -bbox_max || max_.y() < -bbox_max)
+ if (max_.x() < bbox_max.x() || max_.y() < bbox_max.y())
continue;
if (auto* c2 = w.at(ch0 + Vector2i(nb)))
@@ -168,7 +169,7 @@ auto path_search::make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, ro
#endif
const auto shift = coord * iTILE_SIZE2;
- auto sz = Math::max(Vector2i(own_size), min_size);
+ auto sz = Math::max(Vector2i(own_size), min_size);
auto [min, max] = get_value(sz, r);
return { Vector2(min + shift), Vector2(max + shift) };
}
diff --git a/test/path-search.cpp b/test/path-search.cpp
index f6a567a6..eb4ff4a5 100644
--- a/test/path-search.cpp
+++ b/test/path-search.cpp
@@ -75,7 +75,22 @@ void test_bbox()
fm_assert( !is_passable_1(c, bbox({8, 8}, S)) );
fm_assert( is_passable_1(c, bbox({8, 8}, W)) );
}
- // todo use test chunk
+ {
+ using enum rotation;
+ constexpr auto ch = chunk_coords_{0, 0, 0};
+ auto w = world();
+ auto& c = test_app::make_test_chunk(w, ch);
+
+ fm_assert( !is_passable_1(c, bbox({8, 8}, N)) );
+ fm_assert( !is_passable_1(c, bbox({8, 8}, E)) );
+ fm_assert( !is_passable_1(c, bbox({8, 8}, S)) );
+ fm_assert( !is_passable_1(c, bbox({8, 8}, W)) );
+
+ fm_assert( !is_passable_1(c, bbox({8, 9}, N)) );
+ fm_assert( is_passable_1(c, bbox({8, 9}, E)) );
+ fm_assert( is_passable_1(c, bbox({8, 9}, S)) );
+ fm_assert( is_passable_1(c, bbox({8, 9}, W)) );
+ }
}
} // namespace