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/TestRay2f.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/TestRay2f.c')
| -rw-r--r-- | test/src/TestRay2f.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/src/TestRay2f.c b/test/src/TestRay2f.c index 811cd96..99c7821 100644 --- a/test/src/TestRay2f.c +++ b/test/src/TestRay2f.c @@ -180,6 +180,72 @@ BH_UNIT_TEST(Time) } +BH_UNIT_TEST(RayBox) +{ + float start[2], direction[2], bMin[2], bMax[2], r[2]; + float time; + + bMin[0] =-2.0f; bMin[1] =-2.0f; + bMax[0] = 3.0f; bMax[1] = 3.0f; + + start[0] = 0.0f; start[1] = 0.0f; + direction[0] = 1.0f; direction[1] = 0.0f; + BH_VERIFY(BH_Ray2fIntersectBox2f(start, direction, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box2fContains(bMin, bMax, r) == BH_OK); + + start[0] = -4.0f; start[1] = 0.0f; + BH_VERIFY(BH_Ray2fIntersectBox2f(start, direction, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box2fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; + BH_VERIFY(BH_Ray2fIntersectBox2f(start, direction, bMin, bMax, &time, r) != BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; + direction[0] = -1.0f; direction[1] = 0.0f; + BH_VERIFY(BH_Ray2fIntersectBox2f(start, direction, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box2fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 4.0f; + direction[0] = -1.0f; direction[1] = 0.0f; + BH_VERIFY(BH_Ray2fIntersectBox2f(start, direction, bMin, bMax, &time, r) != BH_OK); + + return 0; +} + + +BH_UNIT_TEST(SegmentBox) +{ + float start[2], end[2], bMin[2], bMax[2], r[2]; + float time; + + bMin[0] =-2.0f; bMin[1] =-2.0f; + bMax[0] = 3.0f; bMax[1] = 3.0f; + + start[0] = 0.0f; start[1] = 0.0f; + end[0] = 5.0f; end[1] = 0.0f; + BH_VERIFY(BH_Segment2fIntersectBox2f(start, end, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box2fContains(bMin, bMax, r) == BH_OK); + + start[0] = -4.0f; start[1] = 0.0f; + BH_VERIFY(BH_Segment2fIntersectBox2f(start, end, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box2fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; + BH_VERIFY(BH_Segment2fIntersectBox2f(start, end, bMin, bMax, &time, r) != BH_OK); + + start[0] = 4.0f; start[1] = 0.0f; + end[0] = -5.0f; end[1] = 0.0f; + BH_VERIFY(BH_Segment2fIntersectBox2f(start, end, bMin, bMax, &time, r) == BH_OK); + BH_VERIFY(BH_Box2fContains(bMin, bMax, r) == BH_OK); + + start[0] = 4.0f; start[1] = 4.0f; + end[0] = -5.0f; end[1] = 4.0f; + BH_VERIFY(BH_Segment2fIntersectBox2f(start, end, bMin, bMax, &time, r) != BH_OK); + + return 0; +} + + int main(int argc, char **argv) { (void)argc; @@ -191,6 +257,8 @@ int main(int argc, char **argv) BH_UNIT_ADD(SegmentIntersectLine); BH_UNIT_ADD(SegmentIntersectSegment); BH_UNIT_ADD(Time); + BH_UNIT_ADD(RayBox); + BH_UNIT_ADD(SegmentBox); return BH_UnitRun(); } |
