]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/halfspace.h
Fix the name of the properties panel
[libs/math.git] / source / geometry / halfspace.h
index 5fdea34c885eaf2dbf17296b07d4677984589fef..518f91ab7ad46979766f25d2ea96deb984cde345 100644 (file)
@@ -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<typename T, unsigned D>
 class HalfSpace: public Shape<T, D>
@@ -33,7 +33,7 @@ public:
 template<typename T, unsigned D>
 inline HalfSpace<T, D>::HalfSpace()
 {
-       normal[0] = 1;
+       normal[0] = T(1);
 }
 
 template<typename T, unsigned D>
@@ -57,13 +57,18 @@ inline BoundingBox<T, D> HalfSpace<T, D>::get_axis_aligned_bounding_box() const
 template<typename T, unsigned D>
 inline bool HalfSpace<T, D>::contains(const LinAl::Vector<T, D> &point) const
 {
-       return inner_product(point, normal)<=0;
+       return inner_product(point, normal)<=T(0);
 }
 
 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)