Browse Source

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)
fusion360
Seth Hillbrand 2 years ago
parent
commit
4a800adffc
  1. 7
      libs/kimath/src/geometry/shape_line_chain.cpp

7
libs/kimath/src/geometry/shape_line_chain.cpp

@ -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

Loading…
Cancel
Save