From a9168860e0b0655a803b4479d47d073f0e6e4b41 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 8 Dec 2021 21:04:23 -0500 Subject: [PATCH] Reduce excessive epsilon in polygon search algo Fixes https://gitlab.com/kicad/code/kicad/-/issues/9903 --- pcbnew/tools/convert_tool.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index c6041d7cc2..aa38ae73b8 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -255,7 +255,9 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromSegs( const std::deque& aIt // TODO: This code has a somewhat-similar purpose to ConvertOutlineToPolygon but is slightly // different, so this remains a separate algorithm. It might be nice to analyze the dfiferences // in requirements and refactor this. - const int chainingEpsilon = Millimeter2iu( 0.02 ); + + // Very tight epsilon used here to account for rounding errors in import, not sloppy drawing + const int chainingEpsilonSquared = SEG::Square( 100 ); SHAPE_POLY_SET poly; @@ -267,15 +269,18 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromSegs( const std::deque& aIt auto closeEnough = []( VECTOR2I aLeft, VECTOR2I aRight, unsigned aLimit ) { - return ( aLeft - aRight ).SquaredEuclideanNorm() <= SEG::Square( aLimit ); + return ( aLeft - aRight ).SquaredEuclideanNorm() <= aLimit; }; auto findInsertionPoint = [&]( VECTOR2I aPoint ) -> VECTOR2I { + if( connections.count( aPoint ) ) + return aPoint; + for( const auto& candidatePair : connections ) { - if( closeEnough( aPoint, candidatePair.first, chainingEpsilon ) ) + if( closeEnough( aPoint, candidatePair.first, chainingEpsilonSquared ) ) return candidatePair.first; }