summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-12-06 01:27:07 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-12-06 01:35:31 +0100
commit8a514050c611b3dd8ba5c21ffe413af369954b30 (patch)
tree845bdc5023d1c0ad05fa95648bfc0cf9f2797130 /test
parent0a6612286bfa8c2503c757da2b39da37aa05deaf (diff)
src: add collision iterator adapter
Diffstat (limited to 'test')
-rw-r--r--test/bbox.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/test/bbox.cpp b/test/bbox.cpp
index c045d858..87921271 100644
--- a/test/bbox.cpp
+++ b/test/bbox.cpp
@@ -1,28 +1,49 @@
#include "app.hpp"
#include "src/chunk.hpp"
-#include "compat/LooseQuadtree-impl.h"
+#include "src/collision.hpp"
#include <Magnum/Math/Vector2.h>
namespace floormat {
-void test_app::test_bbox()
+static void test_simple(chunk c)
{
- auto c = make_test_chunk();
auto& qt = c.ensure_passability();
fm_assert(qt.GetSize() >= 2);
using namespace loose_quadtree;
using bbox = BoundingBox<std::int16_t>;
- constexpr auto pos1 = Vector2s(iTILE_SIZE2 * (TILE_MAX_DIM/2) - Vector2i(0, iTILE_SIZE[1]/2)),
- size = Vector2s(iTILE_SIZE2);
- constexpr auto b1 = bbox{pos1[0], pos1[1], size[0], size[1]};
- constexpr auto pos2 = Vector2s(iTILE_SIZE2 * (Vector2i(TILE_MAX_DIM/2) - Vector2i(-1, -1)) - Vector2i(0, iTILE_SIZE[1]/2));
+ constexpr auto pos1 = sTILE_SIZE2 * (TILE_MAX_DIM/2) - Vector2s(0, sTILE_SIZE2[1]/2);
+ constexpr auto b1 = bbox{pos1[0], pos1[1], usTILE_SIZE2[0], usTILE_SIZE2[1]};
auto q1 = qt.QueryIntersectsRegion(b1);
fm_assert(!q1.EndOfQuery());
+ auto x1 = *q1.GetCurrent();
+ fm_assert(x1.pass_mode == pass_mode::blocked);
do q1.Next(); while (!q1.EndOfQuery());
- constexpr auto b2 = bbox{pos2[0], pos2[1], size[0], size[1]};
+ constexpr auto pos2 = Vector2s(iTILE_SIZE2 * (Vector2i(TILE_MAX_DIM/2) - Vector2i(-1, -1)) - Vector2i(0, iTILE_SIZE[1]/2));
+ constexpr auto b2 = bbox{pos2[0], pos2[1], usTILE_SIZE2[0], usTILE_SIZE2[1]};
auto q2 = qt.QueryIntersectsRegion(b2);
fm_assert(q2.EndOfQuery());
}
+static void test_wrapper(chunk c)
+{
+ {
+ int i = 0;
+ for (auto b : c.query_collisions(local_coords{TILE_MAX_DIM/2, TILE_MAX_DIM/2},
+ usTILE_SIZE2,
+ Vector2s(sTILE_SIZE2[0]/2, 0)))
+ {
+ fm_assert(b.pass_mode == pass_mode::blocked);
+ i++;
+ }
+ fm_assert(i > 0);
+ }
+}
+
+void test_app::test_bbox()
+{
+ test_simple(make_test_chunk());
+ test_wrapper(make_test_chunk());
+}
+
} // namespace floormat