Push addition of shape width down into computeArcBBox.

Also improves performance by calling GetBoundingBox only once (this
is not always an inexpensive routine for some items, such as
polygons).
This commit is contained in:
Jeff Young 2021-01-28 22:23:54 +00:00
parent 1733a23ac7
commit 6983bcd55b
2 changed files with 11 additions and 9 deletions

View File

@ -206,8 +206,9 @@ EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem )
const BOX2I EDA_ITEM::ViewBBox() const const BOX2I EDA_ITEM::ViewBBox() const
{ {
// Basic fallback // Basic fallback
return BOX2I( VECTOR2I( GetBoundingBox().GetOrigin() ), EDA_RECT bbox = GetBoundingBox();
VECTOR2I( GetBoundingBox().GetSize() ) );
return BOX2I( bbox.GetOrigin(), bbox.GetSize() );
} }

View File

@ -958,14 +958,11 @@ const BOX2I PCB_SHAPE::ViewBBox() const
EDA_RECT bbox; EDA_RECT bbox;
bbox.SetOrigin( m_end ); bbox.SetOrigin( m_end );
computeArcBBox( bbox ); computeArcBBox( bbox );
BOX2I return_box( bbox.GetOrigin(), bbox.GetSize() ); return BOX2I( bbox.GetOrigin(), bbox.GetSize() );
return_box.Inflate( 2 * m_width );
return return_box;
} }
BOX2I return_box = EDA_ITEM::ViewBBox(); BOX2I return_box = EDA_ITEM::ViewBBox();
return_box.Inflate( 2 * m_width ); return_box.Inflate( m_width );
return return_box; return return_box;
} }
@ -1055,9 +1052,9 @@ void PCB_SHAPE::computeArcBBox( EDA_RECT& aBBox ) const
{ {
switch( quarter ) switch( quarter )
{ {
case 0: aBBox.Merge( wxPoint( m_start.x, m_start.y + radius ) ); break; // down case 0: aBBox.Merge( wxPoint( m_start.x, m_start.y + radius ) ); break; // down
case 1: aBBox.Merge( wxPoint( m_start.x - radius, m_start.y ) ); break; // left case 1: aBBox.Merge( wxPoint( m_start.x - radius, m_start.y ) ); break; // left
case 2: aBBox.Merge( wxPoint( m_start.x, m_start.y - radius ) ); break; // up case 2: aBBox.Merge( wxPoint( m_start.x, m_start.y - radius ) ); break; // up
case 3: aBBox.Merge( wxPoint( m_start.x + radius, m_start.y ) ); break; // right case 3: aBBox.Merge( wxPoint( m_start.x + radius, m_start.y ) ); break; // right
} }
@ -1069,6 +1066,10 @@ void PCB_SHAPE::computeArcBBox( EDA_RECT& aBBox ) const
quarter %= 4; quarter %= 4;
angle -= 900; angle -= 900;
} }
aBBox.Inflate( m_width ); // Technically m_width / 2, but it doesn't hurt to have the
// bounding box a bit large to account for drawing clearances,
// etc.
} }