diff --git a/pcbnew/drc/drc_creepage_utils.cpp b/pcbnew/drc/drc_creepage_utils.cpp index 879f988f73..ce45a3d772 100644 --- a/pcbnew/drc/drc_creepage_utils.cpp +++ b/pcbnew/drc/drc_creepage_utils.cpp @@ -701,16 +701,19 @@ std::vector GraphConnection::GetShapes() return shapes; } -void CREEP_SHAPE::ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const +void CREEP_SHAPE::ConnectChildren( std::shared_ptr a1, std::shared_ptr, + CreepageGraph& aG ) const { } -void BE_SHAPE_POINT::ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const +void BE_SHAPE_POINT::ConnectChildren( std::shared_ptr a1, std::shared_ptr, + CreepageGraph& aG ) const { } -void BE_SHAPE_CIRCLE::ShortenChildDueToGV( GraphNode* a1, GraphNode* a2, CreepageGraph& aG, +void BE_SHAPE_CIRCLE::ShortenChildDueToGV( std::shared_ptr a1, + std::shared_ptr a2, CreepageGraph& aG, double aNormalWeight ) const { EDA_ANGLE angle1 = EDA_ANGLE( a1->m_pos - m_pos ); @@ -737,7 +740,7 @@ void BE_SHAPE_CIRCLE::ShortenChildDueToGV( GraphNode* a1, GraphNode* a2, Creepag skipPoint.y += m_radius * sin( pointAngle.AsRadians() ); - GraphNode* gnt = aG.AddNode( GraphNode::POINT, a1->m_parent, skipPoint ); + std::shared_ptr gnt = aG.AddNode( GraphNode::POINT, a1->m_parent, skipPoint ); path_connection pc; @@ -750,14 +753,15 @@ void BE_SHAPE_CIRCLE::ShortenChildDueToGV( GraphNode* a1, GraphNode* a2, Creepag pc.a2 = maxAngle == angle2 ? a2->m_pos : a1->m_pos; pc.weight = aG.m_minGrooveWidth; - GraphConnection* gc = aG.AddConnection( gnt, maxAngle == angle2 ? a2 : a1, pc ); + std::shared_ptr gc = aG.AddConnection( gnt, maxAngle == angle2 ? a2 : a1, pc ); if( gc ) gc->forceStraightLigne = true; return; } -void BE_SHAPE_CIRCLE::ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const +void BE_SHAPE_CIRCLE::ConnectChildren( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG ) const { if( !a1 || !a2 ) return; @@ -793,7 +797,8 @@ void BE_SHAPE_CIRCLE::ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGra } -void BE_SHAPE_ARC::ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const +void BE_SHAPE_ARC::ConnectChildren( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG ) const { if( !a1 || !a2 ) return; @@ -1761,7 +1766,6 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, int aMinGrooveWidth ) { std::vector intersectionPoints; - std::cout << "Path validation: " << ( (float) aMinGrooveWidth ) / 1e6 << std::endl; bool TestGrooveWidth = aMinGrooveWidth > 0; for( BOARD_ITEM* be : aBe ) @@ -2026,9 +2030,9 @@ std::vector GetPaths( CREEP_SHAPE* aS1, CREEP_SHAPE* aS2, doubl return result; } -double -CreepageGraph::Solve( GraphNode* aFrom, GraphNode* aTo, - std::vector& aResult ) // Change to vector of pointers +double CreepageGraph::Solve( + std::shared_ptr aFrom, std::shared_ptr aTo, + std::vector>& aResult ) // Change to vector of pointers { if( !aFrom || !aTo ) return 0; @@ -2049,14 +2053,14 @@ CreepageGraph::Solve( GraphNode* aFrom, GraphNode* aTo, std::priority_queue, decltype( cmp )> pq( cmp ); // Initialize distances to infinity for all nodes except the starting node - for( GraphNode* node : m_nodes ) + for( std::shared_ptr node : m_nodes ) { if( node != nullptr ) - distances[node] = std::numeric_limits::infinity(); // Set to infinity + distances[node.get()] = std::numeric_limits::infinity(); // Set to infinity } - distances[aFrom] = 0.0; - distances[aTo] = std::numeric_limits::infinity(); - pq.push( aFrom ); + distances[aFrom.get()] = 0.0; + distances[aTo.get()] = std::numeric_limits::infinity(); + pq.push( aFrom.get() ); // Dijkstra's main loop while( !pq.empty() ) @@ -2064,15 +2068,16 @@ CreepageGraph::Solve( GraphNode* aFrom, GraphNode* aTo, GraphNode* current = pq.top(); pq.pop(); - if( current == aTo ) + if( current == aTo.get() ) { break; // Shortest path found } // Traverse neighbors - for( GraphConnection* connection : current->m_connections ) + for( std::shared_ptr connection : current->m_connections ) { - GraphNode* neighbor = connection->n1 == current ? connection->n2 : connection->n1; + GraphNode* neighbor = ( connection->n1 ).get() == current ? ( connection->n2 ).get() + : ( connection->n1 ).get(); if( !neighbor ) continue; @@ -2089,7 +2094,7 @@ CreepageGraph::Solve( GraphNode* aFrom, GraphNode* aTo, } } - double pathWeight = distances[aTo]; + double pathWeight = distances[aTo.get()]; // If aTo is unreachable, return infinity if( pathWeight == std::numeric_limits::infinity() ) @@ -2098,15 +2103,15 @@ CreepageGraph::Solve( GraphNode* aFrom, GraphNode* aTo, } // Trace back the path from aTo to aFrom - GraphNode* step = aTo; + GraphNode* step = aTo.get(); - while( step != aFrom ) + while( step != aFrom.get() ) { GraphNode* prevNode = previous[step]; - for( GraphConnection* connection : step->m_connections ) + for( std::shared_ptr connection : step->m_connections ) { - if( ( connection->n1 == prevNode && connection->n2 == step ) - || ( connection->n1 == step && connection->n2 == prevNode ) ) + if( ( ( connection->n1 ).get() == prevNode && ( connection->n2 ).get() == step ) + || ( ( connection->n1 ).get() == step && ( connection->n2 ).get() == prevNode ) ) { aResult.push_back( connection ); break; @@ -2118,7 +2123,8 @@ CreepageGraph::Solve( GraphNode* aFrom, GraphNode* aTo, return pathWeight; } -void CreepageGraph::Addshape( const SHAPE& aShape, GraphNode* aConnectTo, BOARD_ITEM* aParent ) +void CreepageGraph::Addshape( const SHAPE& aShape, std::shared_ptr aConnectTo, + BOARD_ITEM* aParent ) { CREEP_SHAPE* newshape = nullptr; @@ -2232,7 +2238,7 @@ void CreepageGraph::Addshape( const SHAPE& aShape, GraphNode* aConnectTo, BOARD_ if( !newshape ) return; - GraphNode* gnShape = nullptr; + std::shared_ptr gnShape = nullptr; newshape->SetParent( aParent ); @@ -2248,7 +2254,7 @@ void CreepageGraph::Addshape( const SHAPE& aShape, GraphNode* aConnectTo, BOARD_ { m_shapeCollection.push_back( newshape ); gnShape->m_net = aConnectTo->m_net; - GraphConnection* gc = AddConnection( gnShape, aConnectTo ); + std::shared_ptr gc = AddConnection( gnShape, aConnectTo ); if( gc ) gc->m_path.m_show = false; @@ -2263,11 +2269,11 @@ void CreepageGraph::Addshape( const SHAPE& aShape, GraphNode* aConnectTo, BOARD_ void CreepageGraph::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, bool aGenerateBoardEdges ) { - std::vector nodes1 = m_nodes; - std::vector nodes2 = m_nodes; + std::vector> nodes1 = m_nodes; + std::vector> nodes2 = m_nodes; - for( GraphNode* gn1 : nodes1 ) + for( std::shared_ptr gn1 : nodes1 ) { nodes2.erase( nodes2.begin() ); @@ -2284,7 +2290,7 @@ void CreepageGraph::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, continue; - for( GraphNode* gn2 : nodes2 ) + for( std::shared_ptr gn2 : nodes2 ) { if( !gn2 ) continue; @@ -2319,8 +2325,8 @@ void CreepageGraph::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, { false, true }, m_minGrooveWidth ) ) continue; - GraphNode* connect1; - GraphNode* connect2; + std::shared_ptr connect1; + std::shared_ptr connect2; if( gn1->m_parent->GetType() == CREEP_SHAPE::TYPE::POINT ) { @@ -2328,12 +2334,13 @@ void CreepageGraph::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, } else { - GraphNode* gnt = AddNode( GraphNode::POINT, gn1->m_parent, pc.a1 ); + std::shared_ptr gnt = + AddNode( GraphNode::POINT, gn1->m_parent, pc.a1 ); gnt->m_connectDirectly = false; if( gn1->m_parent->IsConductive() ) { - GraphConnection* gc = AddConnection( gn1, gnt ); + std::shared_ptr gc = AddConnection( gn1, gnt ); if( gc ) gc->m_path.m_show = false; @@ -2347,12 +2354,13 @@ void CreepageGraph::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, } else { - GraphNode* gnt = AddNode( GraphNode::POINT, gn2->m_parent, pc.a2 ); + std::shared_ptr gnt = + AddNode( GraphNode::POINT, gn2->m_parent, pc.a2 ); gnt->m_connectDirectly = false; if( gn2->m_parent->IsConductive() ) { - GraphConnection* gc = AddConnection( gn2, gnt ); + std::shared_ptr gc = AddConnection( gn2, gnt ); if( gc ) gc->m_path.m_show = false; @@ -2368,10 +2376,10 @@ void CreepageGraph::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, void CreepageGraph::Trim( double aWeightLimit ) { - std::vector toRemove; + std::vector> toRemove; // Collect connections to remove - for( auto& gc : m_connections ) + for( std::shared_ptr& gc : m_connections ) { if( gc && ( gc->m_path.weight > aWeightLimit ) ) { @@ -2380,18 +2388,18 @@ void CreepageGraph::Trim( double aWeightLimit ) } // Remove collected connections - for( const auto& gc : toRemove ) + for( const std::shared_ptr& gc : toRemove ) { RemoveConnection( gc ); } } -void CreepageGraph::RemoveConnection( GraphConnection* aGc, bool aDelete ) +void CreepageGraph::RemoveConnection( std::shared_ptr aGc, bool aDelete ) { if( !aGc ) return; - for( GraphNode* gn : { aGc->n1, aGc->n2 } ) + for( std::shared_ptr gn : { aGc->n1, aGc->n2 } ) { if( gn ) { @@ -2401,14 +2409,13 @@ void CreepageGraph::RemoveConnection( GraphConnection* aGc, bool aDelete ) if( nConns.empty() && aDelete ) { auto it = std::find_if( m_nodes.begin(), m_nodes.end(), - [&gn]( const GraphNode* node ) + [&gn]( const std::shared_ptr node ) { - return node == gn; + return node.get() == gn.get(); } ); if( it != m_nodes.end() ) { m_nodes.erase( it ); - delete *it; } } } @@ -2419,38 +2426,40 @@ void CreepageGraph::RemoveConnection( GraphConnection* aGc, bool aDelete ) // Remove the connection from the graph's connections m_connections.erase( std::remove( m_connections.begin(), m_connections.end(), aGc ), m_connections.end() ); - delete aGc; } } -GraphNode* CreepageGraph::AddNode( GraphNode::TYPE aType, CREEP_SHAPE* parent, VECTOR2I pos ) +std::shared_ptr CreepageGraph::AddNode( GraphNode::TYPE aType, CREEP_SHAPE* parent, + VECTOR2I pos ) { - GraphNode* gn = FindNode( aType, parent, pos ); + std::shared_ptr gn = FindNode( aType, parent, pos ); if( gn ) return gn; - gn = new GraphNode( aType, parent, pos ); + gn = std::make_shared( aType, parent, pos ); m_nodes.push_back( gn ); return gn; } -GraphNode* CreepageGraph::AddNodeVirtual() +std::shared_ptr CreepageGraph::AddNodeVirtual() { //Virtual nodes are always unique, do not try to find them - GraphNode* gn = new GraphNode( GraphNode::TYPE::VIRTUAL, nullptr ); + std::shared_ptr gn = + std::make_shared( GraphNode::TYPE::VIRTUAL, nullptr ); m_nodes.push_back( gn ); return gn; } -GraphConnection* CreepageGraph::AddConnection( GraphNode* aN1, GraphNode* aN2, - const path_connection& aPc ) +std::shared_ptr CreepageGraph::AddConnection( std::shared_ptr aN1, + std::shared_ptr aN2, + const path_connection& aPc ) { if( !aN1 || !aN2 ) return nullptr; - GraphConnection* gc = new GraphConnection( aN1, aN2, aPc ); + std::shared_ptr gc = std::make_shared( aN1, aN2, aPc ); m_connections.push_back( gc ); aN1->m_connections.push_back( gc ); aN2->m_connections.push_back( gc ); @@ -2458,7 +2467,8 @@ GraphConnection* CreepageGraph::AddConnection( GraphNode* aN1, GraphNode* aN2, return gc; } -GraphConnection* CreepageGraph::AddConnection( GraphNode* aN1, GraphNode* aN2 ) +std::shared_ptr CreepageGraph::AddConnection( std::shared_ptr aN1, + std::shared_ptr aN2 ) { if( !aN1 || !aN2 ) return nullptr; @@ -2471,9 +2481,10 @@ GraphConnection* CreepageGraph::AddConnection( GraphNode* aN1, GraphNode* aN2 ) return AddConnection( aN1, aN2, pc ); } -GraphNode* CreepageGraph::FindNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent, VECTOR2I aPos ) +std::shared_ptr CreepageGraph::FindNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent, + VECTOR2I aPos ) { - for( GraphNode* gn : m_nodes ) + for( std::shared_ptr gn : m_nodes ) { if( aPos == gn->m_pos && aParent == gn->m_parent && aType == gn->m_type ) { @@ -2484,9 +2495,10 @@ GraphNode* CreepageGraph::FindNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent, } -GraphNode* CreepageGraph::AddNetElements( int aNetCode, PCB_LAYER_ID aLayer, int aMaxCreepage ) +std::shared_ptr CreepageGraph::AddNetElements( int aNetCode, PCB_LAYER_ID aLayer, + int aMaxCreepage ) { - GraphNode* virtualNode = AddNodeVirtual(); + std::shared_ptr virtualNode = AddNodeVirtual(); virtualNode->m_net = aNetCode; for( FOOTPRINT* footprint : m_board.Footprints() ) diff --git a/pcbnew/drc/drc_creepage_utils.h b/pcbnew/drc/drc_creepage_utils.h index 272f3796c9..6def98e497 100644 --- a/pcbnew/drc/drc_creepage_utils.h +++ b/pcbnew/drc/drc_creepage_utils.h @@ -183,7 +183,8 @@ public: const BOARD_ITEM* GetParent() const { return m_parent; }; void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }; - virtual void ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const; + virtual void ConnectChildren( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG ) const; std::vector ReversePaths( const std::vector& aV ) const { @@ -449,7 +450,7 @@ public: CREEP_SHAPE* m_parent = nullptr; - std::vector m_connections = {}; + std::vector> m_connections = {}; VECTOR2I m_pos = VECTOR2I( 0, 0 ); // Virtual nodes are connected with a 0 weight connection to equivalent net ( same net or netclass ) bool m_virtual = false; @@ -466,14 +467,14 @@ public: class GraphConnection { public: - GraphConnection( GraphNode* aN1, GraphNode* aN2, const path_connection& aPc ) : - n1( aN1 ), n2( aN2 ) + GraphConnection( std::shared_ptr aN1, std::shared_ptr aN2, + const path_connection& aPc ) : n1( aN1 ), n2( aN2 ) { m_path = aPc; }; - GraphNode* n1 = nullptr; - GraphNode* n2 = nullptr; + std::shared_ptr n1 = nullptr; + std::shared_ptr n2 = nullptr; path_connection m_path; std::vector GetShapes(); @@ -517,7 +518,8 @@ public: }; - void ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const override; + void ConnectChildren( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG ) const override; }; /** @class BE_SHAPE_CIRCLE @@ -556,9 +558,10 @@ public: int GetRadius() const override { return m_radius; } - void ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const override; - void ShortenChildDueToGV( GraphNode* a1, GraphNode* a2, CreepageGraph& aG, - double aNormalWeight ) const; + void ConnectChildren( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG ) const override; + void ShortenChildDueToGV( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG, double aNormalWeight ) const; protected: @@ -583,7 +586,8 @@ public: m_radius = aRadius; } - void ConnectChildren( GraphNode* a1, GraphNode* a2, CreepageGraph& aG ) const override; + void ConnectChildren( std::shared_ptr a1, std::shared_ptr a2, + CreepageGraph& aG ) const override; std::vector Paths( const BE_SHAPE_POINT& aS2, double aMaxWeight, @@ -661,20 +665,6 @@ public: }; ~CreepageGraph() { - for( GraphConnection* gc : m_connections ) - { - if( gc ) - { - delete gc; - gc = nullptr; - } - } - for( GraphNode* gn : m_nodes ) - if( gn ) - { - delete gn; - gn = nullptr; - } for( CREEP_SHAPE* cs : m_shapeCollection ) if( cs ) { @@ -687,30 +677,36 @@ public: std::vector m_boardEdge; SHAPE_POLY_SET* m_boardOutline; - std::vector m_nodes; - std::vector m_connections; + std::vector> m_nodes; + std::vector> m_connections; void TransformEdgeToCreepShapes(); void TransformCreepShapesToNodes( std::vector& aShapes ); void RemoveDuplicatedShapes(); // Add a node to the graph. If an equivalent node exists, returns the pointer of the existing node instead - GraphNode* AddNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent = nullptr, - VECTOR2I aPos = VECTOR2I() ); - GraphNode* AddNodeVirtual(); - GraphConnection* AddConnection( GraphNode* aN1, GraphNode* aN2, const path_connection& aPc ); - GraphConnection* AddConnection( GraphNode* aN1, GraphNode* aN2 ); - GraphNode* FindNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent, VECTOR2I aPos ); - - void RemoveConnection( GraphConnection*, bool aDelete = false ); + std::shared_ptr AddNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent = nullptr, + VECTOR2I aPos = VECTOR2I() ); + std::shared_ptr AddNodeVirtual(); + std::shared_ptr AddConnection( std::shared_ptr aN1, + std::shared_ptr aN2, + const path_connection& aPc ); + std::shared_ptr AddConnection( std::shared_ptr aN1, + std::shared_ptr aN2 ); + std::shared_ptr FindNode( GraphNode::TYPE aType, CREEP_SHAPE* aParent, + VECTOR2I aPos ); + + void RemoveConnection( std::shared_ptr, bool aDelete = false ); void Trim( double aWeightLimit ); - void Addshape( const SHAPE& aShape, GraphNode* aConnectTo = nullptr, + void Addshape( const SHAPE& aShape, std::shared_ptr aConnectTo = nullptr, BOARD_ITEM* aParent = nullptr ); - double Solve( GraphNode* aFrom, GraphNode* aTo, std::vector& aResult ); + double Solve( std::shared_ptr aFrom, std::shared_ptr aTo, + std::vector>& aResult ); void GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, bool aGenerateBoardEdges = true ); - GraphNode* AddNetElements( int aNetCode, PCB_LAYER_ID aLayer, int aMaxCreepage ); + std::shared_ptr AddNetElements( int aNetCode, PCB_LAYER_ID aLayer, + int aMaxCreepage ); void SetTarget( double aTarget ); double GetTarget() { return m_creepageTarget; }; diff --git a/pcbnew/drc/drc_test_provider_clearance_base.cpp b/pcbnew/drc/drc_test_provider_clearance_base.cpp index b36f4846a7..b372f97b6f 100644 --- a/pcbnew/drc/drc_test_provider_clearance_base.cpp +++ b/pcbnew/drc/drc_test_provider_clearance_base.cpp @@ -106,8 +106,8 @@ void DRC_TEST_PROVIDER_CLEARANCE_BASE::ReportAndShowPathCuToCu( const BOARD_ITEM* aItem1, const BOARD_ITEM* aItem2, PCB_LAYER_ID layer, int aDistance ) { CreepageGraph graph( *m_board ); - GraphNode* NetA = graph.AddNodeVirtual(); - GraphNode* NetB = graph.AddNodeVirtual(); + std::shared_ptr NetA = graph.AddNodeVirtual(); + std::shared_ptr NetB = graph.AddNodeVirtual(); // They need to be different or the algorithm won't compute the path. NetA->m_net = 1; @@ -121,12 +121,12 @@ void DRC_TEST_PROVIDER_CLEARANCE_BASE::ReportAndShowPathCuToCu( double minValue = aDistance * 2; GraphConnection* minGc = nullptr; - for( GraphConnection* gc : graph.m_connections ) + for( std::shared_ptr gc : graph.m_connections ) { if( ( gc->m_path.weight < minValue ) && ( gc->m_path.weight > 0 ) ) { minValue = gc->m_path.weight; - minGc = gc; + minGc = gc.get(); } } diff --git a/pcbnew/drc/drc_test_provider_creepage.cpp b/pcbnew/drc/drc_test_provider_creepage.cpp index 2adf8235b6..836b11bb09 100644 --- a/pcbnew/drc/drc_test_provider_creepage.cpp +++ b/pcbnew/drc/drc_test_provider_creepage.cpp @@ -93,12 +93,13 @@ bool DRC_TEST_PROVIDER_CREEPAGE::Run() } -GraphNode* FindInGraphNodes( GraphNode* aNode, std::vector& aGraph ) +std::shared_ptr FindInGraphNodes( std::shared_ptr aNode, + std::vector>& aGraph ) { if( !aNode ) return nullptr; - for( GraphNode* gn : aGraph ) + for( std::shared_ptr gn : aGraph ) { if( aNode->m_pos == gn->m_pos ) { @@ -138,17 +139,17 @@ int DRC_TEST_PROVIDER_CREEPAGE::testCreepage( CreepageGraph& aGraph, int aNetCod if ( netA->GetBoundingBox().Distance( netB->GetBoundingBox() ) > creepageValue ) return 0; - GraphNode* NetA = aGraph.AddNetElements( aNetCodeA, aLayer, creepageValue ); - GraphNode* NetB = aGraph.AddNetElements( aNetCodeB, aLayer, creepageValue ); + std::shared_ptr NetA = aGraph.AddNetElements( aNetCodeA, aLayer, creepageValue ); + std::shared_ptr NetB = aGraph.AddNetElements( aNetCodeB, aLayer, creepageValue ); aGraph.GeneratePaths( creepageValue, aLayer ); - std::vector nodes1 = aGraph.m_nodes; - std::vector nodes2 = aGraph.m_nodes; + std::vector> nodes1 = aGraph.m_nodes; + std::vector> nodes2 = aGraph.m_nodes; alg::for_all_pairs( aGraph.m_nodes.begin(), aGraph.m_nodes.end(), - [&]( GraphNode* aN1, GraphNode* aN2 ) + [&]( std::shared_ptr aN1, std::shared_ptr aN2 ) { if( aN1 == aN2 ) return; @@ -180,7 +181,7 @@ int DRC_TEST_PROVIDER_CREEPAGE::testCreepage( CreepageGraph& aGraph, int aNetCod aN1->m_parent->ConnectChildren( aN1, aN2, aGraph ); } ); - std::vector shortestPath; + std::vector> shortestPath; shortestPath.clear(); double distance = aGraph.Solve( NetA, NetB, shortestPath ); @@ -211,7 +212,7 @@ int DRC_TEST_PROVIDER_CREEPAGE::testCreepage( CreepageGraph& aGraph, int aNetCod std::vector path; - for( GraphConnection* gc : shortestPath ) + for( std::shared_ptr gc : shortestPath ) { if( !gc ) continue; @@ -378,19 +379,11 @@ int DRC_TEST_PROVIDER_CREEPAGE::testCreepage() { // We need to remove the connection from its endpoints' lists. graph.RemoveConnection( graph.m_connections[i], false ); - delete graph.m_connections[i]; - graph.m_connections[i] = nullptr; } - graph.m_connections.resize( beConnectionsSize ); + graph.m_connections.resize( beConnectionsSize, nullptr ); vectorSize = graph.m_nodes.size(); - - for( size_t i = beNodeSize; i < vectorSize; i++ ) - { - delete graph.m_nodes[i]; - graph.m_nodes[i] = nullptr; - } - graph.m_nodes.resize( beNodeSize ); + graph.m_nodes.resize( beNodeSize, nullptr ); } prevTestChangedGraph = testCreepage( graph, aNet1, aNet2, layer );