Eeschema: Add two utility functions to sch_line

Add IsSameQuandrant and IsParallel functions
This commit is contained in:
Seth Hillbrand 2017-10-16 14:38:57 -07:00 committed by Wayne Stambaugh
parent d0b2f078fe
commit 0fd2405c00
2 changed files with 48 additions and 0 deletions

View File

@ -352,6 +352,42 @@ void SCH_LINE::Rotate( wxPoint aPosition )
}
bool SCH_LINE::IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition )
{
wxPoint first;
wxPoint second;
if( m_start == aPosition )
first = m_end - aPosition;
else if( m_end == aPosition )
first = m_start - aPosition;
else
return false;
if( aLine->m_start == aPosition )
second = aLine->m_end - aPosition;
else if( aLine->m_end == aPosition )
second = aLine->m_start - aPosition;
else
return false;
return (std::signbit( first.x ) == std::signbit( second.x ) &&
std::signbit( first.y ) == std::signbit( second.y ) );
}
bool SCH_LINE::IsParallel( SCH_LINE* aLine )
{
wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false,
wxT( "Cannot test line segment for overlap." ) );
wxPoint firstSeg = m_end - m_start;
wxPoint secondSeg = aLine->m_end - aLine->m_start;
// Use long long here to avoid overflow in calculations
return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
}
bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
{
auto less = []( const wxPoint& lhs, const wxPoint& rhs ) -> bool

View File

@ -142,6 +142,18 @@ public:
*/
bool MergeOverlap( SCH_LINE* aLine );
/**
* Check if two lines are in the same quadrant as each other, using a reference point as
* the origin
*
* @param aLine - Line to compare
* @param aPosition - Point to reference against lines
* @return true if lines are mostly in different quadrants of aPosition, false otherwise
*/
bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
bool IsParallel( SCH_LINE* aLine );
void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) override;