From 5bcf5a18cda4d712ca177f4ad43fea690f31e6f9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 22 Nov 2014 11:41:13 +0200 Subject: [PATCH] Avoid division by zero in HalfSpace::get_intersections --- source/geometry/halfspace.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) -- 2.45.2