X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=11c197e72ebb059814e0c92f685ac533b72acaa2;hb=313e10c1dcf5504789cc145166aece93d8141212;hp=845ca346eaffedf3aad1a4899b54c281c9593ff9;hpb=24f239e418599c13a9d0bdc4942c188ccf0a8437;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 845ca34..11c197e 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" @@ -32,7 +33,6 @@ public: virtual HyperBox get_axis_aligned_bounding_box() const { return *this; } virtual bool contains(const LinAl::Vector &) const; - virtual bool check_intersection(const Ray &) const; virtual unsigned get_max_ray_intersections() const { return 2; } virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; }; @@ -47,7 +47,11 @@ inline HyperBox::HyperBox() template inline HyperBox::HyperBox(const LinAl::Vector &d): dimensions(d) -{ } +{ + for(unsigned i=0; i inline HyperBox *HyperBox::clone() const @@ -64,31 +68,30 @@ 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; } -template -inline bool HyperBox::check_intersection(const Ray &ray) const -{ - return get_intersections(ray, 0, 1); -} - template inline unsigned HyperBox::get_intersections(const Ray &ray, SurfacePoint *points, unsigned size) const { using std::abs; + if(size>2) + size = 2; + LinAl::Vector half_dim = dimensions/T(2); unsigned n = 0; - for(unsigned i=0; i::get_intersections(const Ray &ray, SurfaceP for(unsigned k=0; (inside && k::get_intersections(const Ray &ray, SurfaceP } ++n; - if(n==size || n==2) - return n; } } }