2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_joint.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_router.h"
|
2015-07-02 14:10:49 +00:00
|
|
|
#include "pns_utils.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
#include "pns_diff_pair.h"
|
|
|
|
#include "pns_topology.h"
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool PNS_TOPOLOGY::SimplifyLine( PNS_LINE* aLine )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !aLine->LinkedSegments() || !aLine->SegmentCount() )
|
|
|
|
return false;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_SEGMENT* root = ( *aLine->LinkedSegments() )[0];
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE l = m_world->AssembleLine( root );
|
|
|
|
SHAPE_LINE_CHAIN simplified( l.CLine() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
simplified.Simplify();
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( simplified.PointCount() != l.PointCount() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE lnew( l );
|
|
|
|
m_world->Remove( &l );
|
|
|
|
lnew.SetShape( simplified );
|
|
|
|
m_world->Add( &lnew );
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
const PNS_TOPOLOGY::JOINT_SET PNS_TOPOLOGY::ConnectedJoints( PNS_JOINT* aStart )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
std::deque<PNS_JOINT*> searchQueue;
|
|
|
|
JOINT_SET processed;
|
|
|
|
|
|
|
|
searchQueue.push_back( aStart );
|
|
|
|
processed.insert( aStart );
|
|
|
|
|
|
|
|
while( !searchQueue.empty() )
|
|
|
|
{
|
|
|
|
PNS_JOINT* current = searchQueue.front();
|
|
|
|
searchQueue.pop_front();
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : current->LinkList() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( item->OfKind( PNS_ITEM::SEGMENT ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( item );
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_JOINT* a = m_world->FindJoint( seg->Seg().A, seg );
|
|
|
|
PNS_JOINT* b = m_world->FindJoint( seg->Seg().B, seg );
|
|
|
|
PNS_JOINT* next = ( *a == *current ) ? b : a;
|
|
|
|
|
|
|
|
if( processed.find( next ) == processed.end() )
|
|
|
|
{
|
|
|
|
processed.insert( next );
|
|
|
|
searchQueue.push_back( next );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return processed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool PNS_TOPOLOGY::LeadingRatLine( const PNS_LINE* aTrack, SHAPE_LINE_CHAIN& aRatLine )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_LINE track( *aTrack );
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I end;
|
|
|
|
|
|
|
|
if( !track.PointCount() )
|
|
|
|
return false;
|
|
|
|
|
2016-06-07 15:33:12 +00:00
|
|
|
std::unique_ptr<PNS_NODE> tmpNode( m_world->Branch() );
|
2015-02-18 00:29:54 +00:00
|
|
|
tmpNode->Add( &track );
|
|
|
|
|
|
|
|
PNS_JOINT* jt = tmpNode->FindJoint( track.CPoint( -1 ), &track );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !jt )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( ( !track.EndsWithVia() && jt->LinkCount() >= 2 ) || ( track.EndsWithVia() && jt->LinkCount() >= 3 ) ) // we got something connected
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
end = jt->Pos();
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
int anchor;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
PNS_TOPOLOGY topo( tmpNode.get() );
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEM* it = topo.NearestUnconnectedItem( jt, &anchor );
|
|
|
|
|
|
|
|
if( !it )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
end = it->Anchor( anchor );
|
|
|
|
}
|
|
|
|
|
|
|
|
aRatLine.Clear();
|
2015-02-18 16:53:46 +00:00
|
|
|
aRatLine.Append( track.CPoint( -1 ) );
|
|
|
|
aRatLine.Append( end );
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEM* PNS_TOPOLOGY::NearestUnconnectedItem( PNS_JOINT* aStart, int* aAnchor, int aKindMask )
|
|
|
|
{
|
|
|
|
std::set<PNS_ITEM*> disconnected;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_world->AllItemsInNet( aStart->Net(), disconnected );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( const PNS_JOINT* jt : ConnectedJoints( aStart ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* link : jt->LinkList() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( disconnected.find( link ) != disconnected.end() )
|
|
|
|
disconnected.erase( link );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int best_dist = INT_MAX;
|
|
|
|
PNS_ITEM* best = NULL;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : disconnected )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( item->OfKind( aKindMask ) )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
for(int i = 0; i < item->AnchorCount(); i++)
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I p = item->Anchor( i );
|
|
|
|
int d = ( p - aStart->Pos() ).EuclideanNorm();
|
|
|
|
|
|
|
|
if( d < best_dist )
|
|
|
|
{
|
|
|
|
best_dist = d;
|
|
|
|
best = item;
|
|
|
|
|
|
|
|
if( aAnchor )
|
|
|
|
*aAnchor = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool PNS_TOPOLOGY::followTrivialPath( PNS_LINE* aLine, bool aLeft, PNS_ITEMSET& aSet, std::set<PNS_ITEM*>& aVisited )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I anchor = aLeft ? aLine->CPoint( 0 ) : aLine->CPoint( -1 );
|
|
|
|
PNS_SEGMENT* last = aLeft ? aLine->LinkedSegments()->front() : aLine->LinkedSegments()->back();
|
|
|
|
PNS_JOINT* jt = m_world->FindJoint( anchor, aLine );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
assert( jt != NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
aVisited.insert( last );
|
|
|
|
|
2015-11-05 09:20:08 +00:00
|
|
|
if( jt->IsNonFanoutVia() || jt->IsTraceWidthChange() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_ITEM* via = NULL;
|
|
|
|
PNS_SEGMENT* next_seg = NULL;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* link : jt->Links().Items() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( link->OfKind( PNS_ITEM::VIA ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
via = link;
|
2015-02-18 16:53:46 +00:00
|
|
|
else if( aVisited.find( link ) == aVisited.end() )
|
|
|
|
next_seg = static_cast<PNS_SEGMENT*>( link );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( !next_seg )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE l = m_world->AssembleLine( next_seg );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
VECTOR2I nextAnchor = ( aLeft ? l.CLine().CPoint( -1 ) : l.CLine().CPoint( 0 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( nextAnchor != anchor )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
l.Reverse();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aLeft )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-11-05 09:20:08 +00:00
|
|
|
if( via )
|
|
|
|
aSet.Prepend( via );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aSet.Prepend( l );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 09:20:08 +00:00
|
|
|
if( via )
|
|
|
|
aSet.Add( via );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aSet.Add( l );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
return followTrivialPath( &l, aLeft, aSet, aVisited );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
const PNS_ITEMSET PNS_TOPOLOGY::AssembleTrivialPath( PNS_SEGMENT* aStart )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
PNS_ITEMSET path;
|
2015-02-18 16:53:46 +00:00
|
|
|
std::set<PNS_ITEM*> visited;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE l = m_world->AssembleLine( aStart );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
path.Add( l );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
followTrivialPath( &l, false, path, visited );
|
|
|
|
followTrivialPath( &l, true, path, visited );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
const PNS_ITEMSET PNS_TOPOLOGY::ConnectedItems( PNS_JOINT* aStart, int aKindMask )
|
|
|
|
{
|
|
|
|
return PNS_ITEMSET();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
const PNS_ITEMSET PNS_TOPOLOGY::ConnectedItems( PNS_ITEM* aStart, int aKindMask )
|
|
|
|
{
|
|
|
|
return PNS_ITEMSET();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
int PNS_TOPOLOGY::MatchDpSuffix( wxString aNetName, wxString& aComplementNet, wxString& aBaseDpName )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int rv = 0;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( aNetName.EndsWith( "+" ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aComplementNet = "-";
|
|
|
|
rv = 1;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( aNetName.EndsWith( "_P" ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aComplementNet = "_N";
|
|
|
|
rv = 1;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( aNetName.EndsWith( "-" ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aComplementNet = "+";
|
|
|
|
rv = -1;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( aNetName.EndsWith( "_N" ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aComplementNet = "_P";
|
|
|
|
rv = -1;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( rv != 0 )
|
|
|
|
{
|
|
|
|
aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
|
2015-02-18 00:29:54 +00:00
|
|
|
aComplementNet = aBaseDpName + aComplementNet;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PNS_TOPOLOGY::DpCoupledNet( int aNet )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
BOARD* brd = PNS_ROUTER::GetInstance()->GetBoard();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
wxString refName = brd->FindNet( aNet )->GetNetname();
|
2015-02-18 00:29:54 +00:00
|
|
|
wxString dummy, coupledNetName;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( MatchDpSuffix( refName, coupledNetName, dummy ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
NETINFO_ITEM* net = brd->FindNet( coupledNetName );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !net )
|
2015-02-18 00:29:54 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return net->GetNet();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PNS_TOPOLOGY::DpNetPolarity( int aNet )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
BOARD* brd = PNS_ROUTER::GetInstance()->GetBoard();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
wxString refName = brd->FindNet( aNet )->GetNetname();
|
2015-02-18 00:29:54 +00:00
|
|
|
wxString dummy1, dummy2;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
return MatchDpSuffix( refName, dummy1, dummy2 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2015-07-02 14:10:49 +00:00
|
|
|
bool commonParallelProjection( SEG n, SEG p, SEG &pClip, SEG& nClip );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool PNS_TOPOLOGY::AssembleDiffPair( PNS_ITEM* aStart, PNS_DIFF_PAIR& aPair )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int refNet = aStart->Net();
|
2015-02-18 16:53:46 +00:00
|
|
|
int coupledNet = DpCoupledNet( refNet );
|
|
|
|
|
|
|
|
if( coupledNet < 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
std::set<PNS_ITEM*> coupledItems;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_world->AllItemsInNet( coupledNet, coupledItems );
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
PNS_SEGMENT* coupledSeg = NULL, *refSeg;
|
2015-02-18 00:29:54 +00:00
|
|
|
int minDist = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
if( ( refSeg = dyn_cast<PNS_SEGMENT*>( aStart ) ) != NULL )
|
|
|
|
{
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : coupledItems )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( PNS_SEGMENT* s = dyn_cast<PNS_SEGMENT*>( item ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( s->Layers().Start() == refSeg->Layers().Start() && s->Width() == refSeg->Width() )
|
|
|
|
{
|
|
|
|
int dist = s->Seg().Distance( refSeg->Seg() );
|
2015-07-02 14:10:02 +00:00
|
|
|
bool isParallel = refSeg->Seg().ApproxParallel( s->Seg() );
|
2015-07-02 14:10:49 +00:00
|
|
|
SEG p_clip, n_clip;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-07-02 14:10:49 +00:00
|
|
|
bool isCoupled = commonParallelProjection( refSeg->Seg(), s->Seg(), p_clip, n_clip );
|
|
|
|
|
|
|
|
if( isParallel && isCoupled && dist < minDist )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
minDist = dist;
|
|
|
|
coupledSeg = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !coupledSeg )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE lp = m_world->AssembleLine( refSeg );
|
|
|
|
PNS_LINE ln = m_world->AssembleLine( coupledSeg );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( DpNetPolarity( refNet ) < 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
std::swap( lp, ln );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int gap = -1;
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
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 );
|
2015-08-03 19:11:51 +00:00
|
|
|
gap = (int) std::abs( refDir.Cross( displacement ) / refDir.EuclideanNorm() ) - lp.Width();
|
2015-07-02 14:10:02 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
aPair = PNS_DIFF_PAIR( lp, ln );
|
|
|
|
aPair.SetWidth( lp.Width() );
|
|
|
|
aPair.SetLayers( lp.Layers() );
|
2015-07-02 14:10:02 +00:00
|
|
|
aPair.SetGap( gap );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-19 16:07:16 +00:00
|
|
|
|
|
|
|
const std::set<PNS_ITEM*> PNS_TOPOLOGY::AssembleCluster( PNS_ITEM* aStart, int aLayer )
|
|
|
|
{
|
|
|
|
std::set<PNS_ITEM*> visited;
|
|
|
|
std::deque<PNS_ITEM*> pending;
|
|
|
|
|
|
|
|
pending.push_back( aStart );
|
|
|
|
|
|
|
|
while( !pending.empty() )
|
|
|
|
{
|
|
|
|
PNS_NODE::OBSTACLES obstacles;
|
|
|
|
PNS_ITEM* top = pending.front();
|
|
|
|
|
|
|
|
pending.pop_front();
|
|
|
|
|
|
|
|
visited.insert( top );
|
|
|
|
|
|
|
|
m_world->QueryColliding( top, obstacles, PNS_ITEM::ANY, -1, false, 0 );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_OBSTACLE& obs : obstacles )
|
2015-08-19 16:07:16 +00:00
|
|
|
{
|
|
|
|
if( visited.find( obs.m_item ) == visited.end() && obs.m_item->Layers().Overlaps( aLayer ) && !( obs.m_item->Marker() & MK_HEAD ) )
|
|
|
|
{
|
|
|
|
visited.insert( obs.m_item );
|
|
|
|
pending.push_back( obs.m_item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return visited;
|
|
|
|
}
|