Performance fixes for the board from hell....

This commit is contained in:
Jeff Young 2022-03-08 23:54:34 +00:00
parent 392a3ec131
commit e4b56ab7f1
3 changed files with 34 additions and 3 deletions

View File

@ -1518,7 +1518,7 @@ bool SHAPE_POLY_SET::Collide( const SHAPE* aShape, int aClearance, int* aActual,
return false;
}
const_cast<SHAPE_POLY_SET*>( this )->CacheTriangulation( true );
const_cast<SHAPE_POLY_SET*>( this )->CacheTriangulation( false );
int actual = INT_MAX;
VECTOR2I location;

View File

@ -320,11 +320,37 @@ public:
*/
bool QueryColliding( EDA_RECT aBox, SHAPE* aRefShape, PCB_LAYER_ID aLayer ) const
{
SHAPE_POLY_SET* poly = dynamic_cast<SHAPE_POLY_SET*>( aRefShape );
int min[2] = { aBox.GetX(), aBox.GetY() };
int max[2] = { aBox.GetRight(), aBox.GetBottom() };
bool collision = false;
auto visit =
// Special case the polygon case. Otherwise we'll call its Collide() method which will
// triangulate it as well and then do triangle/triangle collisions. This ends up being
// slower than 4 calls to PointInside().
auto polyVisitor =
[&]( ITEM_WITH_SHAPE* aItem ) -> bool
{
SHAPE* shape = aItem->shape;
wxASSERT( dynamic_cast<SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI*>( shape ) );
auto tri = static_cast<SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI*>( shape );
const SHAPE_LINE_CHAIN& outline = poly->Outline( 0 );
if( outline.PointInside( tri->GetPoint( 0 ) )
|| outline.PointInside( tri->GetPoint( 1 ) )
|| outline.PointInside( tri->GetPoint( 2 ) )
|| tri->PointInside( outline.CPoint( 0 ) ) )
{
collision = true;
return false;
}
return true;
};
auto visitor =
[&]( ITEM_WITH_SHAPE* aItem ) -> bool
{
if( aRefShape->Collide( aItem->shape, 0 ) )
@ -336,7 +362,10 @@ public:
return true;
};
this->m_tree[aLayer]->Search( min, max, visit );
if( poly && poly->OutlineCount() == 1 )
this->m_tree[aLayer]->Search( min, max, polyVisitor );
else
this->m_tree[aLayer]->Search( min, max, visitor );
return collision;
}

View File

@ -997,6 +997,8 @@ void ZONE::CacheTriangulation( PCB_LAYER_ID aLayer )
{
for( std::pair<const PCB_LAYER_ID, std::shared_ptr<SHAPE_POLY_SET>>& pair : m_FilledPolysList )
pair.second->CacheTriangulation();
m_Poly->CacheTriangulation( false );
}
else
{