From: Mikko Rasa Date: Wed, 22 May 2013 19:48:45 +0000 (+0300) Subject: Fix a case in ExtrudedShape with certain ray parameters X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a6ba5f18950f8471c5f3c168a9d65e901a8a6f2a;p=libs%2Fmath.git 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. --- 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; + } } }