Feature/more constexpr (#125)

* added constexpr

* fix

* improved stuff

* added const

* improvement

* fix

* fix

* patch
This commit is contained in:
2025-12-24 02:32:14 +03:00
committed by GitHub
parent 897484bea1
commit d935caf1a4
36 changed files with 543 additions and 399 deletions

View File

@@ -10,48 +10,48 @@ using Triangle3 = omath::Triangle<Vector3<float>>;
TEST(LineTracerMore2, UGreaterThanOneReturnsEnd)
{
Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
constexpr Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
// choose ray so barycentric u > 1
Ray ray; ray.start = {2.f, -1.f, -1.f}; ray.end = {2.f, -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(LineTracerMore2, VGreaterThanOneReturnsEnd)
{
Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
constexpr Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
// choose ray so barycentric v > 1
Ray ray; ray.start = {-1.f, 2.f, -1.f}; ray.end = {-1.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(LineTracerMore2, UPlusVGreaterThanOneReturnsEnd)
{
Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
constexpr Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
// Ray aimed so u+v > 1 (outside triangle region)
Ray ray; ray.start = {1.f, 1.f, -1.f}; ray.end = {1.f, 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(LineTracerMore2, DirectionVectorNormalizedProducesUnitLength)
{
Ray r; r.start = {0.f,0.f,0.f}; r.end = {0.f,3.f,4.f};
auto dir = r.direction_vector_normalized();
auto len = dir.length();
const auto dir = r.direction_vector_normalized();
const auto len = dir.length();
EXPECT_NEAR(len, 1.f, 1e-6f);
}
TEST(LineTracerMore2, ZeroLengthRayHandled)
{
Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
constexpr Triangle3 tri({0.f,0.f,0.f},{1.f,0.f,0.f},{0.f,1.f,0.f});
Ray ray; ray.start = {0.f,0.f,0.f}; ray.end = {0.f,0.f,0.f};
// Zero-length ray: direction length == 0; algorithm should handle without crash
auto hit = LineTracer::get_ray_hit_point(ray, tri);
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
EXPECT_EQ(hit, ray.end);
}