fix for issue 17429 - backported from master

- issue: https://gitlab.com/kicad/code/kicad/-/issues/17429
- fix makes RunOnUnconnectedEdges sort the unnconnected edges before
  running the passed in function on them
- stable sort order keeps the algorith from having non-deterministic
  runs
This commit is contained in:
Adam Feuer 2025-01-14 08:39:51 -08:00
parent 799dadeeec
commit 7cbf86f864

View File

@ -717,23 +717,37 @@ unsigned int CONNECTIVITY_DATA::GetPadCount( int aNet ) const
return n;
}
void sortEdgesOnSerializationForStableOrdering( std::vector<CN_EDGE>& edges )
{
std::sort(edges.begin(), edges.end(),
[](const CN_EDGE& a, const CN_EDGE& b)
{
return a.SerializeToString() < b.SerializeToString();
});
}
void CONNECTIVITY_DATA::RunOnUnconnectedEdges( std::function<bool( CN_EDGE& )> aFunc )
{
std::vector<CN_EDGE> edges;
for( RN_NET* rnNet : m_nets )
{
if( rnNet )
{
for( CN_EDGE& edge : rnNet->GetEdges() )
{
if( !aFunc( edge ) )
return;
edges.push_back( edge );
}
}
}
sortEdgesOnSerializationForStableOrdering( edges );
for( CN_EDGE& edge : edges )
{
if( !aFunc( edge ) )
return;
}
}
static int getMinDist( BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aPoint )
{
switch( aItem->Type() )