Update SHAPE_POLY_SET API to not hide virtual functions

This commit is contained in:
Jon Evans 2023-08-18 10:08:09 -04:00
parent 6c5ec288a5
commit 0c529411d7
4 changed files with 19 additions and 8 deletions

View File

@ -1373,7 +1373,13 @@ public:
* @return The minimum distance squared between aPoint and all the polygons in the set.
* If the point is contained in any of the polygons, the distance is zero.
*/
SEG::ecoord SquaredDistance( VECTOR2I aPoint, VECTOR2I* aNearest = nullptr ) const;
SEG::ecoord SquaredDistance( const VECTOR2I& aPoint, bool aOutlineOnly,
VECTOR2I* aNearest ) const;
SEG::ecoord SquaredDistance( const VECTOR2I& aPoint, bool aOutlineOnly = false ) const override
{
return SquaredDistance( aPoint, aOutlineOnly, nullptr );
}
/**
* Compute the minimum distance squared between aSegment and all the polygons in the set.
@ -1386,7 +1392,7 @@ public:
* @return The minimum distance squared between aSegment and all the polygons in the set.
* If the point is contained in the polygon, the distance is zero.
*/
SEG::ecoord SquaredDistance( const SEG& aSegment, VECTOR2I* aNearest = nullptr ) const;
SEG::ecoord SquaredDistanceToSeg( const SEG& aSegment, VECTOR2I* aNearest = nullptr ) const;
/**
* Check whether the \a aGlobalIndex-th vertex belongs to a hole.

View File

@ -1842,7 +1842,7 @@ bool SHAPE_POLY_SET::Collide( const SEG& aSeg, int aClearance, int* aActual,
VECTOR2I* aLocation ) const
{
VECTOR2I nearest;
ecoord dist_sq = SquaredDistance( aSeg, aLocation ? &nearest : nullptr );
ecoord dist_sq = SquaredDistanceToSeg( aSeg, aLocation ? &nearest : nullptr );
if( dist_sq == 0 || dist_sq < SEG::Square( aClearance ) )
{
@ -1866,7 +1866,7 @@ bool SHAPE_POLY_SET::Collide( const VECTOR2I& aP, int aClearance, int* aActual,
return false;
VECTOR2I nearest;
ecoord dist_sq = SquaredDistance( aP, aLocation ? &nearest : nullptr );
ecoord dist_sq = SquaredDistance( aP, false, aLocation ? &nearest : nullptr );
if( dist_sq == 0 || dist_sq < SEG::Square( aClearance ) )
{
@ -2394,8 +2394,12 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( const SEG& aSegment, int a
}
SEG::ecoord SHAPE_POLY_SET::SquaredDistance( VECTOR2I aPoint, VECTOR2I* aNearest ) const
SEG::ecoord SHAPE_POLY_SET::SquaredDistance( const VECTOR2I& aPoint, bool aOutlineOnly,
VECTOR2I* aNearest ) const
{
wxASSERT_MSG( !aOutlineOnly, wxT( "Warning: SHAPE_POLY_SET::SquaredDistance does not yet "
"support aOutlineOnly==true" ) );
SEG::ecoord currentDistance_sq;
SEG::ecoord minDistance_sq = VECTOR2I::ECOORD_MAX;
VECTOR2I nearest;
@ -2419,7 +2423,7 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistance( VECTOR2I aPoint, VECTOR2I* aNearest
}
SEG::ecoord SHAPE_POLY_SET::SquaredDistance( const SEG& aSegment, VECTOR2I* aNearest ) const
SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToSeg( const SEG& aSegment, VECTOR2I* aNearest ) const
{
SEG::ecoord currentDistance_sq;
SEG::ecoord minDistance_sq = VECTOR2I::ECOORD_MAX;
@ -3077,3 +3081,4 @@ bool SHAPE_POLY_SET::PointInside( const VECTOR2I& aPt, int aAccuracy, bool aUseB
return false;
}

View File

@ -203,7 +203,7 @@ bool DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run()
// Disable is-inside test in SquaredDistance
padOutline.Outline( 0 ).SetClosed( false );
SEG::ecoord dist_sq = padOutline.SquaredDistance( slot->GetSeg() );
SEG::ecoord dist_sq = padOutline.SquaredDistanceToSeg( slot->GetSeg() );
annularWidth = sqrt( dist_sq ) - slot->GetWidth() / 2;
}
}

View File

@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE( SegDistance )
{
SHAPE_POLY_SET polyset = c.m_polyset;
int dist = sqrt( polyset.SquaredDistance( c.m_seg ) ) - ( c.m_seg_width / 2 );
int dist = sqrt( polyset.SquaredDistanceToSeg( c.m_seg ) ) - ( c.m_seg_width / 2 );
// right answer?
BOOST_CHECK_PREDICATE( KI_TEST::IsWithin<int>, ( dist )( c.m_exp_dist )( 1 ) );