diff options
| author | Mikhail Romanko <me@blankhex.com> | 2025-02-24 22:56:16 +0300 |
|---|---|---|
| committer | Mikhail Romanko <me@blankhex.com> | 2025-02-24 22:56:16 +0300 |
| commit | cae66889a1ea21e4906f8d5b29719e9cc979bcaf (patch) | |
| tree | 6a118dcb8b1e280e074c99b61ef4403602a44a4c /test/src/TestRay3f.c | |
| parent | 67e7582d6314029cacbbfdb20378720827a678de (diff) | |
| download | bhlib-cae66889a1ea21e4906f8d5b29719e9cc979bcaf.tar.gz | |
Add 2D/3D boxes/AABBs and intersection tests.
Added support for 2D/3D boxes (or AABBs) and intersection tests between
them and rays/segments.
Diffstat (limited to 'test/src/TestRay3f.c')
| -rw-r--r-- | test/src/TestRay3f.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/src/TestRay3f.c b/test/src/TestRay3f.c index 6a80270..9366da1 100644 --- a/test/src/TestRay3f.c +++ b/test/src/TestRay3f.c @@ -86,6 +86,72 @@ BH_UNIT_TEST(Barycentric) } +BH_UNIT_TEST(RayBox) +{ + float start[3], direction[3], bMin[3], bMax[3], r[3]; + float time; + + bMin[0] =-2.0f; bMin[1] =-2.0f; bMin[2] =-2.0f; + bMax[0] = 3.0f; bMax[1] = 3.0f; bMax[2] = 3.0f; + + start[0] = 0.0f; start[1] = 0.0f; start[2] = 0.0f; + direction[0] = 1.0f; direction[1] = 0.0f; direction[2] = 0.0f; + BH_VERIFY(BH_Ray3fIntersectBox3f(start, direction, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box3fContains(bMin, bMax, r) == BH_OK); + + start[0] = -4.0f; start[1] = 0.0f; start[2] = 0.0f; + BH_VERIFY(BH_Ray3fIntersectBox3f(start, direction, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box3fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; start[2] = 0.0f; + BH_VERIFY(BH_Ray3fIntersectBox3f(start, direction, bMin, bMax, &time, r) != BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; start[2] = 0.0f; + direction[0] = -1.0f; direction[1] = 0.0f; direction[2] = 0.0f; + BH_VERIFY(BH_Ray3fIntersectBox3f(start, direction, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box3fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 4.0f; start[2] = 4.0f; + direction[0] = -1.0f; direction[1] = 0.0f; direction[2] = 0.0f; + BH_VERIFY(BH_Ray3fIntersectBox3f(start, direction, bMin, bMax, &time, r) != BH_OK); + + return 0; +} + + +BH_UNIT_TEST(SegmentBox) +{ + float start[3], end[3], bMin[3], bMax[3], r[3]; + float time; + + bMin[0] =-2.0f; bMin[1] =-2.0f; bMin[2] =-2.0f; + bMax[0] = 3.0f; bMax[1] = 3.0f; bMax[2] = 3.0f; + + start[0] = 0.0f; start[1] = 0.0f; start[2] = 0.0f; + end[0] = 5.0f; end[1] = 0.0f; end[2] = 0.0f; + BH_VERIFY(BH_Segment3fIntersectBox3f(start, end, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box3fContains(bMin, bMax, r) == BH_OK); + + start[0] = -4.0f; start[1] = 0.0f; start[2] = 0.0f; + BH_VERIFY(BH_Segment3fIntersectBox3f(start, end, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box3fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; start[2] = 0.0f; + BH_VERIFY(BH_Segment3fIntersectBox3f(start, end, bMin, bMax, &time, r) != BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; start[2] = 0.0f; + end[0] = -5.0f; end[1] = 0.0f; end[2] = 0.0f; + BH_VERIFY(BH_Segment3fIntersectBox3f(start, end, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box3fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 4.0f; start[2] = 4.0f; + end[0] = -5.0f; end[1] = 4.0f; end[2] = 0.0f; + BH_VERIFY(BH_Segment3fIntersectBox3f(start, end, bMin, bMax, &time, r) != BH_OK); + + return 0; +} + + int main(int argc, char **argv) { (void)argc; @@ -94,6 +160,8 @@ int main(int argc, char **argv) BH_UNIT_ADD(RayIntersectTriangle); BH_UNIT_ADD(SegmentIntersectTriangle); BH_UNIT_ADD(Barycentric); + BH_UNIT_ADD(RayBox); + BH_UNIT_ADD(SegmentBox); return BH_UnitRun(); } |
