Add a clearance check for closed shape line chains
Also improves speed of multiple point checks by first eliminating points outside of the BBox.
This commit is contained in:
parent
108dc20fba
commit
d67821d771
|
@ -331,7 +331,7 @@ int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
|
||||||
|
|
||||||
bool SHAPE_LINE_CHAIN::PointInside( const VECTOR2I& aP ) const
|
bool SHAPE_LINE_CHAIN::PointInside( const VECTOR2I& aP ) const
|
||||||
{
|
{
|
||||||
if( !m_closed || SegmentCount() < 3 )
|
if( !m_closed || SegmentCount() < 3 || !BBox().Contains( aP ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool inside = false;
|
bool inside = false;
|
||||||
|
@ -358,6 +358,12 @@ bool SHAPE_LINE_CHAIN::PointInside( const VECTOR2I& aP ) const
|
||||||
|
|
||||||
|
|
||||||
bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const
|
bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const
|
||||||
|
{
|
||||||
|
return CheckClearance( aP, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SHAPE_LINE_CHAIN::CheckClearance( const VECTOR2I& aP, const int aDist) const
|
||||||
{
|
{
|
||||||
if( !PointCount() )
|
if( !PointCount() )
|
||||||
return false;
|
return false;
|
||||||
|
@ -372,7 +378,7 @@ bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const
|
||||||
if( s.A == aP || s.B == aP )
|
if( s.A == aP || s.B == aP )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( s.Distance( aP ) <= 1 )
|
if( s.Distance( aP ) <= aDist )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -532,7 +532,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Function PointInside()
|
* Function PointInside()
|
||||||
*
|
*
|
||||||
* Checks if point aP lies inside a convex polygon defined by the line chain. For closed
|
* Checks if point aP lies inside a polygon (any type) defined by the line chain. For closed
|
||||||
* shapes only.
|
* shapes only.
|
||||||
* @param aP point to check
|
* @param aP point to check
|
||||||
* @return true if the point is inside the shape (edge is not treated as being inside).
|
* @return true if the point is inside the shape (edge is not treated as being inside).
|
||||||
|
@ -548,6 +548,16 @@ public:
|
||||||
*/
|
*/
|
||||||
bool PointOnEdge( const VECTOR2I& aP ) const;
|
bool PointOnEdge( const VECTOR2I& aP ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function CheckClearance()
|
||||||
|
*
|
||||||
|
* Checks if point aP is closer to (or on) an edge or vertex of the line chain.
|
||||||
|
* @param aP point to check
|
||||||
|
* @param aDist distance in internal units
|
||||||
|
* @return true if the point is equal to or closer than aDist to the line chain.
|
||||||
|
*/
|
||||||
|
bool CheckClearance( const VECTOR2I& aP, const int aDist) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SelfIntersecting()
|
* Function SelfIntersecting()
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue