Minor optimization for ratsnest.

This commit is contained in:
Maciej Suminski 2015-06-04 14:54:06 +02:00
parent e81477704d
commit 0331d9958a
1 changed files with 24 additions and 4 deletions

View File

@ -48,6 +48,10 @@
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
#ifdef PROFILE
#include <profile.h>
#endif
uint64_t getDistance( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2 ) uint64_t getDistance( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2 )
{ {
// Drop the least significant bits to avoid overflow // Drop the least significant bits to avoid overflow
@ -959,14 +963,20 @@ void RN_NET::processZones()
BOOST_FOREACH( std::deque<RN_POLY>& polygons, m_zonePolygons | boost::adaptors::map_values ) BOOST_FOREACH( std::deque<RN_POLY>& polygons, m_zonePolygons | boost::adaptors::map_values )
{ {
if( polygons.empty() )
continue;
RN_LINKS::RN_NODE_SET::iterator point, pointEnd; RN_LINKS::RN_NODE_SET::iterator point, pointEnd;
std::deque<RN_POLY>::iterator poly, polyEnd;
// Sorting by area should speed up the processing, as smaller polygons are computed // Sorting by area should speed up the processing, as smaller polygons are computed
// faster and may reduce the number of points for further checks // faster and may reduce the number of points for further checks
std::sort( polygons.begin(), polygons.end(), sortArea ); std::sort( polygons.begin(), polygons.end(), sortArea );
for( poly = polygons.begin(), polyEnd = polygons.end(); poly != polyEnd; ++poly ) std::deque<RN_POLY>::iterator poly = polygons.begin(), polyEnd = polygons.end();
const RN_NODE_PTR& node = poly->GetNode();
std::deque<RN_EDGE_MST_PTR>& connections = m_zoneConnections[poly->GetParent()];
for( ; poly != polyEnd; ++poly )
{ {
point = candidates.begin(); point = candidates.begin();
pointEnd = candidates.end(); pointEnd = candidates.end();
@ -975,8 +985,8 @@ void RN_NET::processZones()
{ {
if( poly->HitTest( *point ) ) if( poly->HitTest( *point ) )
{ {
RN_EDGE_MST_PTR connection = m_links.AddConnection( poly->GetNode(), *point ); RN_EDGE_MST_PTR connection = m_links.AddConnection( node, *point );
m_zoneConnections[poly->GetParent()].push_back( connection ); connections.push_back( connection );
// This point already belongs to a polygon, we do not need to check it anymore // This point already belongs to a polygon, we do not need to check it anymore
point = candidates.erase( point ); point = candidates.erase( point );
@ -1184,6 +1194,11 @@ void RN_DATA::Recalculate( int aNet )
if( aNet < 0 && netCount > 1 ) // Recompute everything if( aNet < 0 && netCount > 1 ) // Recompute everything
{ {
#ifdef PROFILE
prof_counter totalRealTime;
prof_start( &totalRealTime );
#endif
unsigned int i; unsigned int i;
#ifdef USE_OPENMP #ifdef USE_OPENMP
@ -1200,6 +1215,11 @@ void RN_DATA::Recalculate( int aNet )
updateNet( i ); updateNet( i );
} }
} /* end of parallel section */ } /* end of parallel section */
#ifdef PROFILE
prof_end( &totalRealTime );
wxLogDebug( wxT( "Recalculate all nets: %.1f ms" ), totalRealTime.msecs() );
#endif /* PROFILE */
} }
else if( aNet > 0 ) // Recompute only specific net else if( aNet > 0 ) // Recompute only specific net
{ {