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
This commit is contained in:
parent
2aa9ea87eb
commit
b72c6e5cb0
|
@ -2491,6 +2491,13 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
|
||||||
double xb = currContour.CPoint( nextVertex ).x - x1;
|
double xb = currContour.CPoint( nextVertex ).x - x1;
|
||||||
double yb = currContour.CPoint( nextVertex ).y - y1;
|
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
|
// Compute the new distances
|
||||||
double lena = hypot( xa, ya );
|
double lena = hypot( xa, ya );
|
||||||
double lenb = hypot( xb, yb );
|
double lenb = hypot( xb, yb );
|
||||||
|
@ -2573,6 +2580,9 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
|
||||||
double nx = xc + xs;
|
double nx = xc + xs;
|
||||||
double ny = yc + ys;
|
double ny = yc + ys;
|
||||||
|
|
||||||
|
if( std::isnan( nx ) || std::isnan( ny ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
newContour.Append( KiROUND( nx ), KiROUND( ny ) );
|
newContour.Append( KiROUND( nx ), KiROUND( ny ) );
|
||||||
|
|
||||||
// Store the previous added corner to make a sanity check
|
// Store the previous added corner to make a sanity check
|
||||||
|
@ -2584,6 +2594,9 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
|
||||||
nx = xc + cos( startAngle + ( j + 1 ) * deltaAngle ) * radius;
|
nx = xc + cos( startAngle + ( j + 1 ) * deltaAngle ) * radius;
|
||||||
ny = yc - sin( 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.
|
// Sanity check: the rounding can produce repeated corners; do not add them.
|
||||||
if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY )
|
if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue