Fix pad bounding box calculation bug. (fixes lp:1202828)
This commit is contained in:
parent
cb52b9d0fe
commit
d786ac91df
|
@ -123,12 +123,77 @@ int D_PAD::boundingRadius() const
|
||||||
EDA_RECT D_PAD::GetBoundingBox() const
|
EDA_RECT D_PAD::GetBoundingBox() const
|
||||||
{
|
{
|
||||||
EDA_RECT area;
|
EDA_RECT area;
|
||||||
|
wxPoint quadrant1, quadrant2, quadrant3, quadrant4;
|
||||||
|
int x, y, dx, dy;
|
||||||
|
|
||||||
// radius of pad area, enclosed in minimum sized circle
|
switch( GetShape() )
|
||||||
int radius = boundingRadius();
|
{
|
||||||
|
case PAD_CIRCLE:
|
||||||
|
area.SetOrigin( m_Pos );
|
||||||
|
area.Inflate( m_Size.x / 2 );
|
||||||
|
break;
|
||||||
|
|
||||||
area.SetOrigin( m_Pos );
|
case PAD_OVAL:
|
||||||
area.Inflate( radius );
|
//Use the maximal two most distant points and track their rotation
|
||||||
|
// (utilise symmetry to avoid four points)
|
||||||
|
quadrant1.x = m_Size.x/2;
|
||||||
|
quadrant1.y = 0;
|
||||||
|
quadrant2.x = 0;
|
||||||
|
quadrant2.y = m_Size.y/2;
|
||||||
|
|
||||||
|
RotatePoint( &quadrant1, m_Orient );
|
||||||
|
RotatePoint( &quadrant2, m_Orient );
|
||||||
|
dx = std::max( std::abs( quadrant1.x ) , std::abs( quadrant2.x ) );
|
||||||
|
dy = std::max( std::abs( quadrant1.y ) , std::abs( quadrant2.y ) );
|
||||||
|
area.SetOrigin( m_Pos.x-dx, m_Pos.y-dy );
|
||||||
|
area.SetSize( 2*dx, 2*dy );
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PAD_RECT:
|
||||||
|
//Use two corners and track their rotation
|
||||||
|
// (utilise symmetry to avoid four points)
|
||||||
|
quadrant1.x = m_Size.x/2;
|
||||||
|
quadrant1.y = m_Size.y/2;
|
||||||
|
quadrant2.x = -m_Size.x/2;
|
||||||
|
quadrant2.y = m_Size.y/2;
|
||||||
|
|
||||||
|
RotatePoint( &quadrant1, m_Orient );
|
||||||
|
RotatePoint( &quadrant2, m_Orient );
|
||||||
|
dx = std::max( std::abs( quadrant1.x ) , std::abs( quadrant2.x ) );
|
||||||
|
dy = std::max( std::abs( quadrant1.y ) , std::abs( quadrant2.y ) );
|
||||||
|
area.SetOrigin( m_Pos.x-dx, m_Pos.y-dy );
|
||||||
|
area.SetSize( 2*dx, 2*dy );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PAD_TRAPEZOID:
|
||||||
|
//Use the four corners and track their rotation
|
||||||
|
// (Trapezoids will not be symmetric)
|
||||||
|
quadrant1.x = (m_Size.x + m_DeltaSize.y)/2;
|
||||||
|
quadrant1.y = (m_Size.y - m_DeltaSize.x)/2;
|
||||||
|
quadrant2.x = -(m_Size.x + m_DeltaSize.y)/2;
|
||||||
|
quadrant2.y = (m_Size.y + m_DeltaSize.x)/2;
|
||||||
|
quadrant3.x = -(m_Size.x - m_DeltaSize.y)/2;
|
||||||
|
quadrant3.y = -(m_Size.y + m_DeltaSize.x)/2;
|
||||||
|
quadrant4.x = (m_Size.x - m_DeltaSize.y)/2;
|
||||||
|
quadrant4.y = -(m_Size.y - m_DeltaSize.x)/2;
|
||||||
|
|
||||||
|
RotatePoint( &quadrant1, m_Orient );
|
||||||
|
RotatePoint( &quadrant2, m_Orient );
|
||||||
|
RotatePoint( &quadrant3, m_Orient );
|
||||||
|
RotatePoint( &quadrant4, m_Orient );
|
||||||
|
|
||||||
|
x = std::min( quadrant1.x, std::min( quadrant2.x, std::min( quadrant3.x, quadrant4.x) ) );
|
||||||
|
y = std::min( quadrant1.y, std::min( quadrant2.y, std::min( quadrant3.y, quadrant4.y) ) );
|
||||||
|
dx = std::max( quadrant1.x, std::max( quadrant2.x, std::max( quadrant3.x, quadrant4.x) ) );
|
||||||
|
dy = std::max( quadrant1.y, std::max( quadrant2.y, std::max( quadrant3.y, quadrant4.y) ) );
|
||||||
|
area.SetOrigin( m_Pos.x+x, m_Pos.y+y );
|
||||||
|
area.SetSize( dx-x, dy-y );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue