From d4edc70f65a0e3ebc1ca2ab5f60bc3f437500078 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 7 Jun 2021 13:54:30 -0700 Subject: [PATCH] Remove magic numbers where possible Constant scales will be pre-calculated during compilation, so we can leave the actual formula in place without penalty --- pcbnew/router/pns_solid.cpp | 4 ++-- pcbnew/router/pns_utils.cpp | 21 ++++++++++++++++----- pcbnew/router/pns_via.cpp | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pcbnew/router/pns_solid.cpp b/pcbnew/router/pns_solid.cpp index 96d11d2cc3..da5d39985d 100644 --- a/pcbnew/router/pns_solid.cpp +++ b/pcbnew/router/pns_solid.cpp @@ -49,7 +49,7 @@ static const SHAPE_LINE_CHAIN buildHullForPrimitiveShape( const SHAPE* aShape, i return OctagonalHull( rect->GetPosition(), rect->GetSize(), cl + 1, - 0.2 * cl ); + 0 ); } case SH_CIRCLE: @@ -59,7 +59,7 @@ static const SHAPE_LINE_CHAIN buildHullForPrimitiveShape( const SHAPE* aShape, i return OctagonalHull( circle->GetCenter() - VECTOR2I( r, r ), VECTOR2I( 2 * r, 2 * r ), cl + 1, - 0.585 * ( r + cl ) ); + 2.0 * ( 1.0 - M_SQRT1_2 ) * ( r + cl ) ); } case SH_SEGMENT: diff --git a/pcbnew/router/pns_utils.cpp b/pcbnew/router/pns_utils.cpp index 57bf80f7da..7547477a8e 100644 --- a/pcbnew/router/pns_utils.cpp +++ b/pcbnew/router/pns_utils.cpp @@ -40,13 +40,24 @@ const SHAPE_LINE_CHAIN OctagonalHull( const VECTOR2I& aP0, const VECTOR2I& aSize s.SetClosed( true ); s.Append( aP0.x - aClearance, aP0.y - aClearance + aChamfer ); - s.Append( aP0.x - aClearance + aChamfer, aP0.y - aClearance ); + + if( aChamfer ) + s.Append( aP0.x - aClearance + aChamfer, aP0.y - aClearance ); + s.Append( aP0.x + aSize.x + aClearance - aChamfer, aP0.y - aClearance ); - s.Append( aP0.x + aSize.x + aClearance, aP0.y - aClearance + aChamfer ); + + if( aChamfer ) + s.Append( aP0.x + aSize.x + aClearance, aP0.y - aClearance + aChamfer ); + s.Append( aP0.x + aSize.x + aClearance, aP0.y + aSize.y + aClearance - aChamfer ); - s.Append( aP0.x + aSize.x + aClearance - aChamfer, aP0.y + aSize.y + aClearance ); + + if( aChamfer ) + s.Append( aP0.x + aSize.x + aClearance - aChamfer, aP0.y + aSize.y + aClearance ); + s.Append( aP0.x - aClearance + aChamfer, aP0.y + aSize.y + aClearance ); - s.Append( aP0.x - aClearance, aP0.y + aSize.y + aClearance - aChamfer ); + + if( aChamfer ) + s.Append( aP0.x - aClearance, aP0.y + aSize.y + aClearance - aChamfer ); return s; } @@ -124,7 +135,7 @@ const SHAPE_LINE_CHAIN SegmentHull ( const SHAPE_SEGMENT& aSeg, int aClearance, return OctagonalHull( a - VECTOR2I( aSeg.GetWidth() / 2, aSeg.GetWidth() / 2 ), VECTOR2I( aSeg.GetWidth(), aSeg.GetWidth() ), cl + 1, - 0.52 * d ); + 2.0 * ( 1.0 - M_SQRT1_2 ) * d ); } VECTOR2I dir = b - a; diff --git a/pcbnew/router/pns_via.cpp b/pcbnew/router/pns_via.cpp index b8c265831d..62c9b93941 100644 --- a/pcbnew/router/pns_via.cpp +++ b/pcbnew/router/pns_via.cpp @@ -82,7 +82,7 @@ const SHAPE_LINE_CHAIN VIA::Hull( int aClearance, int aWalkaroundThickness, int // Chamfer = width * ( 1 - sqrt(2)/2 ) for equilateral octagon return OctagonalHull( m_pos - VECTOR2I( width / 2, width / 2 ), VECTOR2I( width, width ), - cl + 1, ( 2 * cl + width ) * 0.2928 ); + cl + 1, ( 2 * cl + width ) * ( 1.0 - M_SQRT1_2 ) ); }