From 43dab2a8b570b9ee9ba8e8becb7df8e751092b75 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Mon, 10 Jun 2024 01:00:46 +0300 Subject: [PATCH] Altium PCB import: avoid integer overflows when rotating rectangular fills. Fixes artifacts seen in https://gitlab.com/kicad/code/kicad/-/issues/18156 (cherry picked from commit 3ea314cb9ff20295db63d7d42f58df43871d35d9) --- pcbnew/pcb_io/altium/altium_pcb.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pcbnew/pcb_io/altium/altium_pcb.cpp b/pcbnew/pcb_io/altium/altium_pcb.cpp index a164a87f08..7bc4a04c8c 100644 --- a/pcbnew/pcb_io/altium/altium_pcb.cpp +++ b/pcbnew/pcb_io/altium/altium_pcb.cpp @@ -4109,8 +4109,8 @@ void ALTIUM_PCB::ConvertFills6ToBoardItem( const AFILL6& aElem ) if( aElem.rotation != 0. ) { - VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2, - ( aElem.pos1.y + aElem.pos2.y ) / 2 ); + VECTOR2I center( aElem.pos1.x / 2 + aElem.pos2.x / 2, + aElem.pos1.y / 2 + aElem.pos2.y / 2 ); shape.Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) ); } @@ -4140,8 +4140,8 @@ void ALTIUM_PCB::ConvertFills6ToFootprintItem( FOOTPRINT* aFootprint, const AFIL if( aElem.rotation != 0. ) { - VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2, - ( aElem.pos1.y + aElem.pos2.y ) / 2 ); + VECTOR2I center( aElem.pos1.x / 2 + aElem.pos2.x / 2, + aElem.pos1.y / 2 + aElem.pos2.y / 2 ); shape.Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) ); } @@ -4182,7 +4182,8 @@ void ALTIUM_PCB::ConvertFills6ToBoardItemOnLayer( const AFILL6& aElem, PCB_LAYER if( aElem.rotation != 0. ) { // TODO: Do we need SHAPE_T::POLY for non 90° rotations? - VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2, ( aElem.pos1.y + aElem.pos2.y ) / 2 ); + VECTOR2I center( aElem.pos1.x / 2 + aElem.pos2.x / 2, + aElem.pos1.y / 2 + aElem.pos2.y / 2 ); fill->Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) ); } @@ -4205,7 +4206,8 @@ void ALTIUM_PCB::ConvertFills6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con if( aElem.rotation != 0. ) { // TODO: Do we need SHAPE_T::POLY for non 90° rotations? - VECTOR2I center( ( aElem.pos1.x + aElem.pos2.x ) / 2, ( aElem.pos1.y + aElem.pos2.y ) / 2 ); + VECTOR2I center( aElem.pos1.x / 2 + aElem.pos2.x / 2, + aElem.pos1.y / 2 + aElem.pos2.y / 2 ); fill->Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) ); }