X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=blobdiff_plain;f=source%2Fgeometry%2Fcompositeshape.h;h=0c2c838ec7d13364e6408872cc8dfad113ce5914;hp=f0b1f529544c12913202640c1e22604e5e5d5ded;hb=4fc002747e8138501d08942be247e60cd99ac404;hpb=7919982691f0b8c69d8bef1bf6471b1e7a312163 diff --git a/source/geometry/compositeshape.h b/source/geometry/compositeshape.h index f0b1f52..0c2c838 100644 --- a/source/geometry/compositeshape.h +++ b/source/geometry/compositeshape.h @@ -21,7 +21,6 @@ protected: ShapeArray shapes; unsigned max_isect; - unsigned min_scratch; CompositeShape() { } CompositeShape(const Shape &, const Shape &); @@ -66,20 +65,14 @@ template inline void CompositeShape::init() { max_isect = 0; - min_scratch = 0; for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) - { - unsigned mi = (*i)->get_max_ray_intersections(); - max_isect += mi; - min_scratch = std::max(min_scratch, mi); - } + max_isect += (*i)->get_max_ray_intersections(); } template inline CompositeShape::CompositeShape(const CompositeShape &other): shapes(other.shapes), - max_isect(other.max_isect), - min_scratch(other.min_scratch) + max_isect(other.max_isect) { for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) *i = (*i)->clone(); @@ -96,7 +89,6 @@ inline CompositeShape &CompositeShape::operator=(const Composi *i = (*i)->clone(); max_isect = other.max_isect; - min_scratch = other.min_scratch; } template @@ -123,12 +115,12 @@ inline BoundingBox CompositeShape::get_axis_aligned_bounding_box( template inline bool CompositeShape::contains(const LinAl::Vector &point) const { - bool inside = Ops::init_inside(); + bool inside = false; for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) { - inside = Ops::combine_inside(inside, (*i)->contains(point)); - if(Ops::is_inside_decided(inside)) - break; + inside = (*i)->contains(point); + if(Ops::shortcircuit(inside)) + return inside; } return inside; } @@ -138,39 +130,58 @@ inline unsigned CompositeShape::get_intersections(const Ray &ray, { SurfacePoint *buffer = points; unsigned buf_size = size; - if(!points) + if(!points && !Ops::shortcircuit(true)) { - buffer = new SurfacePoint[min_scratch]; - buf_size = min_scratch; + buffer = new SurfacePoint[max_isect]; + buf_size = max_isect; } + int start_nesting = 0; unsigned n = 0; - for(typename ShapeArray::const_iterator i=shapes.begin(); (nget_intersections(ray, buffer+base, buf_size-base); - for(unsigned j=0; (ncontains(ray.get_start()); + + if(!count && !start_inside) { - SurfacePoint &pt = buffer[base+j]; + if(Ops::shortcircuit(false)) + return 0; + continue; + } - bool surface = Ops::init_surface(); - for(typename ShapeArray::const_iterator k=shapes.begin(); k!=shapes.end(); ++k) - if(k!=i) - surface = Ops::combine_surface(surface, (*k)->contains(pt.position)); + start_nesting += start_inside; - if(surface) - { - if(points && base+j!=n) - points[n] = pt; + if(!base) + { + n = count; + continue; + } - ++n; + sort_points(buffer, base+count); + + int nesting = start_nesting; + unsigned k = 0; + for(unsigned j=0; j