PNS: Local min distance has a minimum points requirement
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8510
This commit is contained in:
parent
eff9746f34
commit
bd59da3642
|
@ -470,28 +470,10 @@ static bool cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCurs
|
||||||
int minDistGlob = std::numeric_limits<int>::max();
|
int minDistGlob = std::numeric_limits<int>::max();
|
||||||
int minPGlob = -1;
|
int minPGlob = -1;
|
||||||
|
|
||||||
for( int i = 0; i < dists.size() - 3; i++ )
|
|
||||||
{
|
|
||||||
if( dists[i + 2] > dists[i + 1] && dists[i] > dists[i + 1] )
|
|
||||||
{
|
|
||||||
int d = dists[i + 1];
|
|
||||||
if( d < minDistLoc )
|
|
||||||
{
|
|
||||||
minDistLoc = d;
|
|
||||||
minPLoc = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( dists.back() < minDistLoc && minPLoc >= 0 )
|
|
||||||
{
|
|
||||||
minDistLoc = dists.back();
|
|
||||||
minPLoc = dists.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int i = 0; i < dists.size(); i++ )
|
for( int i = 0; i < dists.size(); i++ )
|
||||||
{
|
{
|
||||||
int d = dists[i];
|
int d = dists[i];
|
||||||
|
|
||||||
if( d < minDistGlob )
|
if( d < minDistGlob )
|
||||||
{
|
{
|
||||||
minDistGlob = d;
|
minDistGlob = d;
|
||||||
|
@ -499,6 +481,34 @@ static bool cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCurs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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] )
|
||||||
|
{
|
||||||
|
int d = dists[i + 1];
|
||||||
|
if( d < minDistLoc )
|
||||||
|
{
|
||||||
|
minDistLoc = d;
|
||||||
|
minPLoc = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( dists.back() < minDistLoc && minPLoc >= 0 )
|
||||||
|
{
|
||||||
|
minDistLoc = dists.back();
|
||||||
|
minPLoc = dists.size() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
// fixme: I didn't make my mind yet if local or global minimum feels better. I'm leaving both
|
||||||
// in the code, enabling the global one by default
|
// in the code, enabling the global one by default
|
||||||
minPLoc = -1;
|
minPLoc = -1;
|
||||||
|
|
Loading…
Reference in New Issue