Smarten up the guess selection routine to pick closest item.

Fixes https://gitlab.com/kicad/code/kicad/issues/5697
This commit is contained in:
Jeff Young 2020-09-19 15:55:05 +01:00
parent d402d93487
commit 39bdc547af
1 changed files with 31 additions and 0 deletions

View File

@ -699,6 +699,37 @@ void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const
collector.Transfer( j ); collector.Transfer( j );
} }
} }
// Construct a tight box (1/2 height and width) around the center of the closest item.
// All items which exist at least partly outside this box have sufficient other areas
// for selection and can be dropped.
EDA_ITEM* closest = nullptr;
int closestDist = INT_MAX;
for( EDA_ITEM* item : collector )
{
int dist = EuclideanNorm( item->GetBoundingBox().GetCenter() - (wxPoint) aPos );
if( dist < closestDist )
{
closestDist = dist;
closest = item;
}
}
EDA_RECT tightBox = closest->GetBoundingBox();
tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
for( int i = collector.GetCount() - 1; i >= 0; --i )
{
EDA_ITEM* item = collector[ i ];
if( item == closest )
continue;
if( !item->HitTest( tightBox, true ) )
collector.Transfer( item );
}
} }