X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=e45fadc12ae92d4752b523302328adeaa8df650d;hb=d12977f0eea8aec74e25402dce05d768556ffaef;hp=865b968902f078b25297138786f3602fbafa9260;hpb=643aa7b2317f88463f66da11e595ebe0f6c9621d;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 865b968..e45fadc 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -3,10 +3,9 @@ #include #include +#include #include -#include "ray.h" #include "shape.h" -#include "surfacepoint.h" namespace Msp { namespace Geometry { @@ -30,9 +29,8 @@ public: const LinAl::Vector &get_dimensions() const { return dimensions; } T get_dimension(unsigned) const; - virtual HyperBox get_axis_aligned_bounding_box() const { return *this; } + virtual BoundingBox get_axis_aligned_bounding_box() const; 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 +45,11 @@ inline HyperBox::HyperBox() template inline HyperBox::HyperBox(const LinAl::Vector &d): dimensions(d) -{ } +{ + for(unsigned i=0; i inline HyperBox *HyperBox::clone() const @@ -61,36 +63,40 @@ inline T HyperBox::get_dimension(unsigned i) const return dimensions[i]; } +template +inline BoundingBox HyperBox::get_axis_aligned_bounding_box() const +{ + LinAl::Vector half_dim = dimensions/T(2); + return BoundingBox(-half_dim, half_dim); +} + 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; } } }