From d2d582cc001cb097826804806cbb3e5da25bb301 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 5 Sep 2025 10:03:44 +0200 Subject: [PATCH] PCB_DIM_CENTER: fix incorrect bounding box size for 90deg cross. Fixes https://gitlab.com/kicad/code/kicad/-/issues/21643 From master branch --- pcbnew/pcb_dimension.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index b3aacd38a0..53d0a7499b 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -1715,14 +1715,29 @@ BITMAPS PCB_DIM_CENTER::GetMenuImage() const const BOX2I PCB_DIM_CENTER::GetBoundingBox() const { - int halfWidth = VECTOR2I( m_end - m_start ).x + ( m_lineThickness / 2.0 ); - BOX2I bBox; + int xmin, xmax, ymin, ymax; - bBox.SetX( m_start.x - halfWidth ); - bBox.SetY( m_start.y - halfWidth ); - bBox.SetWidth( halfWidth * 2 ); - bBox.SetHeight( halfWidth * 2 ); + xmin = m_start.x; + xmax = m_start.x; + ymin = m_start.y; + ymax = m_start.y; + + for( const std::shared_ptr& shape : GetShapes() ) + { + BOX2I shapeBox = shape->BBox(); + shapeBox.Inflate( m_lineThickness / 2 ); + + xmin = std::min( xmin, shapeBox.GetOrigin().x ); + xmax = std::max( xmax, shapeBox.GetEnd().x ); + ymin = std::min( ymin, shapeBox.GetOrigin().y ); + ymax = std::max( ymax, shapeBox.GetEnd().y ); + } + + bBox.SetX( xmin ); + bBox.SetY( ymin ); + bBox.SetWidth( xmax - xmin + 1 ); + bBox.SetHeight( ymax - ymin + 1 ); bBox.Normalize(); @@ -1732,8 +1747,7 @@ const BOX2I PCB_DIM_CENTER::GetBoundingBox() const const BOX2I PCB_DIM_CENTER::ViewBBox() const { - return BOX2I( VECTOR2I( GetBoundingBox().GetPosition() ), - VECTOR2I( GetBoundingBox().GetSize() ) ); + return GetBoundingBox(); }