]> 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 de028fa580d627ed06d1cb811f43b104a450ed7a..cbec2d99af744e7182f4b5f0081379b059a14d95 100644 (file)
@@ -23,7 +23,7 @@ private:
        T radius;
 
 public:
-       HyperSphere();
+       HyperSphere(): radius(1) { }
        explicit HyperSphere(T);
 
        virtual HyperSphere *clone() const;
@@ -37,11 +37,6 @@ public:
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
 };
 
-template<typename T, unsigned D>
-inline HyperSphere<T, D>::HyperSphere():
-       radius(1)
-{ }
-
 template<typename T, unsigned D>
 inline HyperSphere<T, D>::HyperSphere(T r):
        radius(r)
@@ -94,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)
                        {
@@ -107,8 +102,6 @@ inline unsigned HyperSphere<T, D>::get_intersections(const Ray<T, D> &ray, Surfa
                        }
 
                        ++n;
-                       if(n==size)
-                               return n;
                }
        }