fixed formating

This commit is contained in:
2025-11-13 16:56:48 +03:00
parent fa91f21e39
commit ee458a24f7

View File

@@ -8,24 +8,22 @@
using Mesh = omath::source_engine::Mesh; using Mesh = omath::source_engine::Mesh;
using Collider = omath::source_engine::MeshCollider; using Collider = omath::source_engine::MeshCollider;
using GJK = omath::collision::GjkAlgorithm<Collider>; using GJK = omath::collision::GjkAlgorithm<Collider>;
using EPA = omath::collision::Epa<Collider>; using EPA = omath::collision::Epa<Collider>;
TEST(UnitTestEpa, TestCollisionTrue) TEST(UnitTestEpa, TestCollisionTrue)
{ {
// Unit cube [-1,1]^3 // Unit cube [-1,1]^3
std::vector<omath::Vector3<float>> vbo = { std::vector<omath::Vector3<float>> vbo = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
{-1,-1,-1}, {-1,-1, 1}, {-1, 1,-1}, {-1, 1, 1}, {1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}};
{ 1, 1, 1}, { 1, 1,-1}, { 1,-1, 1}, { 1,-1,-1}
};
std::vector<omath::Vector3<std::size_t>> vao; // not needed std::vector<omath::Vector3<std::size_t>> vao; // not needed
Mesh a(vbo, vao, {1,1,1}); Mesh a(vbo, vao, {1, 1, 1});
Mesh b(vbo, vao, {1,1,1}); Mesh b(vbo, vao, {1, 1, 1});
// Overlap along +X by 0.5 // Overlap along +X by 0.5
a.set_origin({0,0,0}); a.set_origin({0, 0, 0});
b.set_origin({0.5f,0,0}); b.set_origin({0.5f, 0, 0});
Collider A(a), B(b); Collider A(a), B(b);
@@ -34,7 +32,9 @@ TEST(UnitTestEpa, TestCollisionTrue)
ASSERT_TRUE(gjk.hit) << "GJK should report collision"; ASSERT_TRUE(gjk.hit) << "GJK should report collision";
// EPA // EPA
EPA::Params params; params.max_iterations = 64; params.tolerance = 1e-4f; EPA::Params params;
params.max_iterations = 64;
params.tolerance = 1e-4f;
auto epa = EPA::solve(A, B, gjk.simplex, params); auto epa = EPA::solve(A, B, gjk.simplex, params);
ASSERT_TRUE(epa.success) << "EPA should converge"; ASSERT_TRUE(epa.success) << "EPA should converge";
@@ -51,26 +51,30 @@ TEST(UnitTestEpa, TestCollisionTrue)
// Try both signs with a tiny margin (avoid grazing contacts) // Try both signs with a tiny margin (avoid grazing contacts)
const float margin = 1.0f + 1e-3f; const float margin = 1.0f + 1e-3f;
const auto pen = epa.normal * epa.depth; const auto pen = epa.normal * epa.depth;
Mesh b_plus = b; b_plus.set_origin(b_plus.get_origin() + pen * margin); Mesh b_plus = b;
Mesh b_minus= b; b_minus.set_origin(b_minus.get_origin() - pen * margin); b_plus.set_origin(b_plus.get_origin() + pen * margin);
Mesh b_minus = b;
b_minus.set_origin(b_minus.get_origin() - pen * margin);
Collider B_plus(b_plus), B_minus(b_minus); Collider B_plus(b_plus), B_minus(b_minus);
const bool sep_plus = !GJK::is_collide_with_simplex_info(A, B_plus).hit; const bool sep_plus = !GJK::is_collide_with_simplex_info(A, B_plus).hit;
const bool sep_minus = !GJK::is_collide_with_simplex_info(A, B_minus).hit; const bool sep_minus = !GJK::is_collide_with_simplex_info(A, B_minus).hit;
// Exactly one direction should separate // Exactly one direction should separate
EXPECT_NE(sep_plus, sep_minus) << "Exactly one of ±penetration must separate"; EXPECT_NE(sep_plus, sep_minus) << "Exactly one of ±penetration must separate";
// Optional: pick the resolving direction and assert round-trip // Optional: pick the resolving direction and assert round-trip
const auto resolve = sep_plus ? ( pen * margin) : (-pen * margin); const auto resolve = sep_plus ? (pen * margin) : (-pen * margin);
Mesh b_resolved = b; b_resolved.set_origin(b_resolved.get_origin() + resolve); Mesh b_resolved = b;
b_resolved.set_origin(b_resolved.get_origin() + resolve);
EXPECT_FALSE(GJK::is_collide(A, Collider(b_resolved))) << "Resolved position should be non-colliding"; EXPECT_FALSE(GJK::is_collide(A, Collider(b_resolved))) << "Resolved position should be non-colliding";
// Moving the other way should still collide // Moving the other way should still collide
Mesh b_wrong = b; b_wrong.set_origin(b_wrong.get_origin() - resolve); Mesh b_wrong = b;
b_wrong.set_origin(b_wrong.get_origin() - resolve);
EXPECT_TRUE(GJK::is_collide(A, Collider(b_wrong))); EXPECT_TRUE(GJK::is_collide(A, Collider(b_wrong)));
} }