From: Mikko Rasa Date: Sat, 22 Nov 2014 09:41:13 +0000 (+0200) Subject: Avoid division by zero in HalfSpace::get_intersections X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5bcf5a18cda4d712ca177f4ad43fea690f31e6f9;p=libs%2Fmath.git Avoid division by zero in HalfSpace::get_intersections --- diff --git a/source/geometry/halfspace.h b/source/geometry/halfspace.h index f671629..4adc0df 100644 --- a/source/geometry/halfspace.h +++ b/source/geometry/halfspace.h @@ -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)