From a6b1a09edfa6da50feecaa1b61f03098fc72e6ff Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 28 Feb 2023 09:15:31 -0300 Subject: [PATCH] Fix rounding errors in gerber files The userToDeviceCoordinates helper returns a VECTOR2D Converting it to VECTOR2I back and forth is a bug and generates rounding errors Cherry picked from stable branch --- common/plotters/GERBER_plotter.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/common/plotters/GERBER_plotter.cpp b/common/plotters/GERBER_plotter.cpp index 4ec85e3a57..33d93505c4 100644 --- a/common/plotters/GERBER_plotter.cpp +++ b/common/plotters/GERBER_plotter.cpp @@ -154,7 +154,6 @@ void GERBER_PLOTTER::SetGerberCoordinatesFormat( int aResolution, bool aUseInche void GERBER_PLOTTER::emitDcode( const VECTOR2D& pt, int dcode ) { - fprintf( m_outputFile, "X%dY%dD%02d*\n", KiROUND( pt.x ), KiROUND( pt.y ), dcode ); } @@ -1332,7 +1331,7 @@ void GERBER_PLOTTER::FlashPadOval( const VECTOR2I& aPos, const VECTOR2I& aSize, if( orient.IsCardinal90() ) std::swap( size.x, size.y ); - VECTOR2I pos_device = userToDeviceCoordinates( aPos ); + VECTOR2D pos_device = userToDeviceCoordinates( aPos ); int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0; selectAperture( size, 0, ANGLE_0, APERTURE::AT_OVAL, aperture_attrib ); @@ -1363,7 +1362,7 @@ void GERBER_PLOTTER::FlashPadOval( const VECTOR2I& aPos, const VECTOR2I& aSize, orient -= ANGLE_180; } - VECTOR2I pos_device = userToDeviceCoordinates( aPos ); + VECTOR2D pos_device = userToDeviceCoordinates( aPos ); int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0; selectAperture( size, 0, orient, APERTURE::AM_ROTATED_OVAL, aperture_attrib ); @@ -1426,7 +1425,7 @@ void GERBER_PLOTTER::FlashPadRect( const VECTOR2I& pos, const VECTOR2I& aSize, } else { - VECTOR2I pos_device = userToDeviceCoordinates( pos ); + VECTOR2D pos_device = userToDeviceCoordinates( pos ); int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0; selectAperture( size, 0, ANGLE_0, APERTURE::AT_RECT, aperture_attrib ); @@ -1443,7 +1442,7 @@ void GERBER_PLOTTER::FlashPadRect( const VECTOR2I& pos, const VECTOR2I& aSize, { m_hasApertureRotRect = true; - VECTOR2I pos_device = userToDeviceCoordinates( pos ); + VECTOR2D pos_device = userToDeviceCoordinates( pos ); int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0; selectAperture( size, 0, aOrient, APERTURE::AM_ROT_RECT, aperture_attrib ); @@ -1765,7 +1764,7 @@ void GERBER_PLOTTER::FlashPadChamferRoundRect( const VECTOR2I& aShapePos, const if( aData ) gbr_metadata = *static_cast( aData ); - VECTOR2I pos_device = userToDeviceCoordinates( aShapePos ); + VECTOR2D pos_device = userToDeviceCoordinates( aShapePos ); SHAPE_POLY_SET outline; std::vector cornerList;