New tests: plane/line/topology_compression/serializer/memory_pool/ interval/format_utils/sat/ray_intersect/tri_intersect Expanded: quality_feedback/gdt/validate/interference/motion/ explode/convex_hull/distance/polygon/transaction/sdf Total test files: 162 → 172 (+10)
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#include <gtest/gtest.h>
|
|
#include "vde/collision/sat.h"
|
|
#include "vde/core/point.h"
|
|
#include <vector>
|
|
#include <array>
|
|
|
|
using namespace vde::collision;
|
|
using vde::core::Point3D;
|
|
|
|
// Two separated cubes
|
|
static std::vector<Point3D> 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<std::array<int,3>> 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<Point3D> 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<Point3D> 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<Point3D> 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));
|
|
}
|