geometry: add minimum distance threshold parameter to SHAPE_LINE_CHAIN::Find()/FindSegment()

This commit is contained in:
Tomasz Wlostowski 2021-05-27 23:38:41 +02:00
parent b3fb7190df
commit 7553b7b092
2 changed files with 17 additions and 7 deletions

View File

@ -544,7 +544,7 @@ public:
* @param aP the point to be looked for
* @return index of the correspoinding point in the line chain or negative when not found.
*/
int Find( const VECTOR2I& aP ) const;
int Find( const VECTOR2I& aP, int aThreshold = 0 ) const;
/**
* Function FindSegment()
@ -553,7 +553,7 @@ public:
* @param aP the point to be looked for
* @return index of the correspoinding segment in the line chain or negative when not found.
*/
int FindSegment( const VECTOR2I& aP ) const;
int FindSegment( const VECTOR2I& aP, int aThreshold = 1 ) const;
/**
* Function Slice()

View File

@ -463,20 +463,30 @@ int SHAPE_LINE_CHAIN::Split( const VECTOR2I& aP )
}
int SHAPE_LINE_CHAIN::Find( const VECTOR2I& aP ) const
int SHAPE_LINE_CHAIN::Find( const VECTOR2I& aP, int aThreshold ) const
{
for( int s = 0; s < PointCount(); s++ )
if( CPoint( s ) == aP )
return s;
{
if( aThreshold == 0 )
{
if( CPoint( s ) == aP )
return s;
}
else
{
if( (CPoint( s ) - aP).EuclideanNorm() <= aThreshold )
return s;
}
}
return -1;
}
int SHAPE_LINE_CHAIN::FindSegment( const VECTOR2I& aP ) const
int SHAPE_LINE_CHAIN::FindSegment( const VECTOR2I& aP, int aThreshold ) const
{
for( int s = 0; s < SegmentCount(); s++ )
if( CSegment( s ).Distance( aP ) <= 1 )
if( CSegment( s ).Distance( aP ) <= aThreshold )
return s;
return -1;