diff --git a/libs/kimath/include/geometry/geometry_utils.h b/libs/kimath/include/geometry/geometry_utils.h index 47679bb2b6..6aa5ecb529 100644 --- a/libs/kimath/include/geometry/geometry_utils.h +++ b/libs/kimath/include/geometry/geometry_utils.h @@ -2,7 +2,7 @@ * 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) 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 * 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 ); +/** + * @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 * be same or bigger than the original shape. diff --git a/libs/kimath/src/geometry/geometry_utils.cpp b/libs/kimath/src/geometry/geometry_utils.cpp index bfd8090707..a9d426b373 100644 --- a/libs/kimath/src/geometry/geometry_utils.cpp +++ b/libs/kimath/src/geometry/geometry_utils.cpp @@ -2,7 +2,7 @@ * 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) 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 * 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 ); } + +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 // be same or bigger than the original shape. // Polygons are bigger if the original shape has arcs (round rectangles, ovals, diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 2277bc9a37..98b96ccbef 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -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 // and display the polygon outline created by it. +// arcs on F_Cu are approximated with ERROR_INSIDE, others with ERROR_OUTSIDE #if 0 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(), - aArc->GetEnd(), width, errorloc, ERROR_LOC::ERROR_OUTSIDE ); + aArc->GetEnd(), width, error_value, errorloc ); m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true );