From c7906d5412628fdca72be4895822272b2614ec46 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 12 Sep 2006 12:35:20 +0000 Subject: [PATCH] Added a check for zero length line segment in bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const. --- src/osg/LineSegment.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/osg/LineSegment.cpp b/src/osg/LineSegment.cpp index b123233f7..09b968fe2 100644 --- a/src/osg/LineSegment.cpp +++ b/src/osg/LineSegment.cpp @@ -180,6 +180,21 @@ bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const Vec3 se = _e-_s; float a = se.length2(); + + // check for zero length segment. + if (a==0.0) + { + // check if start point outside sphere radius + if (c>0.0) return false; + + // length segment within radius of bounding sphere but zero length + // so return true, and set the ratio so the start point is the one + // to be used. + r1 = 1.0f; + r2 = 0.0f; + return true; + } + float b = sm*se*2.0f; float d = b*b-4.0f*a*c; @@ -188,6 +203,7 @@ bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const d = sqrtf(d); + float div = 1.0f/(2.0f*a); r1 = (-b-d)*div;