Avoid NaNs when applying fillets

Segments that are inline with each other will create NaNs when
filleting.  This double check prevents NaN points from being added to
the polygon

(cherry picked from commit b72c6e5cb0)
This commit is contained in:
Seth Hillbrand 2023-05-03 11:48:36 -07:00
parent 57ae43890c
commit 53eb39e033
1 changed files with 13 additions and 0 deletions

View File

@ -2492,6 +2492,13 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
double xb = currContour.CPoint( nextVertex ).x - x1;
double yb = currContour.CPoint( nextVertex ).y - y1;
// Avoid segments that will generate nans below
if( std::abs( xa + xb ) < std::numeric_limits<double>::epsilon()
&& std::abs( ya + yb ) < std::numeric_limits<double>::epsilon() )
{
continue;
}
// Compute the new distances
double lena = hypot( xa, ya );
double lenb = hypot( xb, yb );
@ -2574,6 +2581,9 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
double nx = xc + xs;
double ny = yc + ys;
if( std::isnan( nx ) || std::isnan( ny ) )
continue;
newContour.Append( KiROUND( nx ), KiROUND( ny ) );
// Store the previous added corner to make a sanity check
@ -2585,6 +2595,9 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
nx = xc + cos( startAngle + ( j + 1 ) * deltaAngle ) * radius;
ny = yc - sin( startAngle + ( j + 1 ) * deltaAngle ) * radius;
if( std::isnan( nx ) || std::isnan( ny ) )
continue;
// Sanity check: the rounding can produce repeated corners; do not add them.
if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY )
{