From b165240118f286ed84bec4a7df331c25259f1de9 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 12 Jul 2025 11:54:05 -0700 Subject: [PATCH] Optimize zone-zone checks in filler Teardrops are calculated as zones, so when we create a board with thousands of teardrops, we don't want to run O(n^2) checks on the clearance between multiple teardrops. Instead, we can check only the clearance where the two zones have the potential to interact Fixes https://gitlab.com/kicad/code/kicad/-/issues/21226 --- pcbnew/zone_filler.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index d2bb61ffb1..5a106dad0d 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -1563,6 +1563,10 @@ void ZONE_FILLER::buildCopperItemClearances( const ZONE* aZone, PCB_LAYER_ID aLa if( checkForCancel( m_progressReporter ) ) return; + // Only check zones whose bounding box overlaps the max clearance + if( !otherZone->GetBoundingBox().Intersects( zone_boundingbox ) ) + continue; + // Negative clearance permits zones to short if( evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, otherZone, aLayer ) < 0 ) continue; @@ -1586,6 +1590,10 @@ void ZONE_FILLER::buildCopperItemClearances( const ZONE* aZone, PCB_LAYER_ID aLa if( checkForCancel( m_progressReporter ) ) return; + // Only check zones whose bounding box overlaps + if( !otherZone->GetBoundingBox().Intersects( zone_boundingbox ) ) + continue; + if( otherZone->GetIsRuleArea() ) { if( otherZone->GetDoNotAllowZoneFills() && !aZone->IsTeardropArea() )