mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Feature/more constexpr (#125)
* added constexpr * fix * improved stuff * added const * improvement * fix * fix * patch
This commit is contained in:
@@ -11,53 +11,53 @@ using Triangle3 = omath::Triangle<Vector3<float>>;
|
||||
TEST(LineTracerMore, ParallelRayReturnsEnd)
|
||||
{
|
||||
// Ray parallel to triangle plane: construct triangle in XY plane and ray along X axis
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
constexpr Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
Ray ray; ray.start = {0.f,0.f,1.f}; ray.end = {1.f,0.f,1.f};
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
EXPECT_EQ(hit, ray.end);
|
||||
}
|
||||
|
||||
TEST(LineTracerMore, UOutOfRangeReturnsEnd)
|
||||
{
|
||||
// Construct a ray that misses due to u < 0
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
constexpr Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
Ray ray; ray.start = {-1.f,-1.f,-1.f}; ray.end = {-0.5f,-1.f,1.f};
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
EXPECT_EQ(hit, ray.end);
|
||||
}
|
||||
|
||||
TEST(LineTracerMore, VOutOfRangeReturnsEnd)
|
||||
{
|
||||
// Construct ray that has v < 0
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
constexpr Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
Ray ray; ray.start = {2.f,2.f,-1.f}; ray.end = {2.f,2.f,1.f};
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
EXPECT_EQ(hit, ray.end);
|
||||
}
|
||||
|
||||
TEST(LineTracerMore, THitTooSmallReturnsEnd)
|
||||
{
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
constexpr Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
Ray ray; ray.start = {0.f,0.f,0.0000000001f}; ray.end = {0.f,0.f,1.f};
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
EXPECT_EQ(hit, ray.end);
|
||||
}
|
||||
|
||||
TEST(LineTracerMore, THitGreaterThanOneReturnsEnd)
|
||||
{
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
constexpr Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
// Choose a ray and compute t_hit locally to assert consistency
|
||||
Ray ray; ray.start = {0.f,0.f,-1.f}; ray.end = {0.f,0.f,-0.5f};
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
|
||||
const float k_epsilon = std::numeric_limits<float>::epsilon();
|
||||
const auto side_a = tri.side_a_vector();
|
||||
const auto side_b = tri.side_b_vector();
|
||||
constexpr float k_epsilon = std::numeric_limits<float>::epsilon();
|
||||
constexpr auto side_a = tri.side_a_vector();
|
||||
constexpr auto side_b = tri.side_b_vector();
|
||||
const auto ray_dir = ray.direction_vector();
|
||||
const auto p = ray_dir.cross(side_b);
|
||||
const auto det = side_a.dot(p);
|
||||
@@ -82,21 +82,21 @@ TEST(LineTracerMore, THitGreaterThanOneReturnsEnd)
|
||||
TEST(LineTracerMore, InfiniteLengthWithSmallTHitReturnsEnd)
|
||||
{
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
Triangle3 tri2(Vector3<float>{0.f,0.f,-1e-8f}, Vector3<float>{1.f,0.f,-1e-8f}, Vector3<float>{0.f,1.f,-1e-8f});
|
||||
constexpr Triangle3 tri2(Vector3<float>{0.f,0.f,-1e-8f}, Vector3<float>{1.f,0.f,-1e-8f}, Vector3<float>{0.f,1.f,-1e-8f});
|
||||
Ray ray; ray.start = {0.f,0.f,0.f}; ray.end = {0.f,0.f,1.f}; ray.infinite_length = true;
|
||||
// Create triangle slightly behind so t_hit <= eps
|
||||
tri = tri2;
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
EXPECT_EQ(hit, ray.end);
|
||||
}
|
||||
|
||||
TEST(LineTracerMore, SuccessfulHitReturnsPoint)
|
||||
{
|
||||
Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
constexpr Triangle3 tri(Vector3<float>{0.f,0.f,0.f}, Vector3<float>{1.f,0.f,0.f}, Vector3<float>{0.f,1.f,0.f});
|
||||
Ray ray; ray.start = {0.1f,0.1f,-1.f}; ray.end = {0.1f,0.1f,1.f};
|
||||
|
||||
auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
|
||||
EXPECT_NE(hit, ray.end);
|
||||
// Hit should be on plane z=0 and near x=0.1,y=0.1
|
||||
EXPECT_NEAR(hit.z, 0.f, 1e-6f);
|
||||
|
||||
Reference in New Issue
Block a user