Update NearestBicoloredPair to m log(n) search

Instead of iterating over full set, use sweep line algorithm to limit
the number of nodes needed to be searched.  This improves the speed of
the dynamic ratsnest.
This commit is contained in:
Seth Hillbrand 2020-06-23 10:32:58 -07:00
parent 214a9d53b0
commit e8fc421a39
2 changed files with 39 additions and 6 deletions

View File

@ -424,16 +424,49 @@ bool RN_NET::NearestBicoloredPair( const RN_NET& aOtherNet, CN_ANCHOR_PTR& aNode
VECTOR2I::extended_type distMax = VECTOR2I::ECOORD_MAX;
for( const auto& nodeA : m_nodes )
for( const auto& nodeA : aOtherNet.m_nodes )
{
if( nodeA->GetNoLine() )
continue;
for( const auto& nodeB : aOtherNet.m_nodes )
auto fwd_it = m_nodes.lower_bound( nodeA );
auto rev_it = std::make_reverse_iterator( fwd_it );
for( ; fwd_it != m_nodes.end(); ++fwd_it )
{
auto nodeB = *fwd_it;
if( nodeB->GetNoLine() )
continue;
VECTOR2I::extended_type distX = nodeA->Pos().x - nodeB->Pos().x;
if( distX * distX > distMax )
break;
auto squaredDist = ( nodeA->Pos() - nodeB->Pos() ).SquaredEuclideanNorm();
if( squaredDist < distMax )
{
rv = true;
distMax = squaredDist;
aNode1 = nodeA;
aNode2 = nodeB;
}
}
for( ++rev_it; rev_it != m_nodes.rend(); ++rev_it )
{
auto nodeB = *rev_it;
if( nodeB->GetNoLine() )
continue;
VECTOR2I::extended_type distX = nodeA->Pos().x - nodeB->Pos().x;
if( distX * distX > distMax )
break;
auto squaredDist = ( nodeA->Pos() - nodeB->Pos() ).SquaredEuclideanNorm();
if( squaredDist < distMax )

View File

@ -85,10 +85,10 @@ public:
* Function MarkDirty()
* Marks ratsnest for given net as 'dirty', i.e. requiring recomputation.
*/
// void MarkDirty()
// {
// m_dirty = true;
// }
void MarkDirty()
{
m_dirty = true;
}
/**
* Function IsDirty()