X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhalfspace.h;h=4adc0dff45694726f399b7a07a3afff0cedcdb2c;hb=5bcf5a18cda4d712ca177f4ad43fea690f31e6f9;hp=9ed80ff71b85052e6525bb46fb800f775c04fe3f;hpb=484eec5f57755ae6430471b1e13b67f86f15c8fa;p=libs%2Fmath.git diff --git a/source/geometry/halfspace.h b/source/geometry/halfspace.h index 9ed80ff..4adc0df 100644 --- a/source/geometry/halfspace.h +++ b/source/geometry/halfspace.h @@ -24,7 +24,7 @@ public: const LinAl::Vector &get_normal() const { return normal; } - virtual HyperBox get_axis_aligned_bounding_box() const; + virtual BoundingBox get_axis_aligned_bounding_box() const; virtual bool contains(const LinAl::Vector &) const; virtual unsigned get_max_ray_intersections() const { return 1; } virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; @@ -33,7 +33,7 @@ public: template inline HalfSpace::HalfSpace() { - normal[0] = 1; + normal[0] = T(1); } template @@ -48,22 +48,27 @@ inline HalfSpace *HalfSpace::clone() const } template -inline HyperBox HalfSpace::get_axis_aligned_bounding_box() const +inline BoundingBox HalfSpace::get_axis_aligned_bounding_box() const { - // XXX Implement this properly - return HyperBox(); + // XXX If the normal is aligned to an axis, should the bounding box reflect that? + return ~BoundingBox(); } template inline bool HalfSpace::contains(const LinAl::Vector &point) const { - return inner_product(point, normal)<=0; + return inner_product(point, normal)<=T(0); } template inline unsigned HalfSpace::get_intersections(const Ray &ray, SurfacePoint *points, unsigned size) const { - T x = -inner_product(ray.get_start(), normal)/inner_product(ray.get_direction(), normal); + T d = inner_product(ray.get_start(), normal); + T c = inner_product(ray.get_direction(), normal); + if(c==T(0)) + return 0; + + T x = -d/c; if(ray.check_limits(x)) { if(points && size>0)