Add GetCircleToSegmentError() to geometry/geometry_utils.

This function returns the error created by a circle to segment approximation.
This commit is contained in:
jean-pierre charras 2021-06-26 18:57:07 +02:00
parent 5c21f93803
commit 310adedf85
3 changed files with 26 additions and 4 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -54,6 +54,13 @@ enum ERROR_LOC { ERROR_OUTSIDE, ERROR_INSIDE };
*/ */
int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree ); int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree );
/**
* @return the max error when approximating a circle by segments
* @param aRadius is the radius of the circle
* @param aSegCount is the seg count to approximate the circle
*/
int GetCircleToSegmentError( int aRadius, int aSegCount );
/** /**
* When creating polygons to create a clearance polygonal area, the polygon must * When creating polygons to create a clearance polygonal area, the polygon must
* be same or bigger than the original shape. * be same or bigger than the original shape.

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -63,6 +63,19 @@ int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree )
return std::max( segCount, 2 ); return std::max( segCount, 2 );
} }
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 );
double alpha = M_PI / aSegCount;
double error = aRadius * ( 1.0 - cos( alpha) );
return error;
}
// When creating polygons to create a clearance polygonal area, the polygon must // When creating polygons to create a clearance polygonal area, the polygon must
// be same or bigger than the original shape. // be same or bigger than the original shape.
// Polygons are bigger if the original shape has arcs (round rectangles, ovals, // Polygons are bigger if the original shape has arcs (round rectangles, ovals,

View File

@ -703,11 +703,13 @@ void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
// Debug only: enable this code only to test the TransformArcToPolygon function // Debug only: enable this code only to test the TransformArcToPolygon function
// and display the polygon outline created by it. // and display the polygon outline created by it.
// arcs on F_Cu are approximated with ERROR_INSIDE, others with ERROR_OUTSIDE
#if 0 #if 0
SHAPE_POLY_SET cornerBuffer; SHAPE_POLY_SET cornerBuffer;
int errorloc = aArc->GetBoard()->GetDesignSettings().m_MaxError; int error_value = aArc->GetBoard()->GetDesignSettings().m_MaxError;
ERROR_LOC errorloc = aLayer == F_Cu ? ERROR_LOC::ERROR_INSIDE : ERROR_LOC::ERROR_OUTSIDE;
TransformArcToPolygon( cornerBuffer, aArc->GetStart(), aArc->GetMid(), TransformArcToPolygon( cornerBuffer, aArc->GetStart(), aArc->GetMid(),
aArc->GetEnd(), width, errorloc, ERROR_LOC::ERROR_OUTSIDE ); aArc->GetEnd(), width, error_value, errorloc );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false ); m_gal->SetIsFill( false );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );