Fix SHAPE_ARC hittest and adjust radius return

The hittest needs to use distance calc rather than squared distance.
This also adjusts the radius value to be double as to avoid unneeded
loss of precision
This commit is contained in:
Seth Hillbrand 2020-06-13 11:21:14 -07:00
parent 4d4d24fc61
commit a5500973a2
2 changed files with 4 additions and 4 deletions

View File

@ -106,7 +106,7 @@ public:
void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } ); void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
int GetRadius() const; double GetRadius() const;
SEG GetChord() const SEG GetChord() const
{ {

View File

@ -143,7 +143,7 @@ void SHAPE_ARC::update_bbox()
// count through quadrants included in arc // count through quadrants included in arc
for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle ) for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
{ {
const int radius = GetRadius(); const int radius = KiROUND( GetRadius() );
VECTOR2I quad_pt = GetCenter(); VECTOR2I quad_pt = GetCenter();
switch( quad_angle % 4 ) switch( quad_angle % 4 )
@ -184,7 +184,7 @@ bool SHAPE_ARC::Collide( const VECTOR2I& aP, int aClearance ) const
if( !bbox.Contains( aP ) ) if( !bbox.Contains( aP ) )
return false; return false;
auto dist = ( aP - GetCenter() ).SquaredEuclideanNorm(); auto dist = ( aP - GetCenter() ).EuclideanNorm();
return dist <= ( GetRadius() + minDist ) && dist >= ( GetRadius() - minDist ); return dist <= ( GetRadius() + minDist ) && dist >= ( GetRadius() - minDist );
} }
@ -229,7 +229,7 @@ double SHAPE_ARC::GetCentralAngle() const
} }
int SHAPE_ARC::GetRadius() const double SHAPE_ARC::GetRadius() const
{ {
return ( m_start - GetCenter() ).EuclideanNorm(); return ( m_start - GetCenter() ).EuclideanNorm();
} }