From cd18b088cb7a9570afb90dcb86afa067142e0de6 Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 9 Nov 2025 15:38:38 +0300 Subject: [PATCH] updated test --- include/omath/collision/gjk_algorithm.hpp | 2 +- tests/general/unit_test_gjk.cpp | 28 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/omath/collision/gjk_algorithm.hpp b/include/omath/collision/gjk_algorithm.hpp index 2aae2a1..cb8645a 100644 --- a/include/omath/collision/gjk_algorithm.hpp +++ b/include/omath/collision/gjk_algorithm.hpp @@ -20,7 +20,7 @@ namespace omath::collision } [[nodiscard]] - static bool check_collision(const MeshCollider& collider_a, const MeshCollider& collider_b) + static bool is_collide(const MeshCollider& collider_a, const MeshCollider& collider_b) { // Get initial support point in any direction auto support = find_support_vertex(collider_a, collider_b, {1, 0, 0}); diff --git a/tests/general/unit_test_gjk.cpp b/tests/general/unit_test_gjk.cpp index 9ec5f42..45259d4 100644 --- a/tests/general/unit_test_gjk.cpp +++ b/tests/general/unit_test_gjk.cpp @@ -4,7 +4,7 @@ #include #include -TEST(UnitTestGjk, TestCollision) +TEST(UnitTestGjk, TestCollisionTrue) { const std::vector> mesh = { {-1.f, -1.f, -1.f}, @@ -18,7 +18,29 @@ TEST(UnitTestGjk, TestCollision) }; const omath::collision::MeshCollider collider_a(mesh, {0.f, 0.f, 0.f}); - const omath::collision::MeshCollider collider_b(mesh, {0.f, 3.f, 0.f}); + const omath::collision::MeshCollider collider_b(mesh, {0.f, 0.5f, 0.f}); - const auto result = omath::collision::GjkAlgorithm::check_collision(collider_a, collider_b); + const auto result = omath::collision::GjkAlgorithm::is_collide(collider_a, collider_b); + + EXPECT_TRUE(result); +} +TEST(UnitTestGjk, TestCollisionFalse) +{ + const std::vector> mesh = { + {-1.f, -1.f, -1.f}, + {-1.f, -1.f, 1.f}, + {-1.f, 1.f, -1.f}, + {-1.f, 1.f, 1.f}, + { 1.f, 1.f, 1.f}, // x = +1 vertices (put {1,1,1} first in case your support breaks ties by first-hit) + { 1.f, 1.f, -1.f}, + { 1.f, -1.f, 1.f}, + { 1.f, -1.f, -1.f} + }; + + const omath::collision::MeshCollider collider_a(mesh, {0.f, 0.f, 0.f}); + const omath::collision::MeshCollider collider_b(mesh, {0.f, 4.1f, 0.f}); + + const auto result = omath::collision::GjkAlgorithm::is_collide(collider_a, collider_b); + + EXPECT_FALSE(result); } \ No newline at end of file