From a6ba5f18950f8471c5f3c168a9d65e901a8a6f2a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 22 May 2013 22:48:45 +0300 Subject: [PATCH] Fix a case in ExtrudedShape with certain ray parameters A ray starting outside of the length of the shape and pointing away from it caused a local ray with a negative limit to be constructed. --- source/geometry/extrudedshape.h | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/source/geometry/extrudedshape.h b/source/geometry/extrudedshape.h index de582e3..c00111a 100644 --- a/source/geometry/extrudedshape.h +++ b/source/geometry/extrudedshape.h @@ -125,28 +125,32 @@ inline unsigned ExtrudedShape::get_intersections(const Ray &ray, Sur if(offset base_ray(LinAl::Vector(ray_start+ray_direction*offset), - base_dir, (limit-offset)*distortion); - - SurfacePoint *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. */ - base_points = reinterpret_cast *>(points+size)-size; - - unsigned count = base->get_intersections(base_ray, base_points, size); - for(unsigned i=0; (n=offset) { + T distortion = base_dir.norm(); + Ray base_ray(LinAl::Vector(ray_start+ray_direction*offset), + base_dir, (limit-offset)*distortion); + + SurfacePoint *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. */ + base_points = reinterpret_cast *>(points+size)-size; + + unsigned count = base->get_intersections(base_ray, base_points, size); + for(unsigned i=0; (n(base_points[i].normal, T(0)); - points[n].distance = x; - } + if(points) + { + T x = offset+base_points[i].distance/distortion; + points[n].position = ray_start+ray_direction*x; + points[n].normal = LinAl::Vector(base_points[i].normal, T(0)); + points[n].distance = x; + } - ++n; + ++n; + } } } -- 2.43.0