mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 07:23:26 +00:00
improved tests
This commit is contained in:
@@ -59,7 +59,7 @@ namespace omath::collision
|
|||||||
if (tHit <= kEpsilon)
|
if (tHit <= kEpsilon)
|
||||||
return ray.end;
|
return ray.end;
|
||||||
}
|
}
|
||||||
else if (tHit <= kEpsilon || tHit >= 1.0f - kEpsilon)
|
else if (tHit <= kEpsilon || tHit > 1.0f - kEpsilon)
|
||||||
return ray.end;
|
return ray.end;
|
||||||
|
|
||||||
return ray.start + rayDir * tHit;
|
return ray.start + rayDir * tHit;
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ using namespace omath::collision;
|
|||||||
|
|
||||||
using Vec3 = Vector3<float>;
|
using Vec3 = Vector3<float>;
|
||||||
|
|
||||||
namespace {
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constants & helpers
|
// Constants & helpers
|
||||||
@@ -33,8 +34,10 @@ bool VecEqual(const Vec3& a, const Vec3& b, float tol = kTol)
|
|||||||
class LineTracerFixture : public ::testing::Test
|
class LineTracerFixture : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
LineTracerFixture()
|
LineTracerFixture() :
|
||||||
: triangle({0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}) {}
|
triangle({0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f})
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Triangle<Vec3> triangle;
|
Triangle<Vec3> triangle;
|
||||||
};
|
};
|
||||||
@@ -49,7 +52,9 @@ struct TraceCase
|
|||||||
};
|
};
|
||||||
|
|
||||||
class CanTraceLineParam : public LineTracerFixture,
|
class CanTraceLineParam : public LineTracerFixture,
|
||||||
public ::testing::WithParamInterface<TraceCase> {};
|
public ::testing::WithParamInterface<TraceCase>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
TEST_P(CanTraceLineParam, VariousRays)
|
TEST_P(CanTraceLineParam, VariousRays)
|
||||||
{
|
{
|
||||||
@@ -76,10 +81,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
TEST_F(LineTracerFixture, HitPointCorrect)
|
TEST_F(LineTracerFixture, HitPointCorrect)
|
||||||
{
|
{
|
||||||
Ray ray{{0.3f, 0.3f, -1.f}, {0.3f, 0.3f, 1.f}};
|
constexpr Ray ray{{0.3f, 0.3f, -1.f}, {0.3f, 0.3f, 1.f}};
|
||||||
Vec3 expected{0.3f, 0.3f, 0.f};
|
constexpr Vec3 expected{0.3f, 0.3f, 0.f};
|
||||||
|
|
||||||
Vec3 hit = LineTracer::GetRayHitPoint(ray, triangle);
|
const Vec3 hit = LineTracer::GetRayHitPoint(ray, triangle);
|
||||||
ASSERT_FALSE(VecEqual(hit, ray.end));
|
ASSERT_FALSE(VecEqual(hit, ray.end));
|
||||||
EXPECT_TRUE(VecEqual(hit, expected));
|
EXPECT_TRUE(VecEqual(hit, expected));
|
||||||
}
|
}
|
||||||
@@ -89,12 +94,28 @@ TEST_F(LineTracerFixture, HitPointCorrect)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
TEST_F(LineTracerFixture, DistantTriangleClear)
|
TEST_F(LineTracerFixture, DistantTriangleClear)
|
||||||
{
|
{
|
||||||
Ray short_ray{{0.f, 0.f, 0.f}, {0.f, 0.f, 1.f}};
|
constexpr Ray short_ray{{0.f, 0.f, 0.f}, {0.f, 0.f, 1.f}};
|
||||||
Triangle<Vec3> distant{{1000.f,1000.f,1000.f},
|
constexpr Triangle<Vec3> distant{{1000.f, 1000.f, 1000.f},
|
||||||
{1001.f, 1000.f, 1000.f},
|
{1001.f, 1000.f, 1000.f},
|
||||||
{1000.f, 1001.f, 1000.f}};
|
{1000.f, 1001.f, 1000.f}};
|
||||||
|
|
||||||
EXPECT_TRUE(LineTracer::CanTraceLine(short_ray, distant));
|
EXPECT_TRUE(LineTracer::CanTraceLine(short_ray, distant));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LineTracerTraceRayEdge, CantHit)
|
||||||
|
{
|
||||||
|
constexpr omath::Triangle<Vector3<float>> triangle{{2, 0, 0}, {2, 2, 0}, {2, 2, 2}};
|
||||||
|
|
||||||
|
constexpr Ray ray{{}, {1.0, 0, 0}, false};
|
||||||
|
|
||||||
|
EXPECT_TRUE(omath::collision::LineTracer::CanTraceLine(ray, triangle));
|
||||||
|
}
|
||||||
|
TEST(LineTracerTraceRayEdge, CanHit)
|
||||||
|
{
|
||||||
|
constexpr omath::Triangle<Vector3<float>> triangle{{2, 0, 0}, {2, 2, 0}, {2, 2, 2}};
|
||||||
|
|
||||||
|
constexpr Ray ray{{}, {2.1, 0, 0}, false};
|
||||||
|
auto endPoint = omath::collision::LineTracer::GetRayHitPoint(ray, triangle);
|
||||||
|
EXPECT_FALSE(omath::collision::LineTracer::CanTraceLine(ray, triangle));
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user