From 5f10c15a876568b0cef0fdee6baa66d12b672518 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 29 Apr 2022 18:29:28 +0100 Subject: [PATCH] Fix zone merge intersection algorithm. Fixes https://gitlab.com/kicad/code/kicad/issues/11492 --- pcbnew/tools/board_editor_control.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 7cc6428405..12587dc466 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -1465,7 +1465,18 @@ int BOARD_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) continue; } - if( !board->TestZoneIntersection( curr_area, firstZone ) ) + bool intersects = curr_area == firstZone; + + for( ZONE* candidate : toMerge ) + { + if( intersects ) + break; + + if( board->TestZoneIntersection( curr_area, candidate ) ) + intersects = true; + } + + if( !intersects ) { wxLogMessage( _( "Some zones did not intersect and were not merged." ) ); continue; @@ -1476,12 +1487,15 @@ int BOARD_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - if( mergeZones( m_frame, commit, toMerge, merged ) ) + if( !toMerge.empty() ) { - commit.Push( wxT( "Merge zones" ) ); + if( mergeZones( m_frame, commit, toMerge, merged ) ) + { + commit.Push( wxT( "Merge zones" ) ); - for( EDA_ITEM* item : merged ) - m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, item ); + for( EDA_ITEM* item : merged ) + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, item ); + } } return 0;