X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhalfspace.h;h=4adc0dff45694726f399b7a07a3afff0cedcdb2c;hb=5bcf5a18cda4d712ca177f4ad43fea690f31e6f9;hp=5fdea34c885eaf2dbf17296b07d4677984589fef;hpb=7353dc087872cdb93bd57cbaf2b6f0dcc21f9a03;p=libs%2Fmath.git diff --git a/source/geometry/halfspace.h b/source/geometry/halfspace.h index 5fdea34..4adc0df 100644 --- a/source/geometry/halfspace.h +++ b/source/geometry/halfspace.h @@ -33,7 +33,7 @@ public: template inline HalfSpace::HalfSpace() { - normal[0] = 1; + normal[0] = T(1); } template @@ -57,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)