fix eager dynamic allocation in PNS::NODE::addLine

move implementation into PNS::NODE::Add since lines will never be part of the index itself
This commit is contained in:
decimad 2016-08-30 20:55:00 +02:00 committed by Maciej Suminski
parent 96a3145543
commit 94fae5d6a1
2 changed files with 31 additions and 36 deletions

View File

@ -1,3 +1,4 @@
#include "pns_node.h"
/* /*
* KiRouter - a push-and-(sometimes-)shove PCB router * KiRouter - a push-and-(sometimes-)shove PCB router
* *
@ -553,8 +554,10 @@ void NODE::Add( std::unique_ptr< VIA > aVia )
addVia( aVia.release() ); addVia( aVia.release() );
} }
void NODE::addLine( LINE& aLine, bool aAllowRedundant ) void NODE::Add( LINE& aLine, bool aAllowRedundant )
{ {
assert( !aLine.IsLinked() );
SHAPE_LINE_CHAIN& l = aLine.Line(); SHAPE_LINE_CHAIN& l = aLine.Line();
for( int i = 0; i < l.SegmentCount(); i++ ) for( int i = 0; i < l.SegmentCount(); i++ )
@ -563,36 +566,22 @@ void NODE::addLine( LINE& aLine, bool aAllowRedundant )
if( s.A != s.B ) if( s.A != s.B )
{ {
SEGMENT* pseg = new SEGMENT( aLine, s ); SEGMENT* rseg;
SEGMENT* psegR = NULL; if( !aAllowRedundant &&
(rseg = findRedundantSegment( s.A, s.B, aLine.Layers(), aLine.Net() )) )
if( !aAllowRedundant )
psegR = findRedundantSegment( pseg );
if( psegR )
{ {
aLine.LinkSegment( psegR ); // another line could be referencing this segment too :(
aLine.LinkSegment( rseg );
delete pseg;
} }
else else
{ {
pseg->SetOwner( this ); std::unique_ptr< SEGMENT > newseg( new SEGMENT( aLine, s ) );
aLine.LinkSegment( newseg.get() );
linkJoint( s.A, pseg->Layers(), aLine.Net(), pseg ); Add( std::move( newseg ), true );
linkJoint( s.B, pseg->Layers(), aLine.Net(), pseg );
aLine.LinkSegment( pseg );
m_index->Add( pseg );
} }
} }
} }
}
void NODE::Add( LINE& aLine, bool aAllowRedundant )
{
addLine( aLine, aAllowRedundant );
} }
void NODE::addSegment( SEGMENT* aSeg ) void NODE::addSegment( SEGMENT* aSeg )
@ -682,6 +671,9 @@ void NODE::removeLine( LINE* aLine )
{ {
removeSegment( seg ); removeSegment( seg );
} }
aLine->ClearSegmentLinks();
aLine->SetOwner( nullptr );
} }
void NODE::removeVia( VIA* aVia ) void NODE::removeVia( VIA* aVia )
@ -1283,33 +1275,35 @@ int NODE::RemoveByMarker( int aMarker )
return 0; return 0;
} }
SEGMENT* NODE::findRedundantSegment( const VECTOR2I& A, const VECTOR2I& B, const LAYER_RANGE& lr,
SEGMENT* NODE::findRedundantSegment( SEGMENT* aSeg ) int aNet )
{ {
JOINT* jtStart = FindJoint( aSeg->Seg().A, aSeg ); JOINT* jtStart = FindJoint( A, lr.Start(), aNet );
if( !jtStart ) if( !jtStart )
return NULL; return nullptr;
for( ITEM* item : jtStart->LinkList() ) for( ITEM* item : jtStart->LinkList() )
{ {
if( item->OfKind( ITEM::SEGMENT_T ) ) if( item->OfKind( ITEM::SEGMENT_T ) )
{ {
SEGMENT* seg2 = (SEGMENT*) item; SEGMENT* seg2 = (SEGMENT*)item;
const VECTOR2I a1( aSeg->Seg().A );
const VECTOR2I b1( aSeg->Seg().B );
const VECTOR2I a2( seg2->Seg().A ); const VECTOR2I a2( seg2->Seg().A );
const VECTOR2I b2( seg2->Seg().B ); const VECTOR2I b2( seg2->Seg().B );
if( seg2->Layers().Start() == aSeg->Layers().Start() && if( seg2->Layers().Start() == lr.Start() &&
( ( a1 == a2 && b1 == b2 ) || ( a1 == b2 && a2 == b1 ) ) ) ((A == a2 && B == b2) || (A == b2 && B == a2)) )
return seg2; return seg2;
} }
} }
return NULL; return nullptr;
}
SEGMENT* NODE::findRedundantSegment( SEGMENT* aSeg )
{
return findRedundantSegment( aSeg->Seg().A, aSeg->Seg().B, aSeg->Layers(), aSeg->Net() );
} }

View File

@ -439,7 +439,6 @@ private:
///> helpers for adding/removing items ///> helpers for adding/removing items
void addSolid( SOLID* aSeg ); void addSolid( SOLID* aSeg );
void addSegment( SEGMENT* aSeg ); void addSegment( SEGMENT* aSeg );
void addLine( LINE& aLine, bool aAllowRedundant );
void addVia( VIA* aVia ); void addVia( VIA* aVia );
void removeSolid( SOLID* aSeg ); void removeSolid( SOLID* aSeg );
void removeLine( LINE* aLine ); void removeLine( LINE* aLine );
@ -456,6 +455,8 @@ private:
return m_parent == NULL; return m_parent == NULL;
} }
SEGMENT* findRedundantSegment( const VECTOR2I& A, const VECTOR2I& B,
const LAYER_RANGE & lr, int aNet );
SEGMENT* findRedundantSegment( SEGMENT* aSeg ); SEGMENT* findRedundantSegment( SEGMENT* aSeg );
///> scans the joint map, forming a line starting from segment (current). ///> scans the joint map, forming a line starting from segment (current).