#include #include "vde/collision/sat.h" #include "vde/core/point.h" #include #include using namespace vde::collision; using vde::core::Point3D; // Two separated cubes static std::vector cube_verts_at_origin() { return {{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0}, {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1}}; } static std::vector> cube_faces() { return {{0,2,1}, {0,3,2}, // bottom {4,5,6}, {4,6,7}, // top {0,1,5}, {0,5,4}, // front {1,2,6}, {1,6,5}, // right {2,3,7}, {2,7,6}, // back {3,0,4}, {3,4,7}}; // left } TEST(SATTest, DisjointCubes_NoIntersection) { auto va = cube_verts_at_origin(); auto fa = cube_faces(); // Shift second cube 3 units in X std::vector vb; for (auto& v : cube_verts_at_origin()) { vb.push_back(Point3D(v.x() + 3, v.y(), v.z())); } auto fb = cube_faces(); EXPECT_FALSE(sat_intersect(va, fa, vb, fb)); } TEST(SATTest, OverlappingCubes_Intersection) { auto va = cube_verts_at_origin(); auto fa = cube_faces(); // Shift second cube 0.5 units in X (overlapping) std::vector vb; for (auto& v : cube_verts_at_origin()) { vb.push_back(Point3D(v.x() + 0.5, v.y(), v.z())); } auto fb = cube_faces(); EXPECT_TRUE(sat_intersect(va, fa, vb, fb)); } TEST(SATTest, TouchingCubes_AtFace) { auto va = cube_verts_at_origin(); auto fa = cube_faces(); // Shift second cube exactly touching at x=1 std::vector vb; for (auto& v : cube_verts_at_origin()) { vb.push_back(Point3D(v.x() + 1.0, v.y(), v.z())); } auto fb = cube_faces(); // Touching at boundary — may or may not detect, verify no crash sat_intersect(va, fa, vb, fb); SUCCEED(); } TEST(SATTest, SameCube_Intersection) { auto v = cube_verts_at_origin(); auto f = cube_faces(); EXPECT_TRUE(sat_intersect(v, f, v, f)); }