diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 651224eafc..72c5b74e57 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1583,12 +1583,12 @@ D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, i int idxmax = aPadList.size()-1; int delta = aPadList.size(); - if( delta & 1 && delta > 1 ) - delta += 1; - delta /= 2; - int idx = delta; // Starting index is the middle of list + + int idx = 0; // Starting index is the beginning of list while( delta ) { + // Calculate half size of remaining interval to test. + // Ensure the computed value is not truncated (too small) if( (delta & 1) && ( delta > 1 ) ) delta++; delta /= 2; diff --git a/pcbnew/connect.cpp b/pcbnew/connect.cpp index 5d44c7b19e..2439bd5d58 100644 --- a/pcbnew/connect.cpp +++ b/pcbnew/connect.cpp @@ -342,12 +342,12 @@ void CONNECTIONS::CollectItemsNearTo( std::vector& aList, int idxmax = m_candidates.size()-1; int delta = m_candidates.size(); - if( delta & 1 && delta > 1 ) - delta += 1; - delta /= 2; - int idx = delta; // Starting index is the middle of list + + int idx = 0; // Starting index is the beginning of list while( delta ) { + // Calculate half size of remaining interval to test. + // Ensure the computed value is not truncated (too small) if( (delta & 1) && ( delta > 1 ) ) delta++; delta /= 2; @@ -530,12 +530,12 @@ int CONNECTIONS::searchEntryPointInCandidatesList( const wxPoint & aPoint) int idxmax = m_candidates.size()-1; int delta = m_candidates.size(); - if( delta & 1 && delta > 1 ) - delta += 1; - delta /= 2; - int idx = delta; // Starting index is the middle of list + + int idx = 0; // Starting index is the beginning of list while( delta ) { + // Calculate half size of remaining interval to test. + // Ensure the computed value is not truncated (too small) if( (delta & 1) && ( delta > 1 ) ) delta++; delta /= 2;