From: Mikko Rasa Date: Sat, 2 Jul 2016 17:00:50 +0000 (+0300) Subject: Ensure that HyperBox does not produce duplicate intersections X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=818f9df5f383adad815f6f3276bfc1fa30c25681;p=libs%2Fmath.git Ensure that HyperBox does not produce duplicate intersections In certain corner cases (literally) two coincident intersections could be produced when the ray passed through the edge of the box, preventing intersctions on the opposite side from being produced. --- diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 546ad0e..b9fad33 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -112,14 +112,23 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP { if(points) { - points[n].position = p; - points[n].normal = LinAl::Vector(); - points[n].normal[i] = j; - points[n].distance = x; - points[n].entry = (T(j)*ray.get_direction()[i]0 && entry!=points[0].entry) + { + if(entry) + points[1] = points[0]; + else + ++k; + } + if(k(); + points[k].normal[i] = j; + points[k].distance = x; + points[k].entry = (T(j)*ray.get_direction()[i]