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

@@ -8,17 +8,17 @@ using namespace omath::collision;
TEST(LineTracerExtra, MissParallel)
{
Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
Ray ray{ {0.3f,0.3f,1.f}, {0.3f,0.3f,2.f}, false };// parallel above triangle
auto hit = LineTracer::get_ray_hit_point(ray, tri);
constexpr Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
constexpr Ray ray{ {0.3f,0.3f,1.f}, {0.3f,0.3f,2.f}, false }; // parallel above triangle
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
EXPECT_EQ(hit, ray.end);
}
TEST(LineTracerExtra, HitCenter)
{
Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
Ray ray{ {0.3f,0.3f,-1.f}, {0.3f,0.3f,1.f}, false };
auto hit = LineTracer::get_ray_hit_point(ray, tri);
constexpr Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
constexpr Ray ray{ {0.3f,0.3f,-1.f}, {0.3f,0.3f,1.f}, false };
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
ASSERT_FALSE(hit == ray.end);
EXPECT_NEAR(hit.x, 0.3f, 1e-6f);
EXPECT_NEAR(hit.y, 0.3f, 1e-6f);
@@ -27,9 +27,9 @@ TEST(LineTracerExtra, HitCenter)
TEST(LineTracerExtra, HitOnEdge)
{
Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
Ray ray{ {0.0f,0.0f,1.f}, {0.0f,0.0f,0.f}, false };
auto hit = LineTracer::get_ray_hit_point(ray, tri);
constexpr Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
constexpr Ray ray{ {0.0f,0.0f,1.f}, {0.0f,0.0f,0.f}, false };
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
// hitting exact vertex/edge may be considered miss; ensure function handles without crash
if (hit != ray.end)
{
@@ -40,9 +40,9 @@ TEST(LineTracerExtra, HitOnEdge)
TEST(LineTracerExtra, InfiniteRayIgnoredIfBehind)
{
Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
constexpr Triangle<Vector3<float>> tri({0,0,0},{1,0,0},{0,1,0});
// Ray pointing away but infinite_length true should be ignored
Ray ray{ {0.5f,0.5f,-1.f}, {0.5f,0.5f,-2.f}, true };
auto hit = LineTracer::get_ray_hit_point(ray, tri);
constexpr Ray ray{ {0.5f,0.5f,-1.f}, {0.5f,0.5f,-2.f}, true };
const auto hit = LineTracer::get_ray_hit_point(ray, tri);
EXPECT_EQ(hit, ray.end);
}