geometry: add minimum distance threshold parameter to SHAPE_LINE_CHAIN::Find()/FindSegment()
This commit is contained in:
parent
b3fb7190df
commit
7553b7b092
|
@ -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()
|
||||
|
|
|
@ -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( 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;
|
||||
|
|
Loading…
Reference in New Issue