From 9537fd4e45e1d23c6cab5dd363fe665761a65fa3 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 945ef87d50..1f3326b9b0 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp @@ -109,6 +109,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 ) ); addItem( std::move( arc ) );