Eeschema: improve merging of overlapping SCH_LINEs.

* Use std::min and std::max to determine the overlapping line end points.
This commit is contained in:
Simon Richter 2016-06-27 19:54:46 -04:00 committed by Wayne Stambaugh
parent 4bf72be9e4
commit 10c8dae794
1 changed files with 12 additions and 21 deletions

View File

@ -269,17 +269,6 @@ void SCH_LINE::Rotate( wxPoint aPosition )
}
/*
* helper sort function, used by MergeOverlap
* sorts ref and test by x values, or (for same x values) by y values
*/
bool sort_by_ends_position(const wxPoint * ref, const wxPoint * tst )
{
if( ref->x == tst->x )
return ref->y < tst->y;
return ref->x < tst->x;
}
/*
* MergeOverlap try to merge 2 lines that are colinear.
* this function expects these 2 lines have at least a common end
@ -346,16 +335,18 @@ bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
// for horizontal segments the uppermost and the lowest point
if( colinear )
{
std::vector <wxPoint*> candidates;
candidates.reserve( 4 );
candidates.push_back( &m_start );
candidates.push_back( &m_end );
candidates.push_back( &aLine->m_start );
candidates.push_back( &aLine->m_end );
sort( candidates.begin(), candidates.end(), sort_by_ends_position );
wxPoint tmp = *candidates[3];
m_start = *candidates[0];
m_end = tmp;
auto less = []( const wxPoint& lhs, const wxPoint& rhs ) -> bool
{
if( lhs.x == rhs.x )
return lhs.y < rhs.y;
return lhs.x < rhs.x;
};
wxPoint top_left = std::min( { m_start, m_end, aLine->m_start, aLine->m_end }, less );
wxPoint bottom_right = std::max( { m_start, m_end, aLine->m_start, aLine->m_end }, less );
m_start = top_left;
m_end = bottom_right;
return true;
}
return false;