X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=865b968902f078b25297138786f3602fbafa9260;hb=643aa7b2317f88463f66da11e595ebe0f6c9621d;hp=6248d6b0920e906f5bad1ee1ce1b9ba6fbb97fc4;hpb=9260eee3126731c1e6b54ce3407be757d0d71716;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 6248d6b..865b968 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -11,6 +11,10 @@ namespace Msp { namespace Geometry { +/** +A shape bounded by planar faces at right angles to each other. Two- and three- +dimensional cases are Rectangle and Box, respectively. +*/ template class HyperBox: public Shape { @@ -60,6 +64,8 @@ inline T HyperBox::get_dimension(unsigned i) const template inline bool HyperBox::contains(const LinAl::Vector &point) const { + using std::abs; + for(unsigned i=0; idimensions[i]/2) return false; @@ -79,7 +85,6 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP LinAl::Vector half_dim = dimensions/T(2); unsigned n = 0; - T first_depth = T(); for(unsigned i=0; i::get_intersections(const Ray &ray, SurfaceP for(int j=-1; j<=1; j+=2) { T x = (T(j)*half_dim[i]-ray.get_start()[i])/ray.get_direction()[i]; - if(x<0) + if(!ray.check_limits(x)) continue; LinAl::Vector p = ray.get_start()+ray.get_direction()*x; @@ -104,9 +109,9 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP points[n].position = p; points[n].normal = LinAl::Vector(); points[n].normal[i] = j; - if(n==0) - first_depth = x; - else if(n==1 && x