Avoid int overflow in collisions

When calculating arc collisions, avoid overflowing the integer distance,
which gives a false nearest point

(cherry picked from commit 0a227ea916)
This commit is contained in:
Seth Hillbrand 2024-05-20 15:00:33 -07:00
parent 64e3e17143
commit 4a800adffc
1 changed files with 2 additions and 5 deletions

View File

@ -656,16 +656,13 @@ bool SHAPE_LINE_CHAIN::Collide( const SEG& aSeg, int aClearance, int* aActual,
return true;
}
int closest_dist = std::numeric_limits<int>::max();
if( closest_dist_sq < VECTOR2I::ECOORD_MAX )
closest_dist = sqrt( closest_dist_sq );
int dist = std::numeric_limits<int>::max();
SEG::ecoord closest_dist = sqrt( closest_dist_sq );
// Collide arc segments
for( size_t i = 0; i < ArcCount(); i++ )
{
const SHAPE_ARC& arc = Arc( i );
int dist = std::numeric_limits<int>::max();
VECTOR2I pos;
// The arcs in the chain should have zero width