diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index 99c84d05eb..95ca62e59b 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -35,7 +35,6 @@ #include #include -#include #include #include #include @@ -75,10 +74,21 @@ bool sortArea( const RN_POLY& aP1, const RN_POLY& aP2 ) } +bool operator==( const RN_NODE_PTR& aFirst, const RN_NODE_PTR& aSecond ) +{ + return aFirst->GetX() == aSecond->GetX() && aFirst->GetY() == aSecond->GetY(); +} + + +bool operator!=( const RN_NODE_PTR& aFirst, const RN_NODE_PTR& aSecond ) +{ + return aFirst->GetX() != aSecond->GetX() || aFirst->GetY() != aSecond->GetY(); +} + + bool isEdgeConnectingNode( const RN_EDGE_PTR& aEdge, const RN_NODE_PTR& aNode ) { - return ( aEdge->getSourceNode().get() == aNode.get() ) || - ( aEdge->getTargetNode().get() == aNode.get() ); + return aEdge->getSourceNode() == aNode || aEdge->getTargetNode() == aNode; } @@ -246,7 +256,7 @@ void RN_NET::compute() return; } - else if( boardNodes.size() == 1 || boardNodes.empty() ) // This case is even simpler + else if( boardNodes.size() <= 1 ) // This case is even simpler { m_rnEdges.reset( new std::vector( 0 ) ); @@ -566,17 +576,18 @@ const RN_NODE_PTR RN_NET::GetClosestNode( const RN_NODE_PTR& aNode, for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it ) { - RN_NODE_PTR baseNode = *it; + RN_NODE_PTR node = *it; // Obviously the distance between node and itself is the shortest, // that's why we have to skip it - if( *it != aNode && aFilter( baseNode ) ) + if( node != aNode && aFilter( node ) ) { - unsigned int distance = getDistance( *it, aNode ); + unsigned int distance = getDistance( node, aNode ); + if( distance < minDistance ) { minDistance = distance; - closest = *it; + closest = node; } } } @@ -706,15 +717,6 @@ void RN_DATA::AddSimple( const BOARD_ITEM* aItem ) } -void RN_NET::ClearSimple() -{ - BOOST_FOREACH( const RN_NODE_PTR& node, m_simpleNodes ) - node->SetFlag( false ); - - m_simpleNodes.clear(); -} - - void RN_NET::processZones() { BOOST_FOREACH( std::deque& edges, m_zoneConnections | boost::adaptors::map_values ) @@ -935,10 +937,3 @@ void RN_DATA::Recalculate( int aNet ) updateNet( aNet ); } } - - -void RN_DATA::ClearSimple() -{ - BOOST_FOREACH( RN_NET& net, m_nets ) - net.ClearSimple(); -} diff --git a/pcbnew/ratsnest_data.h b/pcbnew/ratsnest_data.h index 4340c74e78..d51c070ee8 100644 --- a/pcbnew/ratsnest_data.h +++ b/pcbnew/ratsnest_data.h @@ -37,6 +37,7 @@ #include #include +#include class BOARD; class BOARD_ITEM; @@ -57,6 +58,9 @@ typedef hed::EdgeMST RN_EDGE_MST; typedef boost::shared_ptr RN_EDGE_MST_PTR; typedef hed::Triangulation TRIANGULATOR; +bool operator==( const RN_NODE_PTR& aFirst, const RN_NODE_PTR& aSecond ); +bool operator!=( const RN_NODE_PTR& aFirst, const RN_NODE_PTR& aSecond ); + ///> General interface for filtering out nodes in search functions. struct RN_NODE_FILTER : public std::unary_function { @@ -83,7 +87,7 @@ struct RN_NODE_COMPARE : std::binary_function { bool operator()( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2 ) const { - return ( aNode1->GetX() == aNode2->GetX() && aNode1->GetY() == aNode2->GetY() ); + return aNode1 == aNode2; } }; @@ -461,7 +465,13 @@ public: * Function ClearSimple() * Removes all nodes and edges that are used for displaying ratsnest in simple mode. */ - void ClearSimple(); + void ClearSimple() + { + BOOST_FOREACH( const RN_NODE_PTR& node, m_simpleNodes ) + node->SetFlag( false ); + + m_simpleNodes.clear(); + } protected: ///> Validates edge, ie. modifies source and target nodes for an edge @@ -556,7 +566,11 @@ public: * Function ClearSimple() * Clears the list of nodes for which ratsnest is drawn in simple mode (one line per node). */ - void ClearSimple(); + void ClearSimple() + { + BOOST_FOREACH( RN_NET& net, m_nets ) + net.ClearSimple(); + } /** * Function ProcessBoard()