pcbnew: Code cleanup

Moving functions to std:: algorithms where feasible to reduce the code
burden.
This commit is contained in:
Seth Hillbrand 2018-10-12 05:54:21 -07:00
parent 6c34fdefd7
commit cc776f71a9
3 changed files with 7 additions and 33 deletions

View File

@ -82,13 +82,8 @@ bool CN_CLUSTER::Contains( const CN_ITEM* aItem )
bool CN_CLUSTER::Contains( const BOARD_CONNECTED_ITEM* aItem )
{
for( auto item : m_items )
{
if( item->Valid() && item->Parent() == aItem )
return true;
}
return false;
return std::find_if( m_items.begin(), m_items.end(), [ &aItem ] ( const CN_ITEM* item )
{ return item->Valid() && item->Parent() == aItem; } ) != m_items.end();
}

View File

@ -27,6 +27,7 @@
#endif
#include <thread>
#include <algorithm>
#include <connectivity_data.h>
#include <connectivity_algo.h>
@ -237,34 +238,13 @@ void CONNECTIVITY_DATA::FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_
m_connAlgo->FindIsolatedCopperIslands( aZones );
}
int CONNECTIVITY_DATA::countRelevantItems( const std::vector<BOARD_ITEM*>& aItems )
{
int n = 0;
for( const auto item : aItems )
{
switch( item->Type() )
{
case PCB_TRACE_T:
case PCB_PAD_T:
case PCB_ZONE_AREA_T:
case PCB_MODULE_T:
case PCB_VIA_T:
n++;
break;
default:
break;
}
}
return n;
}
void CONNECTIVITY_DATA::ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems )
{
if( countRelevantItems( aItems ) == 0 )
if( std::none_of( aItems.begin(), aItems.end(), []( const BOARD_ITEM* aItem )
{ return( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_PAD_T ||
aItem->Type() == PCB_ZONE_AREA_T || aItem->Type() == PCB_MODULE_T ||
aItem->Type() == PCB_VIA_T ); } ) )
{
m_dynamicRatsnest.clear();
return ;

View File

@ -243,7 +243,6 @@ public:
private:
int countRelevantItems( const std::vector<BOARD_ITEM*>& aItems );
void updateRatsnest();
void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );