X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=9a161f35fb0fdbc5ff604735d51eb6e1d060eeaf;hb=827b227ae53884109b6885ccd1424dda8c0b3725;hp=6248d6b0920e906f5bad1ee1ce1b9ba6fbb97fc4;hpb=9260eee3126731c1e6b54ce3407be757d0d71716;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 6248d6b..9a161f3 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "ray.h" #include "shape.h" @@ -11,6 +12,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 { @@ -43,7 +48,11 @@ inline HyperBox::HyperBox() template inline HyperBox::HyperBox(const LinAl::Vector &d): dimensions(d) -{ } +{ + for(unsigned i=0; i inline HyperBox *HyperBox::clone() const @@ -60,8 +69,10 @@ 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) + if(abs(point[i])>dimensions[i]/T(2)) return false; return true; } @@ -77,18 +88,20 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP { using std::abs; + if(size>2) + size = 2; + LinAl::Vector half_dim = dimensions/T(2); unsigned n = 0; - T first_depth = T(); - for(unsigned i=0; i p = ray.get_start()+ray.get_direction()*x; @@ -97,22 +110,20 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP for(unsigned k=0; (inside && k(); points[n].normal[i] = j; - if(n==0) - first_depth = x; - else if(n==1 && x