X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhalfspace.h;h=518f91ab7ad46979766f25d2ea96deb984cde345;hb=2087c3bb9e6087ccce86360c1c57823aa8a9ff40;hp=f671629e56194b0a93a00220c5ef17ef0c6ad0f7;hpb=fb9e6b5ff48e10ea2217cf539e0461956abf02cf;p=libs%2Fmath.git diff --git a/source/geometry/halfspace.h b/source/geometry/halfspace.h index f671629..518f91a 100644 --- a/source/geometry/halfspace.h +++ b/source/geometry/halfspace.h @@ -7,8 +7,8 @@ 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 @@ -63,7 +63,12 @@ inline bool HalfSpace::contains(const LinAl::Vector &point) const 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)