Return closest point on line-circle intersection

Don't only look for the segment endpoints when asking the closest point.
If we have a collision, we need to get the collision point
This commit is contained in:
Seth Hillbrand 2024-05-20 16:27:54 -07:00
parent a5436c92d1
commit 57c0953c39
1 changed files with 11 additions and 1 deletions

View File

@ -84,7 +84,17 @@ public:
if( dist_sq == 0 || dist_sq < SEG::Square( minDist ) )
{
if( aLocation )
*aLocation = pn;
{
if( std::vector<VECTOR2I> pts = m_circle.Intersect( aSeg );
!pts.empty() && dist_sq == 0 )
{
*aLocation = m_circle.Intersect( aSeg )[0];
}
else
{
*aLocation = pn;
}
}
if( aActual )
*aActual = std::max( 0, (int) sqrt( dist_sq ) - m_circle.Radius );