Fix minor issue in TransformCircleToPolygon() when aError is set to a large value.

pcb_painter.cpp: add (but not activate) compil option to show the conversion
of SHAPE_ARC::ConvertToPolyline as segments, for debug purposes.
This commit is contained in:
jean-pierre charras 2021-06-28 15:50:16 +02:00
parent 9a865b1989
commit fa49b54f93
3 changed files with 30 additions and 6 deletions

View File

@ -55,7 +55,10 @@ void TransformCircleToPolygon( SHAPE_LINE_CHAIN& aCornerBuffer, wxPoint aCenter,
int radius = aRadius;
if( aErrorLoc == ERROR_OUTSIDE )
radius += GetCircleToPolyCorrection( aError );
{
int actual_error = GetCircleToSegmentError( radius, numSegs );
radius += GetCircleToPolyCorrection( actual_error );
}
for( int angle = 0; angle < 3600; angle += delta )
{

View File

@ -66,12 +66,14 @@ int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree )
int GetCircleToSegmentError( int aRadius, int aSegCount )
{
// avoid divide-by-zero, and the minimal seg count used here = 2
// (giving error = aRadius)
aSegCount = std::max( 2, aSegCount );
// This is similar to the "inverse" of GetArcToSegmentCount()
// The minimal seg count is 2, giving error = aRadius
if( aSegCount <= 2 )
return aRadius;
double alpha = M_PI / aSegCount;
double error = aRadius * ( 1.0 - cos( alpha) );
int error = KiROUND( aRadius * ( 1.0 - cos( alpha) ) );
return error;
}

View File

@ -713,9 +713,28 @@ void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->SetStrokeColor( COLOR4D( 0, 0, 1.0, 1.0 ) );
m_gal->DrawPolygon( cornerBuffer );
#endif
// Debug only: enable this code only to test the SHAPE_ARC::ConvertToPolyline function
// and display the polyline created by it.
#if 0
int error_value2 = aArc->GetBoard()->GetDesignSettings().m_MaxError;
SHAPE_ARC arc( aArc->GetCenter(), aArc->GetStart(),
aArc->GetAngle() / 10.0, aArc->GetWidth() );
SHAPE_LINE_CHAIN arcSpine = arc.ConvertToPolyline( error_value2 );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( COLOR4D( 0.3, 0.2, 0.5, 1.0 ) );
for( int idx = 1; idx < arcSpine.PointCount(); idx++ )
{
m_gal->DrawSegment( arcSpine.CPoint( idx-1 ), arcSpine.CPoint( idx ),
aArc->GetWidth() );
};
#endif
}