Skip to content

Commit

Permalink
PNS: Fix IsLineCorner logic
Browse files Browse the repository at this point in the history
Handle segment width test in the case of locked segs
Fix logic failure where vias on path cause crash

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11990


(cherry picked from commit 2512375)
  • Loading branch information
craftyjon committed Jul 12, 2022
1 parent 57acce9 commit 664bf13
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions pcbnew/router/pns_joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ class JOINT : public ITEM
*/
bool IsLineCorner( bool aAllowLockedSegs = false ) const
{
if( m_linkedItems.Size() != 2 || m_linkedItems.Count( SEGMENT_T | ARC_T ) != 2 )
if( m_linkedItems.Size() == 2 && m_linkedItems.Count( SEGMENT_T | ARC_T ) == 2 )
{
LINKED_ITEM* seg1 = static_cast<LINKED_ITEM*>( m_linkedItems[0] );
LINKED_ITEM* seg2 = static_cast<LINKED_ITEM*>( m_linkedItems[1] );

// joints between segments of different widths are not considered trivial.
return seg1->Width() == seg2->Width();
}
else if( m_linkedItems.Size() > 2 && m_linkedItems.Count( SEGMENT_T | ARC_T ) == 2 )
{
if( !aAllowLockedSegs )
{
Expand All @@ -113,8 +121,10 @@ class JOINT : public ITEM
else if( ( m_linkedItems.Size() - m_linkedItems.Count( SEGMENT_T | ARC_T ) )
== m_linkedItems.Count( VIA_T ) )
{
const VIA* via = nullptr;
bool hasNonVirtualVia = false;
const LINKED_ITEM* seg1 = nullptr;
const LINKED_ITEM* seg2 = nullptr;
const VIA* via = nullptr;
bool hasNonVirtualVia = false;

for( const ITEM* item : m_linkedItems.CItems() )
{
Expand All @@ -123,28 +133,26 @@ class JOINT : public ITEM
via = static_cast<const VIA*>( item );

hasNonVirtualVia = !via->IsVirtual();

if( hasNonVirtualVia )
break;
}
else if( item->Kind() == SEGMENT_T || item->Kind() == ARC_T )
{
if( !seg1 )
seg1 = static_cast<const LINKED_ITEM*>( item );
else
seg2 = static_cast<const LINKED_ITEM*>( item );
}
}

assert( via );

if( !via || hasNonVirtualVia )
return false;
}
else
{
return false;

assert ( seg1 && seg2 );

return seg1->Width() == seg2->Width();
}
}

auto seg1 = static_cast<LINKED_ITEM*>( m_linkedItems[0] );
auto seg2 = static_cast<LINKED_ITEM*>( m_linkedItems[1] );

// joints between segments of different widths are not considered trivial.
return seg1->Width() == seg2->Width();
return false;
}

bool IsNonFanoutVia() const
Expand Down

0 comments on commit 664bf13

Please sign in to comment.