X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhalfspace.h;h=518f91ab7ad46979766f25d2ea96deb984cde345;hb=1df02cf6bf187dfc8f0afe9223dd0f4cbb90b559;hp=60f040350b0f63ac3ac48409701db028cece4353;hpb=09cc3a8648dd20e9a07d669b353c4a120b67c1c4;p=libs%2Fmath.git diff --git a/source/geometry/halfspace.h b/source/geometry/halfspace.h index 60f0403..518f91a 100644 --- a/source/geometry/halfspace.h +++ b/source/geometry/halfspace.h @@ -1,15 +1,14 @@ #ifndef MSP_GEOMETRY_HALFSPACE_H_ #define MSP_GEOMETRY_HALFSPACE_H_ -#include "boundingbox.h" #include "shape.h" namespace Msp { namespace Geometry { /** -An infinite shape consisting of the space on one side of a plane. Mostly -useful when composited with other shapes. +An unbounded shape consisting of the space on one side of a plane. Mostly +useful when intersected with other shapes. */ template class HalfSpace: public Shape @@ -34,7 +33,7 @@ public: template inline HalfSpace::HalfSpace() { - normal[0] = 1; + normal[0] = T(1); } template @@ -58,13 +57,18 @@ inline BoundingBox HalfSpace::get_axis_aligned_bounding_box() const 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)