diff --git a/pcbnew/router/pns_dp_meander_placer.cpp b/pcbnew/router/pns_dp_meander_placer.cpp index c02c5cc157..0e77b7b715 100644 --- a/pcbnew/router/pns_dp_meander_placer.cpp +++ b/pcbnew/router/pns_dp_meander_placer.cpp @@ -98,7 +98,8 @@ bool PNS_DP_MEANDER_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) return false; } - m_originPair.SetGap( Router()->Sizes().DiffPairGap() ); + if( m_originPair.Gap() < 0 ) + m_originPair.SetGap( Router()->Sizes().DiffPairGap() ); if( !m_originPair.PLine().SegmentCount() || !m_originPair.NLine().SegmentCount() ) diff --git a/pcbnew/router/pns_meander_skew_placer.cpp b/pcbnew/router/pns_meander_skew_placer.cpp index f962b84f33..98697fe34d 100644 --- a/pcbnew/router/pns_meander_skew_placer.cpp +++ b/pcbnew/router/pns_meander_skew_placer.cpp @@ -78,7 +78,8 @@ bool PNS_MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) return false; } - m_originPair.SetGap ( Router()->Sizes().DiffPairGap() ); + if( m_originPair.Gap() < 0 ) + m_originPair.SetGap ( Router()->Sizes().DiffPairGap() ); if( !m_originPair.PLine().SegmentCount() || !m_originPair.NLine().SegmentCount() ) diff --git a/pcbnew/router/pns_topology.cpp b/pcbnew/router/pns_topology.cpp index f59a0fdb15..d99b9a3a09 100644 --- a/pcbnew/router/pns_topology.cpp +++ b/pcbnew/router/pns_topology.cpp @@ -344,8 +344,9 @@ bool PNS_TOPOLOGY::AssembleDiffPair( PNS_ITEM* aStart, PNS_DIFF_PAIR& aPair ) if( s->Layers().Start() == refSeg->Layers().Start() && s->Width() == refSeg->Width() ) { int dist = s->Seg().Distance( refSeg->Seg() ); + bool isParallel = refSeg->Seg().ApproxParallel( s->Seg() ); - if( dist < minDist ) + if( dist < minDist || ( dist == minDist && isParallel ) ) { minDist = dist; coupledSeg = s; @@ -367,9 +368,20 @@ bool PNS_TOPOLOGY::AssembleDiffPair( PNS_ITEM* aStart, PNS_DIFF_PAIR& aPair ) std::swap( lp, ln ); } + int gap = -1 ; + if( refSeg->Seg().ApproxParallel( coupledSeg->Seg() ) ) { + + // Segments are parallel -> compute pair gap + const VECTOR2I refDir = refSeg->Anchor(1) - refSeg->Anchor(0); + const VECTOR2I displacement = refSeg->Anchor(1) - coupledSeg->Anchor(1); + gap = (int) abs( refDir.Cross( displacement ) / refDir.EuclideanNorm() ) - lp->Width(); + + } + aPair = PNS_DIFF_PAIR( *lp, *ln ); aPair.SetWidth( lp->Width() ); aPair.SetLayers( lp->Layers() ); + aPair.SetGap( gap ); return true; }