From 0c529411d75b8376b5289177f7f969acef8318f0 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 18 Aug 2023 10:08:09 -0400 Subject: [PATCH] Update SHAPE_POLY_SET API to not hide virtual functions --- libs/kimath/include/geometry/shape_poly_set.h | 10 ++++++++-- libs/kimath/src/geometry/shape_poly_set.cpp | 13 +++++++++---- pcbnew/drc/drc_test_provider_annular_width.cpp | 2 +- .../geometry/test_shape_poly_set_distance.cpp | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index 339d016dbd..8cd3dc6bbc 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -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. diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 50dcf843a1..9077fef1fe 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -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; } + diff --git a/pcbnew/drc/drc_test_provider_annular_width.cpp b/pcbnew/drc/drc_test_provider_annular_width.cpp index a1207b99b7..6d034fc9de 100644 --- a/pcbnew/drc/drc_test_provider_annular_width.cpp +++ b/pcbnew/drc/drc_test_provider_annular_width.cpp @@ -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; } } diff --git a/qa/tests/libs/kimath/geometry/test_shape_poly_set_distance.cpp b/qa/tests/libs/kimath/geometry/test_shape_poly_set_distance.cpp index 9816605239..eae67dc6e7 100644 --- a/qa/tests/libs/kimath/geometry/test_shape_poly_set_distance.cpp +++ b/qa/tests/libs/kimath/geometry/test_shape_poly_set_distance.cpp @@ -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, ( dist )( c.m_exp_dist )( 1 ) );