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)
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
#include <gtest/gtest.h>
|
|
#include "vde/collision/tri_intersect.h"
|
|
#include "vde/core/triangle.h"
|
|
#include "vde/core/aabb.h"
|
|
#include "vde/core/point.h"
|
|
#include <cmath>
|
|
|
|
using namespace vde::collision;
|
|
using vde::core::Triangle3D;
|
|
using vde::core::AABB3D;
|
|
using vde::core::Point3D;
|
|
|
|
TEST(TriIntersectTest, DisjointTriangles_NoIntersection) {
|
|
Triangle3D t1(Point3D(0,0,0), Point3D(1,0,0), Point3D(0,1,0));
|
|
Triangle3D t2(Point3D(0,0,5), Point3D(1,0,5), Point3D(0,1,5));
|
|
|
|
EXPECT_FALSE(tri_tri_intersect(t1, t2));
|
|
}
|
|
|
|
TEST(TriIntersectTest, CoplanarOverlapping_Intersection) {
|
|
Triangle3D t1(Point3D(0,0,0), Point3D(2,0,0), Point3D(0,2,0));
|
|
Triangle3D t2(Point3D(1,0,0), Point3D(3,0,0), Point3D(1,2,0));
|
|
|
|
EXPECT_TRUE(tri_tri_intersect(t1, t2));
|
|
}
|
|
|
|
TEST(TriIntersectTest, CrossPlanes_Intersection) {
|
|
// t1 in XY plane, t2 in XZ plane crossing through
|
|
Triangle3D t1(Point3D(0,0,0), Point3D(2,0,0), Point3D(0,2,0));
|
|
Triangle3D t2(Point3D(1,-1,0), Point3D(1,1,0), Point3D(1,0,3));
|
|
|
|
EXPECT_TRUE(tri_tri_intersect(t1, t2));
|
|
}
|
|
|
|
TEST(TriIntersectTest, Detailed_Disjoint) {
|
|
Triangle3D t1(Point3D(0,0,0), Point3D(1,0,0), Point3D(0,1,0));
|
|
Triangle3D t2(Point3D(0,0,5), Point3D(1,0,5), Point3D(0,1,5));
|
|
|
|
auto sect = tri_tri_intersect_detailed(t1, t2);
|
|
EXPECT_FALSE(sect.intersects);
|
|
}
|
|
|
|
TEST(TriIntersectTest, Detailed_Intersecting) {
|
|
Triangle3D t1(Point3D(0,0,0), Point3D(2,0,0), Point3D(0,2,0));
|
|
Triangle3D t2(Point3D(1,-1,0), Point3D(1,1,0), Point3D(1,0,3));
|
|
|
|
auto sect = tri_tri_intersect_detailed(t1, t2);
|
|
EXPECT_TRUE(sect.intersects);
|
|
}
|
|
|
|
TEST(TriAABBTest, TriangleInsideBox) {
|
|
Triangle3D tri(Point3D(0.5,0.5,0.5), Point3D(1.5,0.5,0.5), Point3D(0.5,1.5,0.5));
|
|
AABB3D box(Point3D(0,0,0), Point3D(2,2,2));
|
|
|
|
EXPECT_TRUE(tri_aabb_overlap(tri, box));
|
|
}
|
|
|
|
TEST(TriAABBTest, TriangleOutsideBox) {
|
|
Triangle3D tri(Point3D(5,5,5), Point3D(6,5,5), Point3D(5,6,5));
|
|
AABB3D box(Point3D(0,0,0), Point3D(2,2,2));
|
|
|
|
EXPECT_FALSE(tri_aabb_overlap(tri, box));
|
|
}
|