Remove magic numbers where possible
Constant scales will be pre-calculated during compilation, so we can leave the actual formula in place without penalty
This commit is contained in:
parent
b0e6bbb39c
commit
d4edc70f65
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue