From f6f99e45b9d2176b02c5472b2238faecc024844b Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 19 Jun 2023 10:43:30 +0200 Subject: [PATCH] Pcbnew, graphic importer: convert arc with large radius to segment. Arcs having a too large radius cannot be safely handled. The criteria (not perfect) is radius < INT_MAX/2 to use arcs Fixes #14210 https://gitlab.com/kicad/code/kicad/-/issues/14210 --- pcbnew/import_gfx/graphics_importer_pcbnew.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp index d73dd4f85f..02ee66e6ef 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp @@ -116,6 +116,21 @@ void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& arc->SetArcGeometry( MapCoordinate( aStart ), MapCoordinate( mid ), MapCoordinate( end ) ); + // Ensure the arc can be handled by Pcbnew. Arcs with a too big radius cannot. + // The criteria used here is radius < MAX_INT / 2. + // this is not perfect, but we do not know the exact final position of the arc, so + // we cannot test the coordinate values, because the arc can be moved before being placed. + VECTOR2D center = CalcArcCenter( arc->GetStart(), arc->GetEnd(), aAngle ); + double radius = ( center - arc->GetStart() ).EuclideanNorm(); + double rd_max_value = std::numeric_limits::max() / 2.0; + + if( radius >= rd_max_value ) + { + // Arc cannot be handled: convert it to a segment + AddLine( aStart, end, aWidth ); + return; + } + arc->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) ); if( arc->Type() == PCB_FP_SHAPE_T )