From 73fb85a352c1d63b5e1932eb6425d420a4db6581 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 12 Apr 2021 20:34:44 -0400 Subject: [PATCH] PNS: Calculate diff pair primitive orientation using anchors only The previous method fails if the primitive is an expanding or contracting pair (diagonals going inward or outward) resulting in incorrect orientation, which then leads to incorrect candidate gateways being generated and no solution found. Fixes https://gitlab.com/kicad/code/kicad/-/issues/8185 --- pcbnew/router/pns_diff_pair.cpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/pcbnew/router/pns_diff_pair.cpp b/pcbnew/router/pns_diff_pair.cpp index 6520506adb..140e3c6e4b 100644 --- a/pcbnew/router/pns_diff_pair.cpp +++ b/pcbnew/router/pns_diff_pair.cpp @@ -114,43 +114,32 @@ DIRECTION_45 DP_PRIMITIVE_PAIR::anchorDirection( const ITEM* aItem, const VECTOR return DIRECTION_45( aItem->Anchor( 1 ) - aItem->Anchor( 0 ) ); } -void DP_PRIMITIVE_PAIR::CursorOrientation( const VECTOR2I& aCursorPos, VECTOR2I& aMidpoint, VECTOR2I& aDirection ) const +void DP_PRIMITIVE_PAIR::CursorOrientation( const VECTOR2I& aCursorPos, VECTOR2I& aMidpoint, + VECTOR2I& aDirection ) const { assert( m_primP && m_primN ); VECTOR2I aP, aN, dir, midpoint; - if ( m_primP->OfKind( ITEM::SEGMENT_T ) && m_primN->OfKind( ITEM::SEGMENT_T ) ) + if( m_primP->OfKind( ITEM::SEGMENT_T ) && m_primN->OfKind( ITEM::SEGMENT_T ) ) { - aP = m_primP->Anchor( 1 ); - aN = m_primN->Anchor( 1 ); + aP = m_primP->Anchor( 1 ); + aN = m_primN->Anchor( 1 ); midpoint = ( aP + aN ) / 2; - SEG s = static_cast ( m_primP )->Seg(); - - if ( s.B != s.A ) - { - dir = s.B - s.A; - } - else - { - dir = VECTOR2I( 0, 1 ); - } - - dir = dir.Resize( ( aP - aN ).EuclideanNorm() ); - + dir = ( aP - aN ).Perpendicular(); } else { - aP = m_primP->Anchor( 0 ); - aN = m_primN->Anchor( 0 ); + aP = m_primP->Anchor( 0 ); + aN = m_primN->Anchor( 0 ); midpoint = ( aP + aN ) / 2; - dir = ( aP - aN ).Perpendicular(); + dir = ( aP - aN ).Perpendicular(); - if ( dir.Dot( aCursorPos - midpoint ) < 0 ) + if( dir.Dot( aCursorPos - midpoint ) < 0 ) dir = -dir; } - aMidpoint = midpoint; + aMidpoint = midpoint; aDirection = dir; }