inline unsigned CompositeShape<T, D, O>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
{
unsigned n = 0;
- for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
+ for(typename ShapeArray::const_iterator i=shapes.begin(); (n<size && i!=shapes.end()); ++i)
{
unsigned base = n;
unsigned count = (*i)->get_intersections(ray, points+base, size-base);
- for(unsigned j=0; j<count; ++j)
+ for(unsigned j=0; (n<size && j<count); ++j)
{
- // XXX Devise a way to reduce copies here
- SurfacePoint<T, D> pt = points[base+j];
+ SurfacePoint<T, D> &pt = points[base+j];
bool surface = Ops::init_surface();
for(typename ShapeArray::const_iterator k=shapes.begin(); k!=shapes.end(); ++k)
if(surface)
{
- if(points)
- {
- unsigned k;
- for(k=n; (k>0 && points[k-1].distance>pt.distance); --k)
- points[k] = points[k-1];
- if(base+j!=k)
- points[k] = pt;
- }
+ if(points && base+j!=n)
+ points[n] = pt;
++n;
- if(n==size)
- return n;
}
}
}
+ sort_points(points, n);
+
return n;
}