mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Checking flags instead of copying is faster in RN_NET::NearestBicoloredPair.
Partially reverts 87171f53c78b16d60f61173a0df2684fad628c90
This commit is contained in:
parent
8d7c60eb3e
commit
e9ece8266b
@ -536,12 +536,6 @@ bool RN_NET::NearestBicoloredPair( RN_NET* aOtherNet, VECTOR2I& aPos1, VECTOR2I&
|
||||
}
|
||||
};
|
||||
|
||||
std::multiset<std::shared_ptr<CN_ANCHOR>, CN_PTR_CMP> nodes_b;
|
||||
|
||||
std::copy_if( m_nodes.begin(), m_nodes.end(), std::inserter( nodes_b, nodes_b.end() ),
|
||||
[]( const std::shared_ptr<CN_ANCHOR> &aVal )
|
||||
{ return !aVal->GetNoLine(); } );
|
||||
|
||||
/// Sweep-line algorithm to cut the number of comparisons to find the closest point
|
||||
///
|
||||
/// Step 1: The outer loop needs to be the subset (selected nodes) as it is a linear search
|
||||
@ -554,13 +548,16 @@ bool RN_NET::NearestBicoloredPair( RN_NET* aOtherNet, VECTOR2I& aPos1, VECTOR2I&
|
||||
/// Step 2: O( log n ) search to identify a close element ordered by x
|
||||
/// The fwd_it iterator will move forward through the elements while
|
||||
/// the rev_it iterator will move backward through the same set
|
||||
auto fwd_it = nodes_b.lower_bound( nodeA );
|
||||
auto fwd_it = m_nodes.lower_bound( nodeA );
|
||||
auto rev_it = std::make_reverse_iterator( fwd_it );
|
||||
|
||||
for( ; fwd_it != nodes_b.end(); ++fwd_it )
|
||||
for( ; fwd_it != m_nodes.end(); ++fwd_it )
|
||||
{
|
||||
const std::shared_ptr<CN_ANCHOR>& nodeB = *fwd_it;
|
||||
|
||||
if( nodeB->GetNoLine() )
|
||||
continue;
|
||||
|
||||
SEG::ecoord distX_sq = SEG::Square( nodeA->Pos().x - nodeB->Pos().x );
|
||||
|
||||
/// As soon as the x distance (primary sort) is larger than the smallest distance,
|
||||
@ -572,10 +569,13 @@ bool RN_NET::NearestBicoloredPair( RN_NET* aOtherNet, VECTOR2I& aPos1, VECTOR2I&
|
||||
}
|
||||
|
||||
/// Step 3: using the same starting point, check points backwards for closer points
|
||||
for( ; rev_it != nodes_b.rend(); ++rev_it )
|
||||
for( ; rev_it != m_nodes.rend(); ++rev_it )
|
||||
{
|
||||
const std::shared_ptr<CN_ANCHOR>& nodeB = *rev_it;
|
||||
|
||||
if( nodeB->GetNoLine() )
|
||||
continue;
|
||||
|
||||
SEG::ecoord distX_sq = SEG::Square( nodeA->Pos().x - nodeB->Pos().x );
|
||||
|
||||
if( distX_sq > distMax_sq )
|
||||
|
Loading…
x
Reference in New Issue
Block a user