7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 11:20:09 +00:00

Gerbview: fix arc to segment approximation when drawing Regions (polygons)

The approx was 36 segments per 360 deg. But this is not good for arcs having
A small arc angle and a large radius.
The fix uses a max error (currently 5 microns) to calculate the approximation.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18587
This commit is contained in:
jean-pierre charras 2024-08-22 18:29:43 +02:00
parent 9973f1b306
commit 55e1b6a80e

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2024 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
@ -298,7 +298,7 @@ void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, const VECTOR2I
aGbrItem->SetLayerPolarity( aLayerNegative );
}
#include <wx/log.h>
/**
* Create an arc G code when found in polygon outlines.
*
@ -368,9 +368,12 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, const VECTOR2I& aStart, con
EDA_ANGLE arc_angle = start_angle - end_angle;
// Approximate arc by 36 segments per 360 degree
EDA_ANGLE increment_angle = ANGLE_360 / 36;
int count = std::abs( arc_angle.AsDegrees() / increment_angle.AsDegrees() );
// Approximate arc by segments with a approximation error = err_max
// a max err = 5 microns looks good
const int approx_err_max = gerbIUScale.mmToIU( 0.005 );
int radius = VECTOR2I( aStart - rel_center ).EuclideanNorm();
int count = GetArcToSegmentCount( radius, approx_err_max, arc_angle );
EDA_ANGLE increment_angle = std::abs( arc_angle ) / count;
if( aGbrItem->m_ShapeAsPolygon.OutlineCount() == 0 )
aGbrItem->m_ShapeAsPolygon.NewOutline();