Negrini085 / PhotoNim

PhotoNim: a CPU raytracer with BVH optimization based on kmeans clustering
https://negrini085.github.io/PhotoNim/
GNU General Public License v3.0
4 stars 1 forks source link

AABB checkIntersection proc #38

Closed Negrini085 closed 5 months ago

Negrini085 commented 5 months ago

I found out about this bug in the following code line about checkIntersection proc testing: https://github.com/Negrini085/PhotoNim/blob/fd383ca4f1ee326edce0011b0e95f514538fbec7/tests/hitrecord.nim#L34 I will now address the whole problem. I am testing ray intersection with aabb, and the test suite is the following:

suite "HitLeafs":

    setup:
        let
            aabb1 = (newPoint3D(-1, -1, -1), newPoint3D(1, 1, 1))
            aabb2 = (newPoint3D(-1, 0, 1), newPoint3D(1, 2, 3))

    teardown:
        discard aabb1
        discard aabb2

    test "checkIntersection proc":
        # Checking checkIntersection proc, states wether an aabb hit occurred or not
        var
            ray1 = newRay(newPoint3D(-2, 0, 0), eX)
            ray2 = newRay(newPoint3D(0, 0.5, 2), -eZ)
            ray3 = newRay(newPoint3D(-2, -2, -2), -eX)
            ray4 = newRay(newPoint3D(0, 0, 0), -eX)
            ray5 = newRay(newPoint3D(-2, 0, 0), -eX)

        # First aabb
        check aabb1.checkIntersection(ray1)
        check aabb1.checkIntersection(ray2)
        check not aabb1.checkIntersection(ray3)
        check aabb1.checkIntersection(ray4)
        check aabb1.checkIntersection(ray5)         # Why is this passing?? That should not happen, negative times

        # Second aabb
        check not aabb2.checkIntersection(ray1)
        check aabb2.checkIntersection(ray2)
        check not aabb2.checkIntersection(ray3)
        check not aabb2.checkIntersection(ray4)
        check not aabb2.checkIntersection(ray5)

Ray5 should not intersect the aabb at positive times, so why the test still passes? I feel like there is something wrong in checkIntersection procedure.