Optimize testCourtyardClearances when moving footprints (33%->0.69%)

Check bounding boxes without hidden text first before trying to check courtyards.

See https://gitlab.com/kicad/code/kicad/-/issues/18148

(cherry picked from commit 4bf8ed32cd)
This commit is contained in:
Alex Shvartzkop 2024-06-24 06:43:58 +03:00
parent 6afd865259
commit 006f0a95c1
2 changed files with 25 additions and 18 deletions

View File

@ -33,23 +33,29 @@
void DRC_INTERACTIVE_COURTYARD_CLEARANCE::testCourtyardClearances()
{
std::vector<BOX2I> fpBBBoxes( m_FpInMove.size() );
std::vector<BOX2I> frontBBBoxes( m_FpInMove.size() );
std::vector<BOX2I> backBBBoxes( m_FpInMove.size() );
BOX2I movingBBox;
// GetCourtyard updates courtyard caches if needed
for( size_t i = 0; i < m_FpInMove.size(); i++ )
{
FOOTPRINT* fpB = m_FpInMove[i];
fpBBBoxes[i] = fpB->GetBoundingBox();
frontBBBoxes[i] = fpB->GetCourtyard( F_CrtYd ).BBoxFromCaches();
backBBBoxes[i] = fpB->GetCourtyard( B_CrtYd ).BBoxFromCaches();
BOX2I bbox = fpB->GetBoundingBox( true, false );
movingBBox.Merge( bbox );
fpBBBoxes[i] = bbox;
}
movingBBox.Inflate( m_largestCourtyardClearance );
for( FOOTPRINT* fpA: m_board->Footprints() )
{
if( fpA->IsSelected() )
continue;
BOX2I fpABBox = fpA->GetBoundingBox( true, false );
if( !movingBBox.Intersects( fpABBox ) )
continue;
const SHAPE_POLY_SET& frontA = fpA->GetCourtyard( F_CrtYd );
const SHAPE_POLY_SET& backA = fpA->GetCourtyard( B_CrtYd );
@ -63,19 +69,19 @@ void DRC_INTERACTIVE_COURTYARD_CLEARANCE::testCourtyardClearances()
frontABBox.Inflate( m_largestCourtyardClearance );
backABBox.Inflate( m_largestCourtyardClearance );
BOX2I fpABBox = fpA->GetBoundingBox();
for( size_t inMoveId = 0; inMoveId < m_FpInMove.size(); inMoveId++ )
{
FOOTPRINT* fpB = m_FpInMove[inMoveId];
const SHAPE_POLY_SET& frontB = fpB->GetCachedCourtyard( F_CrtYd );
const SHAPE_POLY_SET& backB = fpB->GetCachedCourtyard( B_CrtYd );
const BOX2I fpBBBox = fpBBBoxes[inMoveId];
const BOX2I frontBBBox = frontBBBoxes[inMoveId];
const BOX2I backBBBox = backBBBoxes[inMoveId];
int clearance;
int actual;
VECTOR2I pos;
const SHAPE_POLY_SET& frontB = fpB->GetCourtyard( F_CrtYd );
const SHAPE_POLY_SET& backB = fpB->GetCourtyard( B_CrtYd );
const BOX2I fpBBBox = fpBBBoxes[inMoveId];
const BOX2I frontBBBox = frontB.BBoxFromCaches();
const BOX2I backBBBox = backB.BBoxFromCaches();
int clearance;
int actual;
VECTOR2I pos;
if( frontA.OutlineCount() > 0 && frontB.OutlineCount() > 0
&& frontABBox.Intersects( frontBBBox ) )

View File

@ -983,9 +983,7 @@ const BOX2I FOOTPRINT::GetBoundingBox() const
const BOX2I FOOTPRINT::GetBoundingBox( bool aIncludeText, bool aIncludeInvisibleText ) const
{
std::vector<PCB_TEXT*> texts;
const BOARD* board = GetBoard();
bool isFPEdit = board && board->IsFootprintHolder();
if( board )
{
@ -1006,6 +1004,9 @@ const BOX2I FOOTPRINT::GetBoundingBox( bool aIncludeText, bool aIncludeInvisible
}
}
std::vector<PCB_TEXT*> texts;
bool isFPEdit = board && board->IsFootprintHolder();
BOX2I bbox( m_pos );
bbox.Inflate( pcbIUScale.mmToIU( 0.25 ) ); // Give a min size to the bbox