]> git.tdb.fi Git - libs/math.git/commitdiff
Avoid division by zero in HalfSpace::get_intersections
authorMikko Rasa <tdb@tdb.fi>
Sat, 22 Nov 2014 09:41:13 +0000 (11:41 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 22 Nov 2014 10:37:56 +0000 (12:37 +0200)
source/geometry/halfspace.h

index f671629e56194b0a93a00220c5ef17ef0c6ad0f7..4adc0dff45694726f399b7a07a3afff0cedcdb2c 100644 (file)
@@ -63,7 +63,12 @@ inline bool HalfSpace<T, D>::contains(const LinAl::Vector<T, D> &point) const
 template<typename T, unsigned D>
 inline unsigned HalfSpace<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *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)