From 2e509480a4ea18ce2103c5eb910c9f61b77e8af7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 11 Jan 2020 16:50:18 +0000 Subject: [PATCH] Fix guaranteed divide-by-zero error when called with correction of 0. --- .../board_items_to_polygon_shape_transform.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index b86f961ce6..a794aa66bc 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -646,15 +646,22 @@ void D_PAD::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, case PAD_SHAPE_CUSTOM: { - int numSegs = std::max( GetArcToSegmentCount( aClearanceValue, aError, 360.0 ), - pad_min_seg_per_circle_count ); - double correction = GetCircletoPolyCorrectionFactor( numSegs ); - int clearance = KiROUND( aClearanceValue * correction ); SHAPE_POLY_SET outline; // Will contain the corners in board coordinates outline.Append( m_customShapeAsPolygon ); CustomShapeAsPolygonToBoardPosition( &outline, GetPosition(), GetOrientation() ); + // TODO: do we need the Simplify() & Fracture() if we're not inflating? outline.Simplify( SHAPE_POLY_SET::PM_FAST ); - outline.Inflate( clearance, numSegs ); + + if( aClearanceValue ) + { + int numSegs = std::max( GetArcToSegmentCount( aClearanceValue, aError, 360.0 ), + pad_min_seg_per_circle_count ); + double correction = GetCircletoPolyCorrectionFactor( numSegs ); + int clearance = KiROUND( aClearanceValue * correction ); + + outline.Inflate( clearance, numSegs ); + } + outline.Fracture( SHAPE_POLY_SET::PM_FAST ); aCornerBuffer.Append( outline ); }