PNS: Local min distance has a minimum points requirement

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8510
This commit is contained in:
Jon Evans 2021-05-29 12:39:14 -04:00
parent eff9746f34
commit bd59da3642
1 changed files with 29 additions and 19 deletions

View File

@ -470,6 +470,19 @@ static bool cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCurs
int minDistGlob = std::numeric_limits<int>::max();
int minPGlob = -1;
for( int i = 0; i < dists.size(); i++ )
{
int d = dists[i];
if( d < minDistGlob )
{
minDistGlob = d;
minPGlob = i;
}
}
if( dists.size() >= 3 )
{
for( int i = 0; i < dists.size() - 3; i++ )
{
if( dists[i + 2] > dists[i + 1] && dists[i] > dists[i + 1] )
@ -488,15 +501,12 @@ static bool cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCurs
minDistLoc = dists.back();
minPLoc = dists.size() - 1;
}
for( int i = 0; i < dists.size(); i++ )
{
int d = dists[i];
if( d < minDistGlob )
{
minDistGlob = d;
minPGlob = i;
}
else
{
// Too few points: just use the global
minDistLoc = minDistGlob;
minPLoc = minPGlob;
}
// fixme: I didn't make my mind yet if local or global minimum feels better. I'm leaving both