]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/hypersphere.h
Properly sort intersection points for complex shapes
[libs/math.git] / source / geometry / hypersphere.h
index 35cddd1ac36461f4ee2a0e00122abda491ce3b0a..cbec2d99af744e7182f4b5f0081379b059a14d95 100644 (file)
@@ -89,10 +89,10 @@ inline unsigned HyperSphere<T, D>::get_intersections(const Ray<T, D> &ray, Surfa
        T offset = sqrt(offset_sq);
 
        unsigned n = 0;
-       for(int i=-1; i<=1; i+=2)
+       for(int i=-1; (n<size && i<=1); i+=2)
        {
                T x = mid+offset*i;
-               if(ray.check_limits(x) && n<size)
+               if(ray.check_limits(x))
                {
                        if(points)
                        {
@@ -102,8 +102,6 @@ inline unsigned HyperSphere<T, D>::get_intersections(const Ray<T, D> &ray, Surfa
                        }
 
                        ++n;
-                       if(n==size)
-                               return n;
                }
        }