From 8590809c7a7103ecc0fdbc3d55eb47512ee47cef Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 15 Sep 2016 13:24:58 +0200 Subject: [PATCH] Selection tool fix to enable selecting overlapping items Fixes: lp:1499022 * https://bugs.launchpad.net/kicad/+bug/1499022 --- pcbnew/tools/selection_tool.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 97c32a5bae..c8f2033013 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -1142,8 +1142,9 @@ double calcRatio( double a, double b ) { if( a == 0.0 && b == 0.0 ) return 1.0; + if( b == 0.0 ) - return 10000000.0; // something arbitrarily big for the moment + return std::numeric_limits::max(); return a / b; } @@ -1317,6 +1318,7 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c double maxLength = 0.0; double minLength = std::numeric_limits::max(); double maxArea = 0.0; + const TRACK* maxTrack = nullptr; for( int i = 0; i < aCollector.GetCount(); ++i ) { @@ -1325,10 +1327,15 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c maxLength = std::max( track->GetLength(), maxLength ); maxLength = std::max( (double) track->GetWidth(), maxLength ); - minLength = std::min( std::max( track->GetLength(), (double)track->GetWidth() ), minLength ); + minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength ); - double area = ( track->GetLength() + track->GetWidth() * track->GetWidth() ); - maxArea = std::max(area, maxArea); + double area = track->GetLength() * track->GetWidth(); + + if( area > maxArea ) + { + maxArea = area; + maxTrack = track; + } } } @@ -1350,9 +1357,9 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c { if( MODULE* mod = dyn_cast( aCollector[j] ) ) { - double ratio = maxArea / mod->GetFootprintRect().GetArea(); + double ratio = calcRatio( maxArea, mod->GetFootprintRect().GetArea() ); - if( ratio < modulePadMinCoverRatio ) + if( ratio < modulePadMinCoverRatio && calcCommonArea( maxTrack, mod ) < commonAreaRatio ) rejected.insert( mod ); } }