]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/extrudedshape.h
Minor fixes
[libs/math.git] / source / geometry / extrudedshape.h
index 400c52b8122cdee3d45627b87822aa0bd4cea19f..78dfa4911463e57951eaa0ca4524c223ab9ce9b5 100644 (file)
@@ -41,7 +41,7 @@ template<typename T, unsigned D>
 inline ExtrudedShape<T, D>::ExtrudedShape(const Shape<T, D-1> &b, T l):
        length(l)
 {
-       if(l<=0)
+       if(l<=T(0))
                throw std::invalid_argument("ExtrudedShape::ExtrudedShape");
 
        base = b.clone();
@@ -116,7 +116,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
        {
                T offset = T();
                T limit = T();
-               if(ray.get_direction()[D-1]!=T(0))
+               if(ray_direction[D-1]!=T(0))
                {
                        offset = (half_length-ray_start[D-1])/ray_direction[D-1];
                        limit = (-half_length-ray_start[D-1])/ray_direction[D-1];
@@ -134,8 +134,8 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
 
                        SurfacePoint<T, D-1> *base_points = 0;
                        if(points)
-                               /* Shamelessly reuse the provided storage.  Align to the end of the array
-                               so processing can start from the first (nearest) point. */
+                               /* Shamelessly reuse the provided storage.  Align to the end of the
+                               array so processing can start from the first (nearest) point. */
                                base_points = reinterpret_cast<SurfacePoint<T, D-1> *>(points+size)-size;
 
                        unsigned count = base->get_intersections(base_ray, base_points, size);
@@ -147,6 +147,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
                                        points[n].position = ray_start+ray_direction*x;
                                        points[n].normal = compose(base_points[i].normal, T(0));
                                        points[n].distance = x;
+                                       points[n].entry = base_points[i].entry;
                                }
 
                                ++n;
@@ -156,7 +157,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
 
        /* If the ray is not parallel to the base space, it may pass through the
        caps. */
-       if(n<size && ray_direction[D-1])
+       if(n<size && ray_direction[D-1]!=T(0))
        {
                for(int i=-1; (n<size && i<=1); i+=2)
                {
@@ -173,6 +174,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
                                        points[n].normal = LinAl::Vector<T, D>();
                                        points[n].normal[D-1] = i;
                                        points[n].distance = x;
+                                       points[n].entry = (T(i)*ray_direction[D-1]<T(0));
                                }
 
                                ++n;