mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added trace line
This commit is contained in:
@@ -13,7 +13,9 @@ add_executable(unit-tests
|
||||
UnitTestVector3.cpp
|
||||
UnitTestVector2.cpp
|
||||
UnitTestColor.cpp
|
||||
UnitTestVector4.cpp)
|
||||
UnitTestVector4.cpp
|
||||
UnitTestLineTrace.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)
|
||||
|
||||
|
||||
67
tests/UnitTestLineTrace.cpp
Normal file
67
tests/UnitTestLineTrace.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "omath/collision/LineTracer.hpp"
|
||||
#include "omath/Triangle3d.hpp"
|
||||
#include "omath/Vector3.hpp"
|
||||
|
||||
using namespace omath;
|
||||
using namespace omath::collision;
|
||||
|
||||
class LineTracerTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
// Set up common variables for use in each test
|
||||
Vector3 vertex1{0.0f, 0.0f, 0.0f};
|
||||
Vector3 vertex2{1.0f, 0.0f, 0.0f};
|
||||
Vector3 vertex3{0.0f, 1.0f, 0.0f};
|
||||
Triangle3d triangle{vertex1, vertex2, vertex3};
|
||||
};
|
||||
|
||||
// Test that a ray intersecting the triangle returns false for CanTraceLine
|
||||
TEST_F(LineTracerTest, RayIntersectsTriangle)
|
||||
{
|
||||
constexpr Ray ray{{0.3f, 0.3f, -1.0f}, {0.3f, 0.3f, 1.0f}};
|
||||
EXPECT_FALSE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
|
||||
// Test that a ray parallel to the triangle plane returns true for CanTraceLine
|
||||
TEST_F(LineTracerTest, RayParallelToTriangle)
|
||||
{
|
||||
constexpr Ray ray{{0.3f, 0.3f, 1.0f}, {0.3f, 0.3f, 2.0f}};
|
||||
EXPECT_TRUE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
|
||||
// Test that a ray starting inside the triangle but pointing away returns true
|
||||
TEST_F(LineTracerTest, RayStartsInTriangleButDoesNotIntersect)
|
||||
{
|
||||
constexpr Ray ray{{0.3f, 0.3f, 0.0f}, {0.3f, 0.3f, -1.0f}};
|
||||
EXPECT_TRUE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
|
||||
// Test that a ray not intersecting the triangle plane returns true
|
||||
TEST_F(LineTracerTest, RayMissesTriangle)
|
||||
{
|
||||
constexpr Ray ray{{2.0f, 2.0f, -1.0f}, {2.0f, 2.0f, 1.0f}};
|
||||
EXPECT_TRUE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
|
||||
// Test that a ray lying exactly in the plane of the triangle without intersecting returns true
|
||||
TEST_F(LineTracerTest, RayInPlaneNotIntersecting)
|
||||
{
|
||||
constexpr Ray ray{{-1.0f, -1.0f, 0.0f}, {1.5f, 1.5f, 0.0f}};
|
||||
EXPECT_TRUE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
|
||||
// Test edge case where the ray exactly intersects one of the triangle's vertices, expecting false
|
||||
TEST_F(LineTracerTest, RayIntersectsVertex)
|
||||
{
|
||||
const Ray ray{{-1.0f, -1.0f, -1.0f}, vertex1}; // Intersecting at vertex1
|
||||
EXPECT_FALSE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
|
||||
// Test edge case where the ray exactly intersects one of the triangle's edges, expecting false
|
||||
TEST_F(LineTracerTest, RayIntersectsEdge)
|
||||
{
|
||||
constexpr Ray ray{{-1.0f, 0.0f, -1.0f}, {0.5f, 0.0f, 0.0f}};
|
||||
// Intersecting on the edge between vertex1 and vertex2
|
||||
EXPECT_FALSE(LineTracer::CanTraceLine(ray, triangle));
|
||||
}
|
||||
Reference in New Issue
Block a user