Convert DXF arcs in fp space

Once the arcs are set in pcbnew, they have integer representation and
can accumulate rounding errors.  So we convert the start/end points in
the importer to ensure that the connected points in a DXF remain
connected

Fixes https://gitlab.com/kicad/code/kicad/issues/9827
This commit is contained in:
Seth Hillbrand 2021-12-07 10:51:58 -08:00
parent 42f63b679d
commit c613f5e2f1
1 changed files with 13 additions and 4 deletions

View File

@ -98,11 +98,20 @@ void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D&
std::unique_ptr<PCB_SHAPE> arc( createDrawing() );
arc->SetShape( SHAPE_T::ARC );
arc->SetLayer( GetLayer() );
/**
* We need to perform the rotation/conversion here while still using floating point values
* to avoid rounding errors when operating in integer space in pcbnew
*/
VECTOR2D end = aStart - aCenter;
VECTOR2D mid = aStart - aCenter;
end = aCenter + end.Rotate( DEG2RAD( aAngle ) );
mid = aCenter + mid.Rotate( DEG2RAD( aAngle / 2.0 ) );
arc->SetArcGeometry( MapCoordinate( aStart ), MapCoordinate( mid ), MapCoordinate( end ) );
arc->SetWidth( MapLineWidth( aWidth ) );
arc->SetCenter( MapCoordinate( aCenter ));
arc->SetStart( MapCoordinate( aStart ) );
arc->SetArcAngleAndEnd( aAngle * 10.0, /* pcbnew uses the decidegree */
true /* infer winding direction from the sign of aAngle */);
if( arc->Type() == PCB_FP_SHAPE_T )
static_cast<FP_SHAPE*>( arc.get() )->SetLocalCoord();