Skip to content

Commit

Permalink
Added a check for zero length line segment in bool LineSegment::inter…
Browse files Browse the repository at this point in the history
…sect(const BoundingSphere& bs,float& r1,float& r2) const.
  • Loading branch information
robertosfield committed Sep 12, 2006
1 parent d61bd2a commit c0fb7ad
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/osg/LineSegment.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit c0fb7ad

Please sign in to comment.