Improve hit-test logic by gradually increasing threshold.

Fixes: lp:1828222
* https://bugs.launchpad.net/kicad/+bug/1828222
This commit is contained in:
Jeff Young 2019-05-15 18:00:49 +01:00
parent ddc6079ceb
commit eba892009d
1 changed files with 20 additions and 3 deletions

View File

@ -449,8 +449,16 @@ EDA_ITEM* EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T*
if( !start )
return nullptr;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( start, aFilterList, (wxPoint) aWhere, m_unit, m_convert );
int thresholdMax = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
for( int threshold : { 0, thresholdMax/2, thresholdMax } )
{
collector.m_Threshold = threshold;
collector.Collect( start, aFilterList, (wxPoint) aWhere, m_unit, m_convert );
if( collector.GetCount() > 0 )
break;
}
bool anyCollected = collector.GetCount() != 0;
@ -673,7 +681,16 @@ EDA_ITEM* EE_SELECTION_TOOL::GetNode( VECTOR2I aPosition )
{
EE_COLLECTOR collector;
collector.Collect( m_frame->GetScreen()->GetDrawItems(), nodeTypes, (wxPoint) aPosition );
int thresholdMax = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
for( int threshold : { 0, thresholdMax/2, thresholdMax } )
{
collector.m_Threshold = threshold;
collector.Collect( m_frame->GetScreen()->GetDrawItems(), nodeTypes, (wxPoint) aPosition );
if( collector.GetCount() > 0 )
break;
}
return collector.GetCount() ? collector[ 0 ] : nullptr;
}