From 1a493ed9edc24dd021463f47c3d7d570c4b22007 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 17 Mar 2022 12:55:24 +0100 Subject: [PATCH] Gerber plotter: fix incorrect handling of arcs in polygons. Fixes #11156 https://gitlab.com/kicad/code/kicad/issues/11156 --- common/plotters/GERBER_plotter.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/common/plotters/GERBER_plotter.cpp b/common/plotters/GERBER_plotter.cpp index 3300bf712c..f50e34fa1b 100644 --- a/common/plotters/GERBER_plotter.cpp +++ b/common/plotters/GERBER_plotter.cpp @@ -843,16 +843,6 @@ void GERBER_PLOTTER::plotArc( const SHAPE_ARC& aArc, bool aPlotInRegion ) VECTOR2I start( aArc.GetP0() ); VECTOR2I end( aArc.GetP1() ); VECTOR2I center( aArc.GetCenter() ); - EDA_ANGLE startAngle = aArc.GetStartAngle(); - EDA_ANGLE endAngle = aArc.GetEndAngle(); - - if( startAngle > endAngle ) - { - if( endAngle < ANGLE_0 ) - endAngle.Normalize(); - else - startAngle = startAngle.Normalize() - ANGLE_360; - } if( !aPlotInRegion ) MoveTo( start); @@ -860,14 +850,18 @@ void GERBER_PLOTTER::plotArc( const SHAPE_ARC& aArc, bool aPlotInRegion ) LineTo( start ); VECTOR2D devEnd = userToDeviceCoordinates( end ); - VECTOR2D devCenter = userToDeviceCoordinates( center ) - userToDeviceCoordinates( start ); + VECTOR2D devCenter = userToDeviceCoordinates( center - start ); + + // We need to know if the arc is CW or CCW in device coordinates, so build this arc. + SHAPE_ARC deviceArc( userToDeviceCoordinates( start ), + userToDeviceCoordinates( aArc.GetArcMid() ), devEnd, 0 ); fprintf( m_outputFile, "G75*\n" ); // Multiquadrant (360 degrees) mode - if( startAngle > endAngle ) - fprintf( m_outputFile, "G03*\n" ); // Active circular interpolation, CCW - else + if( deviceArc.IsClockwise() ) fprintf( m_outputFile, "G02*\n" ); // Active circular interpolation, CW + else + fprintf( m_outputFile, "G03*\n" ); // Active circular interpolation, CCW fprintf( m_outputFile, "X%dY%dI%dJ%dD01*\n", KiROUND( devEnd.x ), KiROUND( devEnd.y ),