KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_zone_filler.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <boost/test/data/test_case.hpp>
22
23#include <chrono>
24
26#include <board.h>
27#include <board_commit.h>
28#include <zone_filler.h>
30#include <drc/drc_engine.h>
31#include <pad.h>
32#include <pcb_track.h>
33#include <footprint.h>
34#include <zone.h>
35#include <drc/drc_engine.h>
36#include <drc/drc_item.h>
39#include <advanced_config.h>
41#include <teardrop/teardrop.h>
43#include <netclass.h>
44#include <netinfo.h>
45#include <cmath>
46
47
50static void CheckAllOutlineAreasAtLeast( const std::shared_ptr<SHAPE_POLY_SET>& aFill,
51 double aMinArea, const wxString& aLabel )
52{
53 for( int ii = 0; ii < aFill->OutlineCount(); ++ii )
54 {
55 const double area = std::abs( aFill->Outline( ii ).Area() );
56
57 BOOST_CHECK_MESSAGE( area >= aMinArea,
58 wxString::Format( "%s %d area %.0f IU^2 below %.0f IU^2; partial "
59 "stamps should not survive.",
60 aLabel, ii, area, aMinArea ) );
61 }
62}
63
64
73
74
75int delta = KiROUND( 0.006 * pcbIUScale.IU_PER_MM );
76
77
79{
80 KI_TEST::LoadBoard( m_settingsManager, "zone_filler", m_board );
81
82 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
83
84 KI_TEST::FillZones( m_board.get() );
85
86 // Now that the zones are filled we're going to increase the size of -some- pads and
87 // tracks so that they generate DRC errors. The test then makes sure that those errors
88 // are generated, and that the other pads and tracks do -not- generate errors.
89
90 for( PAD* pad : m_board->Footprints()[0]->Pads() )
91 {
92 if( pad->GetNumber() == "2" || pad->GetNumber() == "4" || pad->GetNumber() == "6" )
93 {
94 pad->SetSize( PADSTACK::ALL_LAYERS,
95 pad->GetSize( PADSTACK::ALL_LAYERS ) + VECTOR2I( delta, delta ) );
96 }
97 }
98
99 int ii = 0;
100 KIID arc8;
101 KIID arc12;
102
103 for( PCB_TRACK* track : m_board->Tracks() )
104 {
105 if( track->Type() == PCB_ARC_T )
106 {
107 ii++;
108
109 if( ii == 8 )
110 {
111 arc8 = track->m_Uuid;
112 track->SetWidth( track->GetWidth() + delta + delta );
113 }
114 else if( ii == 12 )
115 {
116 arc12 = track->m_Uuid;
117 track->Move( VECTOR2I( -delta, -delta ) );
118 }
119 }
120 }
121
122 bool foundPad2Error = false;
123 bool foundPad4Error = false;
124 bool foundPad6Error = false;
125 bool foundArc8Error = false;
126 bool foundArc12Error = false;
127 bool foundOtherError = false;
128
129 bds.m_DRCEngine->InitEngine( wxFileName() ); // Just to be sure to be sure
130
132 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
133 const std::function<void( PCB_MARKER* )>& aPathGenerator )
134 {
135 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
136 {
137 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
138 PAD* pad_a = dynamic_cast<PAD*>( item_a );
139 PCB_TRACK* trk_a = dynamic_cast<PCB_TRACK*>( item_a );
140
141 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
142 PAD* pad_b = dynamic_cast<PAD*>( item_b );
143 PCB_TRACK* trk_b = dynamic_cast<PCB_TRACK*>( item_b );
144
145 if( pad_a && pad_a->GetNumber() == "2" ) foundPad2Error = true;
146 else if( pad_a && pad_a->GetNumber() == "4" ) foundPad4Error = true;
147 else if( pad_a && pad_a->GetNumber() == "6" ) foundPad6Error = true;
148 else if( pad_b && pad_b->GetNumber() == "2" ) foundPad2Error = true;
149 else if( pad_b && pad_b->GetNumber() == "4" ) foundPad4Error = true;
150 else if( pad_b && pad_b->GetNumber() == "6" ) foundPad6Error = true;
151 else if( trk_a && trk_a->m_Uuid == arc8 ) foundArc8Error = true;
152 else if( trk_a && trk_a->m_Uuid == arc12 ) foundArc12Error = true;
153 else if( trk_b && trk_b->m_Uuid == arc8 ) foundArc8Error = true;
154 else if( trk_b && trk_b->m_Uuid == arc12 ) foundArc12Error = true;
155 else foundOtherError = true;
156
157 }
158 } );
159
160 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
161
162 BOOST_CHECK_EQUAL( foundPad2Error, true );
163 BOOST_CHECK_EQUAL( foundPad4Error, true );
164 BOOST_CHECK_EQUAL( foundPad6Error, true );
165 BOOST_CHECK_EQUAL( foundArc8Error, true );
166 BOOST_CHECK_EQUAL( foundArc12Error, true );
167 BOOST_CHECK_EQUAL( foundOtherError, false );
168}
169
170
172{
173 KI_TEST::LoadBoard( m_settingsManager, "notched_zones", m_board );
174
175 // Older algorithms had trouble where the filleted zones intersected and left notches.
176 // See:
177 // https://gitlab.com/kicad/code/kicad/-/issues/2737
178 // https://gitlab.com/kicad/code/kicad/-/issues/2752
179 SHAPE_POLY_SET frontCopper;
180
181 KI_TEST::FillZones( m_board.get() );
182
183 frontCopper = SHAPE_POLY_SET();
184
185 for( ZONE* zone : m_board->Zones() )
186 {
187 if( zone->GetLayerSet().Contains( F_Cu ) )
188 {
189 frontCopper.BooleanAdd( *zone->GetFilledPolysList( F_Cu ) );
190 }
191 }
192
193 BOOST_CHECK_EQUAL( frontCopper.OutlineCount(), 2 );
194}
195
196
197static const std::vector<wxString> RegressionZoneFillTests_tests = {
198 "issue18",
199 "issue2568",
200 "issue3812",
201 "issue5102",
202 "issue5313",
203 "issue5320",
204 "issue5567",
205 "issue5830",
206 "issue6039",
207 "issue6260",
208 "issue6284",
209 "issue7086",
210 "issue14294", // Bad Clipper2 fill
211 "fill_bad" // Missing zone clearance expansion
212};
213
214
216 boost::unit_test::data::make( RegressionZoneFillTests_tests ), relPath )
217{
218 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
219
220 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
221
222 KI_TEST::FillZones( m_board.get() );
223
224 std::vector<DRC_ITEM> violations;
225
227 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
228 const std::function<void( PCB_MARKER* )>& aPathGenerator )
229 {
230 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
231 violations.push_back( *aItem );
232 } );
233
234 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
235
236 if( violations.empty() )
237 {
238 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
239 BOOST_TEST_MESSAGE( wxString::Format( "Zone fill regression: %s passed", relPath ) );
240 }
241 else
242 {
243 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
244
245 std::map<KIID, EDA_ITEM*> itemMap;
246 m_board->FillItemMap( itemMap );
247
248 for( const DRC_ITEM& item : violations )
249 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
250
251 BOOST_ERROR( wxString::Format( "Zone fill regression: %s failed", relPath ) );
252 }
253}
254
255
265BOOST_FIXTURE_TEST_CASE( RegressionZoneClearanceWithIterativeRefill, ZONE_FILL_TEST_FIXTURE )
266{
267 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
268 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
269
270 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
271 guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
272
273 auto runDrcClearanceCheck =
274 [this]( bool aIterative ) -> int
275 {
276 ADVANCED_CFG& innerCfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
277 innerCfg.m_ZoneFillIterativeRefill = aIterative;
278
279 KI_TEST::LoadBoard( m_settingsManager, "issue23053/issue23053", m_board );
280
281 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
282
283 KI_TEST::FillZones( m_board.get() );
284
285 std::vector<DRC_ITEM> violations;
286
287 std::map<KIID, EDA_ITEM*> itemMap;
288 m_board->FillItemMap( itemMap );
289 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
290
292 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos,
293 int aLayer,
294 const std::function<void( PCB_MARKER* )>& aPathGenerator )
295 {
296 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
297 {
298 BOARD_ITEM* itemA = m_board->ResolveItem( aItem->GetMainItemID() );
299 BOARD_ITEM* itemB = m_board->ResolveItem( aItem->GetAuxItemID() );
300
301 if( dynamic_cast<ZONE*>( itemA ) && dynamic_cast<ZONE*>( itemB ) )
302 {
303 violations.push_back( *aItem );
304
306 aItem->ShowReport( &unitsProvider,
307 RPT_SEVERITY_ERROR, itemMap ) );
308 }
309 }
310 } );
311
312 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
313
314 return static_cast<int>( violations.size() );
315 };
316
317 int iterativeViolations = runDrcClearanceCheck( true );
318
319 BOOST_CHECK_MESSAGE( iterativeViolations == 0,
320 wxString::Format( "Iterative refill produced %d zone-to-zone clearance "
321 "violations (expected 0)", iterativeViolations ) );
322
323 int nonIterativeViolations = runDrcClearanceCheck( false );
324
325 BOOST_CHECK_MESSAGE( nonIterativeViolations == 0,
326 wxString::Format( "Non-iterative refill produced %d zone-to-zone clearance "
327 "violations (expected 0)", nonIterativeViolations ) );
328}
329
330
331static const std::vector<wxString> RegressionSliverZoneFillTests_tests = {
332 "issue16182" // Slivers
333};
334
335
336BOOST_DATA_TEST_CASE_F( ZONE_FILL_TEST_FIXTURE, RegressionSliverZoneFillTests,
337 boost::unit_test::data::make( RegressionSliverZoneFillTests_tests ),
338 relPath )
339{
340 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
341
342 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
343
344 KI_TEST::FillZones( m_board.get() );
345
346 std::vector<DRC_ITEM> violations;
347
349 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
350 const std::function<void( PCB_MARKER* )>& aPathGenerator )
351 {
352 if( aItem->GetErrorCode() == DRCE_COPPER_SLIVER )
353 violations.push_back( *aItem );
354 } );
355
356 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
357
358 if( violations.empty() )
359 {
360 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
361 BOOST_TEST_MESSAGE( wxString::Format( "Zone fill copper sliver regression: %s passed", relPath ) );
362 }
363 else
364 {
365 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
366
367 std::map<KIID, EDA_ITEM*> itemMap;
368 m_board->FillItemMap( itemMap );
369
370 for( const DRC_ITEM& item : violations )
371 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
372
373 BOOST_ERROR( wxString::Format( "Zone fill copper sliver regression: %s failed", relPath ) );
374 }
375}
376
377
378static const std::vector<std::pair<wxString,int>> RegressionTeardropFill_tests = {
379 { "teardrop_issue_JPC2", 5 }, // Arcs with teardrops connecting to pads
380};
381
382
384 boost::unit_test::data::make( RegressionTeardropFill_tests ), test )
385{
386 const wxString& relPath = test.first;
387 const int count = test.second;
388
389 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
390
391 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
392
393 KI_TEST::FillZones( m_board.get() );
394
395 int zoneCount = 0;
396
397 for( ZONE* zone : m_board->Zones() )
398 {
399 if( zone->IsTeardropArea() )
400 zoneCount++;
401 }
402
403 BOOST_CHECK_MESSAGE( zoneCount == count, "Expected " << count << " teardrop zones in "
404 << relPath << ", found "
405 << zoneCount );
406}
407
408
410{
411
412 std::vector<wxString> tests = { { "issue19956/issue19956" } // Arcs with teardrops connecting to pads
413 };
414
415 for( const wxString& relPath : tests )
416 {
417 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
418 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
419 KI_TEST::FillZones( m_board.get() );
420
421 for( ZONE* zone : m_board->Zones() )
422 {
423 for( PCB_LAYER_ID layer : zone->GetLayerSet() )
424 {
425 std::shared_ptr<SHAPE> a_shape( zone->GetEffectiveShape( layer ) );
426
427 for( PAD* pad : m_board->GetPads() )
428 {
429 std::shared_ptr<SHAPE> pad_shape( pad->GetEffectiveShape( layer ) );
430 int clearance = pad_shape->GetClearance( a_shape.get() );
431 BOOST_CHECK_MESSAGE( pad->GetNetCode() == zone->GetNetCode() || clearance != 0,
432 wxString::Format( "Pad %s from Footprint %s has net code %s and "
433 "is connected to zone with net code %s",
434 pad->GetNumber(),
435 pad->GetParentFootprint()->GetReferenceAsString(),
436 pad->GetNetname(),
437 zone->GetNetname() ) );
438 }
439 }
440 }
441 }
442}
443
444
459BOOST_FIXTURE_TEST_CASE( RegressionZonePriorityIsolatedIslands, ZONE_FILL_TEST_FIXTURE )
460{
461 // Enable iterative refill to fix issue 21746
462 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
463 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
464 cfg.m_ZoneFillIterativeRefill = true;
465
466 // Restore config at end of scope to avoid polluting other tests
467 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } } guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
468
469 KI_TEST::LoadBoard( m_settingsManager, "issue21746/issue21746", m_board );
470
471 KI_TEST::FillZones( m_board.get() );
472
473 // Find the GND zone
474 ZONE* gndZone = nullptr;
475
476 for( ZONE* zone : m_board->Zones() )
477 {
478 if( zone->GetNetname() == "GND" )
479 {
480 gndZone = zone;
481 break;
482 }
483 }
484
485 BOOST_REQUIRE_MESSAGE( gndZone != nullptr, "GND zone not found in test board" );
486
487 // Calculate board outline area
488 SHAPE_POLY_SET boardOutline;
489 bool hasOutline = m_board->GetBoardPolygonOutlines( boardOutline, true );
490 BOOST_REQUIRE_MESSAGE( hasOutline, "Board outline not found" );
491
492 double boardArea = 0.0;
493
494 for( int i = 0; i < boardOutline.OutlineCount(); i++ )
495 boardArea += boardOutline.Outline( i ).Area();
496
497 // Get GND zone filled area
498 gndZone->CalculateFilledArea();
499 double gndFilledArea = gndZone->GetFilledArea();
500
501 // The GND zone should fill at least 25% of the board area
502 // With the bug, it fills almost nothing because VDD knocks it out
503 double fillRatio = gndFilledArea / boardArea;
504
505 BOOST_TEST_MESSAGE( wxString::Format( "Board area: %.2f sq mm, GND filled area: %.2f sq mm, "
506 "Fill ratio: %.1f%%",
507 boardArea / 1e6, gndFilledArea / 1e6,
508 fillRatio * 100.0 ) );
509
510 BOOST_CHECK_MESSAGE( fillRatio >= 0.25,
511 wxString::Format( "GND zone fill ratio %.1f%% is less than expected 25%%. "
512 "This indicates issue 21746 - lower priority zones not "
513 "filling areas where higher priority isolated islands "
514 "were removed.",
515 fillRatio * 100.0 ) );
516}
517
518
532BOOST_FIXTURE_TEST_CASE( RegressionViaFlashingUnreachableZone, ZONE_FILL_TEST_FIXTURE )
533{
534 KI_TEST::LoadBoard( m_settingsManager, "issue22010/issue22010", m_board );
535
536 KI_TEST::FillZones( m_board.get() );
537
538 // Find vias with zone_layer_connections set for In1.Cu or In2.Cu
539 // After filling, vias that the zone doesn't actually reach should NOT be flashed
540 int viasWithUnreachableFlashing = 0;
541 int totalConditionalVias = 0;
542
543 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT( "In1.Cu" ) );
544 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT( "In2.Cu" ) );
545
546 for( PCB_TRACK* track : m_board->Tracks() )
547 {
548 if( track->Type() != PCB_VIA_T )
549 continue;
550
551 PCB_VIA* via = static_cast<PCB_VIA*>( track );
552
553 if( !via->GetRemoveUnconnected() )
554 continue;
555
556 totalConditionalVias++;
557
558 // Check if via is flashed on In1.Cu or In2.Cu
559 bool flashedOnIn1 = via->FlashLayer( in1Cu );
560 bool flashedOnIn2 = via->FlashLayer( in2Cu );
561
562 if( !flashedOnIn1 && !flashedOnIn2 )
563 continue;
564
565 VECTOR2I viaCenter = via->GetPosition();
566 int holeRadius = via->GetDrillValue() / 2;
567
568 // Check if any zone fill actually reaches this via
569 bool zoneReachesVia = false;
570
571 for( ZONE* zone : m_board->Zones() )
572 {
573 if( zone->GetIsRuleArea() )
574 continue;
575
576 if( zone->GetNetCode() != via->GetNetCode() )
577 continue;
578
579 for( PCB_LAYER_ID layer : { in1Cu, in2Cu } )
580 {
581 if( !zone->IsOnLayer( layer ) )
582 continue;
583
584 if( !zone->HasFilledPolysForLayer( layer ) )
585 continue;
586
587 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
588
589 if( fill->Contains( viaCenter, -1, holeRadius ) )
590 {
591 zoneReachesVia = true;
592 break;
593 }
594 }
595
596 if( zoneReachesVia )
597 break;
598 }
599
600 // If via is flashed but zone doesn't reach it, that's the bug
601 if( !zoneReachesVia && ( flashedOnIn1 || flashedOnIn2 ) )
602 viasWithUnreachableFlashing++;
603 }
604
605 BOOST_TEST_MESSAGE( wxString::Format( "Total conditional vias: %d, Vias with unreachable "
606 "flashing: %d", totalConditionalVias,
607 viasWithUnreachableFlashing ) );
608
609 BOOST_CHECK_MESSAGE( viasWithUnreachableFlashing == 0,
610 wxString::Format( "Found %d vias flashed on zone layers where the zone "
611 "fill doesn't actually reach them. This indicates "
612 "issue 22010 is not fixed.",
613 viasWithUnreachableFlashing ) );
614}
615
616
630{
631 KI_TEST::LoadBoard( m_settingsManager, "issue12964/issue12964", m_board );
632
633 KI_TEST::FillZones( m_board.get() );
634
635 int viasShortingZones = 0;
636 int totalConditionalVias = 0;
637
638 for( PCB_TRACK* track : m_board->Tracks() )
639 {
640 if( track->Type() != PCB_VIA_T )
641 continue;
642
643 PCB_VIA* via = static_cast<PCB_VIA*>( track );
644
645 if( !via->GetRemoveUnconnected() )
646 continue;
647
648 totalConditionalVias++;
649
650 VECTOR2I viaCenter = via->GetPosition();
651
652 for( ZONE* zone : m_board->Zones() )
653 {
654 if( zone->GetIsRuleArea() )
655 continue;
656
657 if( zone->GetNetCode() == via->GetNetCode() )
658 continue;
659
660 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
661 {
662 if( !via->FlashLayer( layer ) )
663 continue;
664
665 if( !zone->HasFilledPolysForLayer( layer ) )
666 continue;
667
668 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
669 int viaRadius = via->GetWidth( layer ) / 2;
670
671 if( fill->Contains( viaCenter, -1, viaRadius ) )
672 {
673 BOOST_TEST_MESSAGE( wxString::Format(
674 "Via at (%d, %d) on net %s is flashing on layer %s where zone "
675 "net %s is filled - this creates a short!",
676 viaCenter.x, viaCenter.y, via->GetNetname(),
677 m_board->GetLayerName( layer ), zone->GetNetname() ) );
678 viasShortingZones++;
679 }
680 }
681 }
682 }
683
684 BOOST_TEST_MESSAGE( wxString::Format( "Total conditional vias: %d, Vias shorting zones: %d",
685 totalConditionalVias, viasShortingZones ) );
686
687 BOOST_CHECK_MESSAGE( viasShortingZones == 0,
688 wxString::Format( "Found %d vias flashed on layers where they short to "
689 "zones with different nets. This indicates issue 12964 "
690 "is not fixed.",
691 viasShortingZones ) );
692}
693
694
707BOOST_FIXTURE_TEST_CASE( HatchZoneThermalConnectivity, ZONE_FILL_TEST_FIXTURE )
708{
709 KI_TEST::LoadBoard( m_settingsManager, "hatch_thermal_connectivity/hatch_thermal_connectivity",
710 m_board );
711
712 KI_TEST::FillZones( m_board.get() );
713
714 m_board->BuildConnectivity();
715
716 int unconnectedCount = m_board->GetConnectivity()->GetUnconnectedCount( false );
717
718 BOOST_CHECK_MESSAGE( unconnectedCount == 0,
719 wxString::Format( "Found %d unconnected items after zone fill. "
720 "Hatch zone thermal reliefs should maintain connectivity "
721 "even with large hatch gaps.",
722 unconnectedCount ) );
723}
724
725
742BOOST_FIXTURE_TEST_CASE( RegressionShallowArcZoneFill, ZONE_FILL_TEST_FIXTURE )
743{
744 KI_TEST::LoadBoard( m_settingsManager, "issue22475/issue22475", m_board );
745
746 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT( "In1.Cu" ) );
747
748 ZONE* gndZone = nullptr;
749
750 for( ZONE* zone : m_board->Zones() )
751 {
752 if( zone->GetNetname() == "GND" && zone->IsOnLayer( in1Cu ) )
753 {
754 gndZone = zone;
755 break;
756 }
757 }
758
759 BOOST_REQUIRE_MESSAGE( gndZone != nullptr, "GND zone on In1.Cu not found in test board" );
760
761 if( !gndZone )
762 return;
763
764 KI_TEST::FillZones( m_board.get() );
765
766 BOOST_REQUIRE_MESSAGE( gndZone->HasFilledPolysForLayer( in1Cu ),
767 "GND zone has no fill on In1.Cu" );
768
769 const std::shared_ptr<SHAPE_POLY_SET>& fill = gndZone->GetFilledPolysList( in1Cu );
770
771 // The zone fill should produce a single contiguous outline. Multiple outlines
772 // indicate disconnected fill areas caused by malformed clearance holes.
773 BOOST_CHECK_EQUAL( fill->OutlineCount(), 1 );
774
775 double zoneOutlineArea = gndZone->Outline()->Area();
776
777 BOOST_REQUIRE_MESSAGE( zoneOutlineArea > 0.0, "Zone outline area must be positive" );
778
779 double fillArea = 0.0;
780
781 for( int i = 0; i < fill->OutlineCount(); i++ )
782 fillArea += std::abs( fill->Outline( i ).Area() );
783
784 double fillRatio = fillArea / zoneOutlineArea;
785
786 // The zone should be mostly filled. A low fill ratio indicates excessive voids
787 // from malformed clearance holes around shallow arcs.
788 BOOST_CHECK_GE( fillRatio, 0.90 );
789}
790
791
804BOOST_FIXTURE_TEST_CASE( RegressionIterativeRefillRespectsKeepouts, ZONE_FILL_TEST_FIXTURE )
805{
806 // Enable iterative refill
807 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
808 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
809 cfg.m_ZoneFillIterativeRefill = true;
810
811 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
812 guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
813
814 KI_TEST::LoadBoard( m_settingsManager, "issue22809/issue22809", m_board );
815
816 KI_TEST::FillZones( m_board.get() );
817
818 // Find all zone keepouts
819 std::vector<ZONE*> keepouts;
820
821 for( ZONE* zone : m_board->Zones() )
822 {
823 if( zone->GetIsRuleArea() && zone->GetDoNotAllowZoneFills() )
824 keepouts.push_back( zone );
825 }
826
827 BOOST_REQUIRE_MESSAGE( !keepouts.empty(), "No zone keepouts found in test board" );
828
829 // For each keepout, check that no zone fill exists inside it
830 int violationCount = 0;
831
832 for( ZONE* keepout : keepouts )
833 {
834 for( PCB_LAYER_ID layer : keepout->GetLayerSet().Seq() )
835 {
836 SHAPE_POLY_SET keepoutOutline( *keepout->Outline() );
837 keepoutOutline.ClearArcs();
838
839 for( ZONE* zone : m_board->Zones() )
840 {
841 if( zone->GetIsRuleArea() )
842 continue;
843
844 if( !zone->IsOnLayer( layer ) )
845 continue;
846
847 if( !zone->HasFilledPolysForLayer( layer ) )
848 continue;
849
850 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
851
852 // Check if any fill intersects the keepout
853 SHAPE_POLY_SET intersection = *fill;
854 intersection.BooleanIntersection( keepoutOutline );
855
856 if( intersection.OutlineCount() > 0 )
857 {
858 double intersectionArea = 0;
859
860 for( int i = 0; i < intersection.OutlineCount(); i++ )
861 intersectionArea += std::abs( intersection.Outline( i ).Area() );
862
863 // Allow for small numerical errors (less than 1 square mm)
864 if( intersectionArea > 1e6 )
865 {
866 BOOST_TEST_MESSAGE( wxString::Format(
867 "Zone %s fill on layer %s overlaps keepout by %.2f sq mm",
868 zone->GetNetname(),
869 m_board->GetLayerName( layer ),
870 intersectionArea / 1e6 ) );
871 violationCount++;
872 }
873 }
874 }
875 }
876 }
877
878 BOOST_CHECK_MESSAGE( violationCount == 0,
879 wxString::Format( "Found %d zone fills overlapping keepout areas. "
880 "This indicates issue 22809 - iterative refiller "
881 "ignores zone keepouts.", violationCount ) );
882}
883
884
898BOOST_FIXTURE_TEST_CASE( RegressionTHPadInnerLayerFlashing, ZONE_FILL_TEST_FIXTURE )
899{
900 KI_TEST::LoadBoard( m_settingsManager, "issue22826/issue22826", m_board );
901
902 KI_TEST::FillZones( m_board.get() );
903
904 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT( "In2.Cu" ) );
905 int padsWithMissingFlashing = 0;
906 int totalConditionalPads = 0;
907
908 for( FOOTPRINT* footprint : m_board->Footprints() )
909 {
910 for( PAD* pad : footprint->Pads() )
911 {
912 if( !pad->GetRemoveUnconnected() )
913 continue;
914
915 if( !pad->HasHole() )
916 continue;
917
918 if( pad->GetNetname() != "VBUS_DUT" && pad->GetNetname() != "VBUS_DBG" )
919 continue;
920
921 totalConditionalPads++;
922
923 // Check if the pad should flash on In2.Cu
924 bool shouldFlash = false;
925
926 for( ZONE* zone : m_board->Zones() )
927 {
928 if( zone->GetIsRuleArea() )
929 continue;
930
931 if( zone->GetNetCode() != pad->GetNetCode() )
932 continue;
933
934 if( !zone->IsOnLayer( in2Cu ) )
935 continue;
936
937 if( zone->Outline()->Contains( pad->GetPosition() ) )
938 {
939 shouldFlash = true;
940 break;
941 }
942 }
943
944 if( shouldFlash && !pad->FlashLayer( in2Cu ) )
945 {
946 BOOST_TEST_MESSAGE( wxString::Format(
947 "Pad %s at (%d, %d) on net %s is inside zone but not flashing on In2.Cu",
948 pad->GetNumber(), pad->GetPosition().x, pad->GetPosition().y,
949 pad->GetNetname() ) );
950 padsWithMissingFlashing++;
951 }
952 }
953 }
954
955 BOOST_TEST_MESSAGE( wxString::Format( "Total conditional pads: %d, Pads with missing "
956 "flashing: %d", totalConditionalPads,
957 padsWithMissingFlashing ) );
958
959 BOOST_CHECK_MESSAGE( padsWithMissingFlashing == 0,
960 wxString::Format( "Found %d TH pads that should flash on inner layers "
961 "but don't. This indicates issue 22826 is not fixed.",
962 padsWithMissingFlashing ) );
963}
964
965
974BOOST_FIXTURE_TEST_CASE( RegressionRoundRectTeardropGeometry, ZONE_FILL_TEST_FIXTURE )
975{
976 KI_TEST::LoadBoard( m_settingsManager, "issue19405_roundrect_teardrop", m_board );
977
978 // Set up tool manager for teardrop generation
979 TOOL_MANAGER toolMgr;
980 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
981
982 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
983 toolMgr.RegisterTool( dummyTool );
984
985 // Generate teardrops
986 BOARD_COMMIT commit( dummyTool );
987 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
988 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
989
990 if( !commit.Empty() )
991 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
992
993 // Find teardrop zones
994 int teardropCount = 0;
995 bool foundBadTeardrop = false;
996
997 for( ZONE* zone : m_board->Zones() )
998 {
999 if( !zone->IsTeardropArea() )
1000 continue;
1001
1002 teardropCount++;
1003
1004 // Get the teardrop outline
1005 const SHAPE_POLY_SET* outline = zone->Outline();
1006
1007 if( !outline || outline->OutlineCount() == 0 )
1008 continue;
1009
1010 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
1011
1012 // Check that the teardrop polygon is convex or at least doesn't have
1013 // any sharp concave angles that would indicate intersection with the pad corner.
1014 // A well-formed teardrop should have all turns in the same direction
1015 // (or very close to it) except at the pad anchor points.
1016 int concaveCount = 0;
1017
1018 for( int i = 0; i < chain.PointCount(); i++ )
1019 {
1020 int prev = ( i == 0 ) ? chain.PointCount() - 1 : i - 1;
1021 int next = ( i + 1 ) % chain.PointCount();
1022
1023 VECTOR2I v1 = chain.CPoint( i ) - chain.CPoint( prev );
1024 VECTOR2I v2 = chain.CPoint( next ) - chain.CPoint( i );
1025
1026 // Cross product gives handedness of turn
1027 int64_t cross = (int64_t) v1.x * v2.y - (int64_t) v1.y * v2.x;
1028
1029 // Count significant concave turns (negative cross product for CCW polygons)
1030 // Small values are numerical noise
1031 if( cross < -1000 )
1032 concaveCount++;
1033 }
1034
1035 // A teardrop should have at most 2-3 concave points (at the pad anchor points)
1036 // Many concave points indicate the curve is intersecting the pad corner
1037 if( concaveCount > 5 )
1038 {
1039 BOOST_TEST_MESSAGE( wxString::Format( "Teardrop has %d concave vertices, "
1040 "indicating possible corner intersection",
1041 concaveCount ) );
1042 foundBadTeardrop = true;
1043 }
1044 }
1045
1046 BOOST_CHECK_MESSAGE( teardropCount > 0, "Expected at least one teardrop zone" );
1047
1048 BOOST_CHECK_MESSAGE( !foundBadTeardrop,
1049 "Found teardrop with excessive concave vertices, indicating "
1050 "issue 19405 - teardrop curve intersecting rounded rectangle corner" );
1051}
1052
1053
1060{
1061 KI_TEST::LoadBoard( m_settingsManager, "teardrop_spike", m_board );
1062
1063 TOOL_MANAGER toolMgr;
1064 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
1065
1066 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
1067 toolMgr.RegisterTool( dummyTool );
1068
1069 BOARD_COMMIT commit( dummyTool );
1070 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
1071 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
1072
1073 if( !commit.Empty() )
1074 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
1075
1076 int teardropCount = 0;
1077 bool foundSpike = false;
1078
1079 const int maxError = m_board->GetDesignSettings().m_MaxError;
1080
1081 for( ZONE* zone : m_board->Zones() )
1082 {
1083 if( !zone->IsTeardropArea() )
1084 continue;
1085
1086 teardropCount++;
1087
1088 PCB_LAYER_ID layer = zone->GetFirstLayer();
1089 int netcode = zone->GetNetCode();
1090
1091 // A well-formed teardrop only ever covers the copper it bridges: the pads/vias it
1092 // anchors on and the track(s) it follows. Build that corridor from all copper on the
1093 // teardrop's net and layer (generously inflated) and require the teardrop to lie
1094 // inside it. A spike sweeps area outside the corridor.
1095 SHAPE_POLY_SET corridor;
1096
1097 for( FOOTPRINT* fp : m_board->Footprints() )
1098 {
1099 for( PAD* pad : fp->Pads() )
1100 {
1101 if( pad->GetNetCode() == netcode && pad->IsOnLayer( layer ) )
1102 pad->TransformShapeToPolygon( corridor, layer, 0, maxError, ERROR_OUTSIDE );
1103 }
1104 }
1105
1106 for( PCB_TRACK* track : m_board->Tracks() )
1107 {
1108 if( track->GetNetCode() == netcode && track->IsOnLayer( layer ) )
1109 track->TransformShapeToPolygon( corridor, layer, 0, maxError, ERROR_OUTSIDE );
1110 }
1111
1112 // Inflate by a full track width so the teardrop's flare toward the pad, which is
1113 // legitimately wider than the bare track, is comfortably inside the corridor.
1114 corridor.Inflate( pcbIUScale.mmToIU( 0.127 ), CORNER_STRATEGY::ROUND_ALL_CORNERS,
1115 maxError );
1116 corridor.Simplify();
1117
1118 SHAPE_POLY_SET outside = *zone->Outline();
1119 outside.BooleanSubtract( corridor );
1120
1121 double tdArea = std::abs( zone->Outline()->Area() );
1122 double outArea = std::abs( outside.Area() );
1123 double ratio = tdArea > 0 ? outArea / tdArea : 0.0;
1124
1125 BOOST_TEST_MESSAGE( wxString::Format(
1126 "Teardrop on layer %d: area %.0f, area outside corridor %.0f (%.1f%%)",
1127 (int) layer, tdArea, outArea, ratio * 100.0 ) );
1128
1129 if( ratio > 0.02 )
1130 {
1131 foundSpike = true;
1132 BOOST_TEST_MESSAGE( wxString::Format(
1133 "Teardrop on layer %d sweeps %.1f%% of its area outside the track/pad "
1134 "corridor (spike)",
1135 (int) layer, ratio * 100.0 ) );
1136 }
1137 }
1138
1139 BOOST_CHECK_MESSAGE( teardropCount > 0, "Expected at least one teardrop zone" );
1140 BOOST_CHECK_MESSAGE( !foundSpike,
1141 "A teardrop vertex spikes outside the track/pad corridor it should "
1142 "follow" );
1143}
1144
1145
1154{
1155 KI_TEST::LoadBoard( m_settingsManager, "oval_teardrop", m_board );
1156
1157 // Set up tool manager for teardrop generation
1158 TOOL_MANAGER toolMgr;
1159 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
1160
1161 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
1162 toolMgr.RegisterTool( dummyTool );
1163
1164 // Generate teardrops
1165 BOARD_COMMIT commit( dummyTool );
1166 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
1167 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
1168
1169 if( !commit.Empty() )
1170 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
1171
1172 // Find teardrop zones
1173 int teardropCount = 0;
1174 bool foundBadTeardrop = false;
1175
1176 for( ZONE* zone : m_board->Zones() )
1177 {
1178 if( !zone->IsTeardropArea() )
1179 continue;
1180
1181 teardropCount++;
1182
1183 const SHAPE_POLY_SET* outline = zone->Outline();
1184
1185 if( !outline || outline->OutlineCount() == 0 )
1186 continue;
1187
1188 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
1189
1190 // Check for excessive concave vertices that would indicate the teardrop curve
1191 // is not tangent to the oval's semicircular end
1192 int concaveCount = 0;
1193
1194 for( int i = 0; i < chain.PointCount(); i++ )
1195 {
1196 int prev = ( i == 0 ) ? chain.PointCount() - 1 : i - 1;
1197 int next = ( i + 1 ) % chain.PointCount();
1198
1199 VECTOR2I v1 = chain.CPoint( i ) - chain.CPoint( prev );
1200 VECTOR2I v2 = chain.CPoint( next ) - chain.CPoint( i );
1201
1202 int64_t cross = (int64_t) v1.x * v2.y - (int64_t) v1.y * v2.x;
1203
1204 if( cross < -1000 )
1205 concaveCount++;
1206 }
1207
1208 if( concaveCount > 5 )
1209 {
1210 BOOST_TEST_MESSAGE( wxString::Format( "Oval teardrop has %d concave vertices",
1211 concaveCount ) );
1212 foundBadTeardrop = true;
1213 }
1214 }
1215
1216 BOOST_CHECK_MESSAGE( teardropCount > 0, "Expected at least one teardrop zone" );
1217
1218 BOOST_CHECK_MESSAGE( !foundBadTeardrop,
1219 "Found teardrop with excessive concave vertices on oval pad, "
1220 "indicating curve is not tangent to semicircular end" );
1221}
1222
1223
1232{
1233 KI_TEST::LoadBoard( m_settingsManager, "large_circle_teardrop", m_board );
1234
1235 // Set up tool manager for teardrop generation
1236 TOOL_MANAGER toolMgr;
1237 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
1238
1239 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
1240 toolMgr.RegisterTool( dummyTool );
1241
1242 // Generate teardrops
1243 BOARD_COMMIT commit( dummyTool );
1244 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
1245 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
1246
1247 if( !commit.Empty() )
1248 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
1249
1250 // Find the pad and its teardrop
1251 PAD* largePad = nullptr;
1252
1253 for( FOOTPRINT* fp : m_board->Footprints() )
1254 {
1255 for( PAD* pad : fp->Pads() )
1256 {
1257 if( pad->GetShape( F_Cu ) == PAD_SHAPE::CIRCLE )
1258 {
1259 largePad = pad;
1260 break;
1261 }
1262 }
1263 }
1264
1265 BOOST_REQUIRE_MESSAGE( largePad != nullptr, "Expected a circular pad in test board" );
1266
1267 int padRadius = largePad->GetSize( F_Cu ).x / 2;
1268 VECTOR2I padCenter = largePad->GetPosition();
1269
1270 // Find teardrop zones
1271 int teardropCount = 0;
1272 bool foundBadTeardrop = false;
1273
1274 for( ZONE* zone : m_board->Zones() )
1275 {
1276 if( !zone->IsTeardropArea() )
1277 continue;
1278
1279 teardropCount++;
1280
1281 const SHAPE_POLY_SET* outline = zone->Outline();
1282
1283 if( !outline || outline->OutlineCount() == 0 )
1284 continue;
1285
1286 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
1287
1288 // Check for excessive concave vertices
1289 int concaveCount = 0;
1290
1291 for( int i = 0; i < chain.PointCount(); i++ )
1292 {
1293 int prev = ( i == 0 ) ? chain.PointCount() - 1 : i - 1;
1294 int next = ( i + 1 ) % chain.PointCount();
1295
1296 VECTOR2I v1 = chain.CPoint( i ) - chain.CPoint( prev );
1297 VECTOR2I v2 = chain.CPoint( next ) - chain.CPoint( i );
1298
1299 int64_t cross = (int64_t) v1.x * v2.y - (int64_t) v1.y * v2.x;
1300
1301 if( cross < -1000 )
1302 concaveCount++;
1303 }
1304
1305 if( concaveCount > 5 )
1306 {
1307 BOOST_TEST_MESSAGE( wxString::Format( "Large circle teardrop has %d concave vertices",
1308 concaveCount ) );
1309 foundBadTeardrop = true;
1310 }
1311
1312 // Also verify that the teardrop anchor points near the pad are approximately
1313 // on the circle edge (within tolerance)
1314 int maxError = m_board->GetDesignSettings().m_MaxError;
1315
1316 for( int i = 0; i < chain.PointCount(); i++ )
1317 {
1318 VECTOR2I pt = chain.CPoint( i );
1319 double dist = ( pt - padCenter ).EuclideanNorm();
1320
1321 // Points that are close to the circle should be approximately on it
1322 if( dist > padRadius * 0.5 && dist < padRadius * 1.5 )
1323 {
1324 double deviation = std::abs( dist - padRadius );
1325
1326 // Allow some tolerance for polygon approximation
1327 if( deviation > maxError * 5 && deviation < padRadius * 0.2 )
1328 {
1329 BOOST_TEST_MESSAGE( wxString::Format(
1330 "Teardrop point at distance %.2f from pad center (radius %.2f), "
1331 "deviation %.2f exceeds tolerance",
1332 dist / 1000.0, padRadius / 1000.0, deviation / 1000.0 ) );
1333 }
1334 }
1335 }
1336 }
1337
1338 BOOST_CHECK_MESSAGE( teardropCount > 0, "Expected at least one teardrop zone" );
1339
1340 BOOST_CHECK_MESSAGE( !foundBadTeardrop,
1341 "Found teardrop with excessive concave vertices on large circle, "
1342 "indicating anchor points may not be on circle edge" );
1343}
1344
1345
1356BOOST_FIXTURE_TEST_CASE( RegressionCoincidentPadClearance, ZONE_FILL_TEST_FIXTURE )
1357{
1358 KI_TEST::LoadBoard( m_settingsManager, "issue23123_minimal", m_board );
1359
1360 KI_TEST::FillZones( m_board.get() );
1361
1362 // After filling, every pad whose net differs from the zone must have clearance.
1363 // Check each zone/pad combination on each shared layer.
1364 int violations = 0;
1365
1366 for( ZONE* zone : m_board->Zones() )
1367 {
1368 if( zone->GetIsRuleArea() )
1369 continue;
1370
1371 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
1372 {
1373 if( !zone->HasFilledPolysForLayer( layer ) )
1374 continue;
1375
1376 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
1377
1378 for( PAD* pad : m_board->GetPads() )
1379 {
1380 if( !pad->IsOnLayer( layer ) )
1381 continue;
1382
1383 if( pad->GetNetCode() == zone->GetNetCode() )
1384 continue;
1385
1386 std::shared_ptr<SHAPE> padShape = pad->GetEffectiveShape( layer );
1387 int clearance = padShape->GetClearance( fill.get() );
1388
1389 if( clearance < 1 )
1390 {
1391 BOOST_TEST_MESSAGE( wxString::Format(
1392 "Pad %s (net %s) at (%d, %d) has zero clearance to zone %s "
1393 "on layer %s",
1394 pad->GetNumber(), pad->GetNetname(),
1395 pad->GetPosition().x, pad->GetPosition().y,
1396 zone->GetNetname(), m_board->GetLayerName( layer ) ) );
1397 violations++;
1398 }
1399 }
1400 }
1401 }
1402
1403 BOOST_CHECK_MESSAGE( violations == 0,
1404 wxString::Format( "Found %d pads with missing zone clearance. "
1405 "Coincident pads with different nets must not be "
1406 "deduplicated in zone fill knockout.",
1407 violations ) );
1408}
1409
1410
1421{
1422 KI_TEST::LoadBoard( m_settingsManager, "connect/connect", m_board );
1423
1424 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
1425
1426 KI_TEST::FillZones( m_board.get() );
1427
1428 std::vector<DRC_ITEM> violations;
1429
1430 bds.m_DRCEngine->InitEngine( wxFileName() );
1431
1433 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
1434 const std::function<void( PCB_MARKER* )>& aPathGenerator )
1435 {
1436 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
1437 {
1438 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
1439 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
1440
1441 ZONE* zone_a = dynamic_cast<ZONE*>( item_a );
1442 ZONE* zone_b = dynamic_cast<ZONE*>( item_b );
1443
1444 if( zone_a || zone_b )
1445 violations.push_back( *aItem );
1446 }
1447 } );
1448
1449 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
1450
1451 BOOST_CHECK_EQUAL( violations.size(), 0 );
1452}
1453
1454
1466{
1467 KI_TEST::LoadBoard( m_settingsManager, "issue23339_zone_layer_rules", m_board );
1468
1469 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
1470
1471 // First verify that EvalRules returns the correct clearance per layer
1472 ZONE* hvZone = nullptr;
1473 ZONE* lvZone = nullptr;
1474
1475 for( ZONE* zone : m_board->Zones() )
1476 {
1477 if( zone->GetNetname() == "HV_NET" )
1478 hvZone = zone;
1479 else if( zone->GetNetname() == "LV_NET" )
1480 lvZone = zone;
1481 }
1482
1483 BOOST_REQUIRE( hvZone );
1484 BOOST_REQUIRE( lvZone );
1485
1486 // Outer layer rule should give 4.6mm clearance on F.Cu
1488 hvZone, lvZone, F_Cu );
1489
1490 BOOST_TEST_MESSAGE( "F.Cu clearance: " << outerConstraint.GetValue().Min()
1491 << " (expected " << pcbIUScale.mmToIU( 4.6 ) << ")" );
1492 BOOST_CHECK_EQUAL( outerConstraint.GetValue().Min(), pcbIUScale.mmToIU( 4.6 ) );
1493
1494 // Inner layer rule should give 2.3mm clearance on In1.Cu
1496 hvZone, lvZone, In1_Cu );
1497
1498 BOOST_TEST_MESSAGE( "In1.Cu clearance: " << innerConstraint.GetValue().Min()
1499 << " (expected " << pcbIUScale.mmToIU( 2.3 ) << ")" );
1500 BOOST_CHECK_EQUAL( innerConstraint.GetValue().Min(), pcbIUScale.mmToIU( 2.3 ) );
1501
1502 // Now fill zones and check that fills actually respect the clearances
1503 KI_TEST::FillZones( m_board.get() );
1504
1505 // Run DRC and verify no clearance violations between zones
1506 std::vector<DRC_ITEM> violations;
1507
1508 bds.m_DRCEngine->InitEngine( wxFileName() );
1509
1511 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
1512 const std::function<void( PCB_MARKER* )>& aPathGenerator )
1513 {
1514 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
1515 {
1516 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
1517 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
1518
1519 ZONE* zone_a = dynamic_cast<ZONE*>( item_a );
1520 ZONE* zone_b = dynamic_cast<ZONE*>( item_b );
1521
1522 if( zone_a && zone_b )
1523 {
1524 BOOST_TEST_MESSAGE( "Zone-to-zone clearance violation on layer "
1525 << aLayer << ": " << aItem->GetErrorMessage( true ) );
1526 violations.push_back( *aItem );
1527 }
1528 }
1529 } );
1530
1531 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
1532
1533 BOOST_CHECK_EQUAL( violations.size(), 0 );
1534}
1535
1536
1537BOOST_FIXTURE_TEST_CASE( RegressionZoneFillMinWidthAfterKnockout, ZONE_FILL_TEST_FIXTURE )
1538{
1539 KI_TEST::LoadBoard( m_settingsManager, "issue23332_min_width/issue23332_min_width", m_board );
1540
1541 KI_TEST::FillZones( m_board.get() );
1542
1543 int epsilon = pcbIUScale.mmToIU( 0.001 );
1544
1545 for( ZONE* zone : m_board->Zones() )
1546 {
1547 int half_min_width = zone->GetMinThickness() / 2;
1548
1549 if( half_min_width - epsilon <= epsilon )
1550 continue;
1551
1552 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
1553 {
1554 if( !zone->HasFilledPolysForLayer( layer ) )
1555 continue;
1556
1557 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1558
1559 if( !fill || fill->OutlineCount() == 0 )
1560 continue;
1561
1562 // Check each filled island individually so that a tiny thin sliver
1563 // isn't masked by a large zone's total area
1564 for( int ii = 0; ii < fill->OutlineCount(); ii++ )
1565 {
1566 SHAPE_POLY_SET island;
1567 island.AddOutline( fill->Outline( ii ) );
1568
1569 for( int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1570 island.AddHole( fill->Hole( ii, jj ) );
1571
1572 double originalArea = island.Area();
1573
1574 if( originalArea <= 0 )
1575 continue;
1576
1578
1579 test.Deflate( half_min_width - epsilon, CORNER_STRATEGY::CHAMFER_ALL_CORNERS,
1580 ARC_HIGH_DEF );
1581
1582 test.Inflate( half_min_width - epsilon, CORNER_STRATEGY::ROUND_ALL_CORNERS,
1583 ARC_HIGH_DEF, true );
1584
1585 double prunedArea = test.Area();
1586 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1587
1588 BOOST_TEST_MESSAGE( wxString::Format(
1589 "Zone %s layer %d island %d: area=%.0f, loss=%.4f%%",
1590 zone->GetNetname(), static_cast<int>( layer ), ii,
1591 originalArea, areaLoss * 100.0 ) );
1592
1593 BOOST_CHECK_MESSAGE( areaLoss < 0.01,
1594 wxString::Format(
1595 "Zone %s layer %d island %d lost %.2f%% area from "
1596 "min-width pruning (min_width=%.3fmm)",
1597 zone->GetNetname(), static_cast<int>( layer ), ii,
1598 areaLoss * 100.0,
1599 zone->GetMinThickness()
1600 / static_cast<double>( pcbIUScale.IU_PER_MM ) ) );
1601 }
1602 }
1603 }
1604}
1605
1606
1607BOOST_FIXTURE_TEST_CASE( RegressionSameNetOverlappingZones, ZONE_FILL_TEST_FIXTURE )
1608{
1609 KI_TEST::LoadBoard( m_settingsManager, "issue23418/testing", m_board );
1610
1611 KI_TEST::FillZones( m_board.get() );
1612
1613 int epsilon = pcbIUScale.mmToIU( 0.001 );
1614
1615 for( ZONE* zone : m_board->Zones() )
1616 {
1617 int half_min_width = zone->GetMinThickness() / 2;
1618
1619 if( half_min_width - epsilon <= epsilon )
1620 continue;
1621
1622 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
1623 {
1624 if( !zone->HasFilledPolysForLayer( layer ) )
1625 continue;
1626
1627 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1628
1629 if( !fill || fill->OutlineCount() == 0 )
1630 continue;
1631
1632 for( int ii = 0; ii < fill->OutlineCount(); ii++ )
1633 {
1634 SHAPE_POLY_SET island;
1635 island.AddOutline( fill->Outline( ii ) );
1636
1637 for( int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1638 island.AddHole( fill->Hole( ii, jj ) );
1639
1640 double originalArea = island.Area();
1641
1642 if( originalArea <= 0 )
1643 continue;
1644
1646
1647 test.Deflate( half_min_width - epsilon, CORNER_STRATEGY::CHAMFER_ALL_CORNERS,
1648 ARC_HIGH_DEF );
1649
1650 test.Inflate( half_min_width - epsilon, CORNER_STRATEGY::ROUND_ALL_CORNERS,
1651 ARC_HIGH_DEF, true );
1652
1653 double prunedArea = test.Area();
1654 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1655
1656 BOOST_CHECK_MESSAGE( areaLoss < 0.01,
1657 wxString::Format(
1658 "Zone %s (priority %d) layer %d island %d lost "
1659 "%.2f%% area from min-width pruning, suggesting "
1660 "degenerate geometry from overlapping same-net zones",
1661 zone->GetNetname(),
1662 zone->GetAssignedPriority(),
1663 static_cast<int>( layer ), ii,
1664 areaLoss * 100.0 ) );
1665 }
1666 }
1667 }
1668}
1669
1670
1671BOOST_FIXTURE_TEST_CASE( RegressionDiffNetOverlappingZones, ZONE_FILL_TEST_FIXTURE )
1672{
1673 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
1674 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
1675
1676 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
1677 guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
1678
1679 auto runAreaLossCheck =
1680 [this]( bool aIterative )
1681 {
1682 ADVANCED_CFG& innerCfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
1683 innerCfg.m_ZoneFillIterativeRefill = aIterative;
1684
1685 KI_TEST::LoadBoard( m_settingsManager, "issue23418_diffnet/testing", m_board );
1686 KI_TEST::FillZones( m_board.get() );
1687
1688 int epsilon = pcbIUScale.mmToIU( 0.001 );
1689
1690 for( ZONE* zone : m_board->Zones() )
1691 {
1692 int half_min_width = zone->GetMinThickness() / 2;
1693
1694 if( half_min_width - epsilon <= epsilon )
1695 continue;
1696
1697 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
1698 {
1699 if( !zone->HasFilledPolysForLayer( layer ) )
1700 continue;
1701
1702 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1703
1704 if( !fill || fill->OutlineCount() == 0 )
1705 continue;
1706
1707 for( int ii = 0; ii < fill->OutlineCount(); ii++ )
1708 {
1709 SHAPE_POLY_SET island;
1710 island.AddOutline( fill->Outline( ii ) );
1711
1712 for( int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1713 island.AddHole( fill->Hole( ii, jj ) );
1714
1715 double originalArea = island.Area();
1716
1717 if( originalArea <= 0 )
1718 continue;
1719
1721
1722 test.Deflate( half_min_width - epsilon,
1724
1725 test.Inflate( half_min_width - epsilon,
1727
1728 double prunedArea = test.Area();
1729 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1730
1732 areaLoss < 0.01,
1733 wxString::Format(
1734 "Zone %s (priority %d) layer %d island %d lost "
1735 "%.2f%% area (iterative=%d), suggesting degenerate "
1736 "geometry from different-net zone knockouts",
1737 zone->GetNetname(), zone->GetAssignedPriority(),
1738 static_cast<int>( layer ), ii, areaLoss * 100.0,
1739 aIterative ) );
1740 }
1741 }
1742 }
1743 };
1744
1745 runAreaLossCheck( false );
1746 runAreaLossCheck( true );
1747}
1748
1749
1765BOOST_FIXTURE_TEST_CASE( RegressionThermalReliefsToNowhere, ZONE_FILL_TEST_FIXTURE )
1766{
1767 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
1768 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
1769 cfg.m_ZoneFillIterativeRefill = true;
1770
1771 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
1772 guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
1773
1774 KI_TEST::LoadBoard( m_settingsManager, "issue23535_minimal/issue23535_minimal", m_board );
1775
1776 KI_TEST::FillZones( m_board.get() );
1777
1778 ZONE* gndZone = nullptr;
1779
1780 for( ZONE* zone : m_board->Zones() )
1781 {
1782 if( zone->GetNetname() == "GND" )
1783 gndZone = zone;
1784 }
1785
1786 BOOST_REQUIRE( gndZone );
1788
1789 const std::shared_ptr<SHAPE_POLY_SET>& gndFill = gndZone->GetFilledPolysList( F_Cu );
1790
1791 // The pad is at (6.5mm, 5mm) with size 1.5mm and thermal gap 0.5mm.
1792 // The right edge of the pad is at x=7.25mm, thermal gap extends to x=7.75mm.
1793 // After zone knockout, GND fill stops at roughly x=7.5mm.
1794 //
1795 // A thermal-relief-to-nowhere spoke would create copper at a point inside the
1796 // thermal gap but past the zone fill boundary. Check a point at (7.4mm, 5mm)
1797 // which is in the thermal gap (x > 7.25) and near the knockout edge.
1798 VECTOR2I spokeTestPoint( pcbIUScale.mmToIU( 7.4 ), pcbIUScale.mmToIU( 5.0 ) );
1799
1800 bool hasSpokeToNowhere = gndFill->Contains( spokeTestPoint );
1801
1802 BOOST_CHECK_MESSAGE( !hasSpokeToNowhere,
1803 "GND zone fill contains copper at the thermal gap test point (7.4, 5.0), "
1804 "indicating a thermal relief spoke to nowhere (issue 23535)." );
1805
1806 // Also verify that the left-pointing spoke still connects properly.
1807 // A point at (5.6mm, 5mm) is in the thermal gap on the left side and should have
1808 // copper from a valid left-pointing spoke.
1809 VECTOR2I validSpokePoint( pcbIUScale.mmToIU( 5.6 ), pcbIUScale.mmToIU( 5.0 ) );
1810
1811 bool hasValidSpoke = gndFill->Contains( validSpokePoint );
1812
1813 BOOST_CHECK_MESSAGE( hasValidSpoke,
1814 "GND zone fill does not contain copper at the valid spoke test point "
1815 "(5.6, 5.0). The fix may have incorrectly removed valid spokes." );
1816}
1817
1818
1829{
1830 KI_TEST::LoadBoard( m_settingsManager, "off_center_teardrop", m_board );
1831
1832 TOOL_MANAGER toolMgr;
1833 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
1834
1835 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
1836 toolMgr.RegisterTool( dummyTool );
1837
1838 BOARD_COMMIT commit( dummyTool );
1839 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
1840 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
1841
1842 if( !commit.Empty() )
1843 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
1844
1845 // The test board has a 3mm circle pad at (100, 100) with a 0.25mm track connecting
1846 // at (100.75, 99) heading to (115, 99). The track enters the pad off-center: 1mm above
1847 // and 0.75mm right of center. The teardrop should be approximately symmetric about the
1848 // track's axis (the line from ~(100.75, 99) toward (115, 99), i.e., horizontal).
1849
1850 int teardropCount = 0;
1851
1852 for( ZONE* zone : m_board->Zones() )
1853 {
1854 if( !zone->IsTeardropArea() )
1855 continue;
1856
1857 teardropCount++;
1858
1859 const SHAPE_POLY_SET* outline = zone->Outline();
1860
1861 if( !outline || outline->OutlineCount() == 0 )
1862 continue;
1863
1864 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
1865
1866 // The track axis is approximately at Y=99mm (in board coordinates = 99 * 1e6 nm).
1867 // Measure the maximum extent above and below this axis across all teardrop vertices.
1868 int trackY = pcbIUScale.mmToIU( 99 );
1869 int maxAbove = 0;
1870 int maxBelow = 0;
1871
1872 for( int i = 0; i < chain.PointCount(); i++ )
1873 {
1874 int dy = chain.CPoint( i ).y - trackY;
1875
1876 if( dy < 0 )
1877 maxAbove = std::max( maxAbove, -dy );
1878 else
1879 maxBelow = std::max( maxBelow, dy );
1880 }
1881
1882 // Both sides should have some extent (the teardrop flares out on both sides)
1883 BOOST_CHECK_MESSAGE( maxAbove > 0 && maxBelow > 0,
1884 "Teardrop should extend on both sides of the track axis" );
1885
1886 if( maxAbove > 0 && maxBelow > 0 )
1887 {
1888 // The two sides should be approximately equal. Allow 30% asymmetry tolerance
1889 // to account for polygon approximation of the circular pad and convex hull rounding.
1890 double ratio = static_cast<double>( std::min( maxAbove, maxBelow ) )
1891 / static_cast<double>( std::max( maxAbove, maxBelow ) );
1892
1893 BOOST_CHECK_MESSAGE( ratio > 0.7,
1894 wxString::Format( "Teardrop asymmetry ratio %.2f is too low "
1895 "(above=%d, below=%d). Expected roughly "
1896 "symmetric about the track axis.",
1897 ratio, maxAbove, maxBelow ) );
1898 }
1899 }
1900
1901 BOOST_CHECK_MESSAGE( teardropCount > 0, "Expected at least one teardrop zone for off-center track" );
1902}
1903
1904
1913BOOST_FIXTURE_TEST_CASE( ElongatedPadTeardropContainment, ZONE_FILL_TEST_FIXTURE )
1914{
1915 KI_TEST::LoadBoard( m_settingsManager, "teardrop_elongated_pad", m_board );
1916
1917 TOOL_MANAGER toolMgr;
1918 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
1919
1920 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
1921 toolMgr.RegisterTool( dummyTool );
1922
1923 BOARD_COMMIT commit( dummyTool );
1924 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
1925 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
1926
1927 if( !commit.Empty() )
1928 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
1929
1930 // Find the pad to build an expanded outline for containment checking.
1931 // The pad is at board position (136.45, 100.819) with size (3.5, 0.3) rotated 270 deg,
1932 // giving board extents X: [136.3, 136.6], Y: [99.069, 102.569].
1933 PAD* testPad = nullptr;
1934
1935 for( FOOTPRINT* fp : m_board->Footprints() )
1936 {
1937 for( PAD* pad : fp->Pads() )
1938 {
1939 if( pad->GetNumber() == "7" )
1940 {
1941 testPad = pad;
1942 break;
1943 }
1944 }
1945 }
1946
1947 BOOST_REQUIRE_MESSAGE( testPad != nullptr, "Could not find pad 7 in test board" );
1948
1949 // Build the pad outline polygon with a small tolerance for the track half-width
1950 int tolerance = std::max( m_board->GetDesignSettings().m_MaxError,
1951 pcbIUScale.mmToIU( 0.001 ) );
1952 SHAPE_POLY_SET padPoly;
1953 testPad->TransformShapeToPolygon( padPoly, B_Cu, tolerance,
1954 m_board->GetDesignSettings().m_MaxError, ERROR_OUTSIDE );
1955
1956 int teardropCount = 0;
1957
1958 for( ZONE* zone : m_board->Zones() )
1959 {
1960 if( !zone->IsTeardropArea() )
1961 continue;
1962
1963 const SHAPE_POLY_SET* outline = zone->Outline();
1964
1965 BOOST_REQUIRE_MESSAGE( outline && outline->OutlineCount() > 0,
1966 "Teardrop zone has no outline" );
1967
1968 teardropCount++;
1969
1970 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
1971
1972 // Check each vertex of the teardrop. Vertices on the pad side (closer to pad center
1973 // than to the track anchor) must be inside the expanded pad outline.
1974 VECTOR2I padCenter = testPad->GetPosition();
1975
1976 // The track anchor region is near (136.45, 99.16) in mm, i.e., outside the pad.
1977 // We only check vertices that are closer to the pad center than to the track anchor.
1978 VECTOR2I trackAnchor( pcbIUScale.mmToIU( 136.45 ), pcbIUScale.mmToIU( 99.16 ) );
1979
1980 for( int i = 0; i < chain.PointCount(); i++ )
1981 {
1982 VECTOR2I pt = chain.CPoint( i );
1983 double distToPad = ( VECTOR2D( pt ) - VECTOR2D( padCenter ) ).EuclideanNorm();
1984 double distToTrack = ( VECTOR2D( pt ) - VECTOR2D( trackAnchor ) ).EuclideanNorm();
1985
1986 // Only check vertices on the pad side of the teardrop
1987 if( distToPad < distToTrack )
1988 {
1990 padPoly.Contains( pt ),
1991 wxString::Format( "Teardrop vertex (%d, %d) is outside the pad "
1992 "outline with %d nm tolerance",
1993 pt.x, pt.y, tolerance ) );
1994 }
1995 }
1996 }
1997
1998 BOOST_CHECK_MESSAGE( teardropCount > 0,
1999 "Expected at least one teardrop zone for elongated pad" );
2000}
2001
2002
2011BOOST_FIXTURE_TEST_CASE( TwoSegmentAngledTeardropNoSelfIntersection, ZONE_FILL_TEST_FIXTURE )
2012{
2013 auto runVariant = [&]( bool aCurvedEdges )
2014 {
2015 KI_TEST::LoadBoard( m_settingsManager, "two_segment_teardrop", m_board );
2016
2017 for( PCB_TRACK* track : m_board->Tracks() )
2018 {
2019 if( track->Type() == PCB_VIA_T )
2020 {
2021 static_cast<PCB_VIA*>( track )->SetTeardropCurved( aCurvedEdges );
2022 break;
2023 }
2024 }
2025
2026 TOOL_MANAGER toolMgr;
2027 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
2028
2029 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
2030 toolMgr.RegisterTool( dummyTool );
2031
2032 BOARD_COMMIT commit( dummyTool );
2033 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
2034 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
2035
2036 if( !commit.Empty() )
2037 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
2038
2039 int teardropCount = 0;
2040 bool foundSelfIntersection = false;
2041
2042 for( ZONE* zone : m_board->Zones() )
2043 {
2044 if( !zone->IsTeardropArea() )
2045 continue;
2046
2047 teardropCount++;
2048
2049 const SHAPE_POLY_SET* outline = zone->Outline();
2050
2051 if( !outline || outline->OutlineCount() == 0 )
2052 continue;
2053
2054 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
2055 int n = chain.PointCount();
2056
2057 for( int i = 0; i < n && !foundSelfIntersection; i++ )
2058 {
2059 SEG segA( chain.CPoint( i ), chain.CPoint( ( i + 1 ) % n ) );
2060
2061 for( int j = i + 2; j < n; j++ )
2062 {
2063 if( i == 0 && j == n - 1 )
2064 continue;
2065
2066 SEG segB( chain.CPoint( j ), chain.CPoint( ( j + 1 ) % n ) );
2067 OPT_VECTOR2I hit = segA.Intersect( segB );
2068
2069 if( hit.has_value() )
2070 {
2071 BOOST_TEST_MESSAGE( wxString::Format(
2072 "Self-intersection at (%d, %d) between edges %d and %d "
2073 "(curved=%s)",
2074 hit->x, hit->y, i, j,
2075 aCurvedEdges ? "yes" : "no" ) );
2076
2077 for( int k = 0; k < n; k++ )
2078 {
2079 BOOST_TEST_MESSAGE( wxString::Format(
2080 " pt[%d] = (%d, %d)", k,
2081 chain.CPoint( k ).x, chain.CPoint( k ).y ) );
2082 }
2083
2084 foundSelfIntersection = true;
2085 break;
2086 }
2087 }
2088 }
2089 }
2090
2091 BOOST_CHECK_MESSAGE( teardropCount > 0,
2092 wxString::Format( "Expected at least one teardrop zone "
2093 "(curved=%s)",
2094 aCurvedEdges ? "yes" : "no" ) );
2095
2096 BOOST_CHECK_MESSAGE( !foundSelfIntersection,
2097 wxString::Format( "Teardrop polygon has self-intersecting "
2098 "edges (curved=%s)",
2099 aCurvedEdges ? "yes" : "no" ) );
2100 };
2101
2102 runVariant( true );
2103 runVariant( false );
2104}
2105
2106
2125BOOST_FIXTURE_TEST_CASE( OffCenterTwoSegmentTeardropNoSpike, ZONE_FILL_TEST_FIXTURE )
2126{
2127 auto runVariant = [&]( bool aCurvedEdges )
2128 {
2129 KI_TEST::LoadBoard( m_settingsManager, "teardrop_offcenter_two_segment", m_board );
2130
2131 VECTOR2I viaPos;
2132 int viaRadius = 0;
2133
2134 for( PCB_TRACK* track : m_board->Tracks() )
2135 {
2136 if( track->Type() == PCB_VIA_T )
2137 {
2138 PCB_VIA* via = static_cast<PCB_VIA*>( track );
2139 via->SetTeardropCurved( aCurvedEdges );
2140 viaPos = via->GetPosition();
2141 viaRadius = via->GetWidth( PADSTACK::ALL_LAYERS ) / 2;
2142 break;
2143 }
2144 }
2145
2146 BOOST_REQUIRE( viaRadius > 0 );
2147
2148 TOOL_MANAGER toolMgr;
2149 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
2150
2151 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
2152 toolMgr.RegisterTool( dummyTool );
2153
2154 BOARD_COMMIT commit( dummyTool );
2155 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
2156 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
2157
2158 if( !commit.Empty() )
2159 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
2160
2161 // The crafted board's first segment emerges from the via by ~10 um on a 100 um
2162 // track width; the emerging-length filter rejects it and no teardrop is built.
2163 const double maxBackSideDist = viaRadius * 1.2;
2164 int teardropCount = 0;
2165 int spikingPoints = 0;
2166 VECTOR2I worstPoint;
2167 double worstDistance = 0.0;
2168
2169 for( ZONE* zone : m_board->Zones() )
2170 {
2171 if( !zone->IsTeardropArea() )
2172 continue;
2173
2174 teardropCount++;
2175
2176 const SHAPE_POLY_SET* outline = zone->Outline();
2177
2178 if( !outline || outline->OutlineCount() == 0 )
2179 continue;
2180
2181 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
2182
2183 for( int i = 0; i < chain.PointCount(); i++ )
2184 {
2185 const VECTOR2I& pt = chain.CPoint( i );
2186 VECTOR2I rel = pt - viaPos;
2187
2188 // Only consider points on the back side (opposite the track entry).
2189 if( rel.x >= 0 )
2190 continue;
2191
2192 double dist = rel.EuclideanNorm();
2193
2194 if( dist > maxBackSideDist )
2195 {
2196 spikingPoints++;
2197
2198 if( dist > worstDistance )
2199 {
2200 worstDistance = dist;
2201 worstPoint = pt;
2202 }
2203 }
2204 }
2205 }
2206
2207 BOOST_CHECK_MESSAGE( teardropCount == 0,
2208 wxString::Format( "Expected no teardrop on grazing-entry "
2209 "track (emergence below track width), got "
2210 "%d (curved=%s)",
2211 teardropCount,
2212 aCurvedEdges ? "yes" : "no" ) );
2213
2214 BOOST_CHECK_MESSAGE( spikingPoints == 0,
2215 wxString::Format( "Found %d teardrop polygon vertex/vertices "
2216 "outside the expected envelope (worst at "
2217 "(%d, %d), %f mm from via center; curved=%s)",
2218 spikingPoints,
2219 worstPoint.x, worstPoint.y,
2220 worstDistance / pcbIUScale.IU_PER_MM,
2221 aCurvedEdges ? "yes" : "no" ) );
2222 };
2223
2224 runVariant( true );
2225 runVariant( false );
2226}
2227
2228
2240BOOST_FIXTURE_TEST_CASE( MultiTrackSharedInsideJunctionNoSelfIntersection,
2242{
2243 auto runVariant = [&]( bool aCurvedEdges )
2244 {
2245 KI_TEST::LoadBoard( m_settingsManager, "teardrop_multi_inside_via", m_board );
2246
2247 for( PCB_TRACK* track : m_board->Tracks() )
2248 {
2249 if( track->Type() == PCB_VIA_T )
2250 {
2251 static_cast<PCB_VIA*>( track )->SetTeardropCurved( aCurvedEdges );
2252 break;
2253 }
2254 }
2255
2256 TOOL_MANAGER toolMgr;
2257 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
2258
2259 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
2260 toolMgr.RegisterTool( dummyTool );
2261
2262 BOARD_COMMIT commit( dummyTool );
2263 TEARDROP_MANAGER teardropMgr( m_board.get(), &toolMgr );
2264 teardropMgr.UpdateTeardrops( commit, nullptr, nullptr, true );
2265
2266 if( !commit.Empty() )
2267 commit.Push( _( "Add teardrops" ), SKIP_UNDO | SKIP_SET_DIRTY );
2268
2269 int teardropCount = 0;
2270 int selfIntersectingCount = 0;
2271 VECTOR2I worstPoint;
2272
2273 for( ZONE* zone : m_board->Zones() )
2274 {
2275 if( !zone->IsTeardropArea() )
2276 continue;
2277
2278 teardropCount++;
2279
2280 const SHAPE_POLY_SET* outline = zone->Outline();
2281
2282 if( !outline || outline->OutlineCount() == 0 )
2283 continue;
2284
2285 const SHAPE_LINE_CHAIN& chain = outline->Outline( 0 );
2286 int n = chain.PointCount();
2287 bool intersected = false;
2288
2289 for( int i = 0; i < n && !intersected; i++ )
2290 {
2291 SEG segA( chain.CPoint( i ), chain.CPoint( ( i + 1 ) % n ) );
2292
2293 for( int j = i + 2; j < n; j++ )
2294 {
2295 if( i == 0 && j == n - 1 )
2296 continue;
2297
2298 SEG segB( chain.CPoint( j ), chain.CPoint( ( j + 1 ) % n ) );
2299 OPT_VECTOR2I hit = segA.Intersect( segB );
2300
2301 if( hit.has_value() )
2302 {
2303 BOOST_TEST_MESSAGE( wxString::Format(
2304 "Teardrop polygon self-intersection at (%d, %d) "
2305 "between edges %d and %d (curved=%s)",
2306 hit->x, hit->y, i, j, aCurvedEdges ? "yes" : "no" ) );
2307
2308 worstPoint = hit.value();
2309 intersected = true;
2310 break;
2311 }
2312 }
2313 }
2314
2315 if( intersected )
2316 selfIntersectingCount++;
2317 }
2318
2319 BOOST_CHECK_MESSAGE( teardropCount > 0,
2320 wxString::Format( "Expected at least one teardrop zone "
2321 "(curved=%s)",
2322 aCurvedEdges ? "yes" : "no" ) );
2323
2324 BOOST_CHECK_MESSAGE( selfIntersectingCount == 0,
2325 wxString::Format( "%d of %d teardrop polygon(s) self-intersect "
2326 "(worst at (%d, %d); curved=%s)",
2327 selfIntersectingCount, teardropCount,
2328 worstPoint.x, worstPoint.y,
2329 aCurvedEdges ? "yes" : "no" ) );
2330 };
2331
2332 runVariant( true );
2333 runVariant( false );
2334}
2335
2336
2344BOOST_FIXTURE_TEST_CASE( RegressionKeepoutBoundaryMissingFill, ZONE_FILL_TEST_FIXTURE )
2345{
2346 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
2347 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
2348
2349 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
2350 guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
2351
2352 auto getTotalFilledArea =
2353 [this]() -> double
2354 {
2355 double totalArea = 0;
2356
2357 for( ZONE* zone : m_board->Zones() )
2358 {
2359 if( zone->GetIsRuleArea() )
2360 continue;
2361
2362 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
2363 {
2364 if( !zone->HasFilledPolysForLayer( layer ) )
2365 continue;
2366
2367 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
2368
2369 if( fill )
2370 totalArea += std::abs( fill->Area() );
2371 }
2372 }
2373
2374 return totalArea;
2375 };
2376
2377 auto refillAndMeasure =
2378 [this, &cfg, &getTotalFilledArea]( bool aIterative ) -> double
2379 {
2380 cfg.m_ZoneFillIterativeRefill = aIterative;
2381
2382 KI_TEST::LoadBoard( m_settingsManager, "issue23515/issue23515", m_board );
2383
2384 double storedArea = getTotalFilledArea();
2385
2386 BOOST_REQUIRE_MESSAGE( storedArea > 0, "Stored v9 fill has zero area" );
2387
2388 KI_TEST::FillZones( m_board.get() );
2389 return getTotalFilledArea();
2390 };
2391
2392 KI_TEST::LoadBoard( m_settingsManager, "issue23515/issue23515", m_board );
2393
2394 double storedArea = getTotalFilledArea();
2395
2396 BOOST_REQUIRE_MESSAGE( storedArea > 0, "Stored v9 fill has zero area" );
2397
2398 double nonIterativeArea = refillAndMeasure( false );
2399 double iterativeArea = refillAndMeasure( true );
2400 double nonIterativeAreaRatio = nonIterativeArea / storedArea;
2401 double iterativeAreaRatio = iterativeArea / storedArea;
2402
2404 nonIterativeAreaRatio > 0.99999,
2405 wxString::Format(
2406 "Non-iterative refill lost %.4f%% versus stored v9 fill "
2407 "(stored=%.2f mm^2, non-iterative=%.2f mm^2). "
2408 "This suggests missing pieces near keepout boundaries (issue 23515).",
2409 ( 1.0 - nonIterativeAreaRatio ) * 100.0,
2410 storedArea / 1e6, nonIterativeArea / 1e6 ) );
2411
2413 iterativeAreaRatio > 0.99999,
2414 wxString::Format(
2415 "Iterative refill lost %.4f%% versus stored v9 fill "
2416 "(stored=%.2f mm^2, iterative=%.2f mm^2). "
2417 "This suggests missing pieces near keepout boundaries (issue 23515).",
2418 ( 1.0 - iterativeAreaRatio ) * 100.0,
2419 storedArea / 1e6, iterativeArea / 1e6 ) );
2420}
2421
2422
2431BOOST_FIXTURE_TEST_CASE( HatchZoneViaConnectionRespectsSetting, ZONE_FILL_TEST_FIXTURE )
2432{
2433 m_board = std::make_unique<BOARD>();
2434
2435 // Two-layer board is sufficient for this test
2436 m_board->SetCopperLayerCount( 2 );
2437
2438 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
2439 bds.SetCopperLayerCount( 2 );
2440
2441 bds.m_MinClearance = pcbIUScale.mmToIU( 0.2 );
2442
2443 // Add a GND net
2444 NETINFO_ITEM* gndNet = new NETINFO_ITEM( m_board.get(), wxT( "GND" ) );
2445 m_board->Add( gndNet );
2446 int gndNetCode = gndNet->GetNetCode();
2447
2448 // Via dimensions: 2.0mm diameter, 1.0mm drill - large enough to span multiple hatch cells
2449 // so the via always touches webbing lines regardless of position within the hatch grid.
2450 int viaDiam = pcbIUScale.mmToIU( 2.0 );
2451 int viaDrill = pcbIUScale.mmToIU( 1.0 );
2452
2453 // Hatch zone parameters: 0.5mm gap, 0.3mm thickness. The via (radius=1.0mm) is wider
2454 // than the gap, so it will always intersect webbing in FULL mode. The thermal gap
2455 // (0.5mm) makes the knockout circle radius = 1.0+0.5 = 1.5mm.
2456 int hatchGap = pcbIUScale.mmToIU( 0.5 );
2457 int hatchThickness = pcbIUScale.mmToIU( 0.3 );
2458
2459 // Via center at 10mm,10mm (middle of the zone)
2460 VECTOR2I viaPos( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) );
2461
2462 auto makeVia =
2463 [&]() -> PCB_VIA*
2464 {
2465 PCB_VIA* via = new PCB_VIA( m_board.get() );
2466 via->SetPosition( viaPos );
2467 via->SetLayerPair( F_Cu, B_Cu );
2468 via->SetDrill( viaDrill );
2469 via->SetWidth( PADSTACK::ALL_LAYERS, viaDiam );
2470 via->SetNetCode( gndNetCode );
2471 m_board->Add( via );
2472 return via;
2473 };
2474
2475 auto makeHatchZone =
2476 [&]( ZONE_CONNECTION aConnection ) -> ZONE*
2477 {
2478 ZONE* zone = new ZONE( m_board.get() );
2479 zone->SetLayer( F_Cu );
2480 zone->SetNetCode( gndNetCode );
2482 zone->SetHatchGap( hatchGap );
2483 zone->SetHatchThickness( hatchThickness );
2484 zone->SetPadConnection( aConnection );
2485 zone->SetMinThickness( pcbIUScale.mmToIU( 0.2 ) );
2486 zone->SetThermalReliefGap( pcbIUScale.mmToIU( 0.5 ) );
2487 zone->SetThermalReliefSpokeWidth( pcbIUScale.mmToIU( 0.5 ) );
2488
2489 SHAPE_POLY_SET outline;
2490 outline.NewOutline();
2491 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) ) );
2492 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 19 ), pcbIUScale.mmToIU( 1 ) ) );
2493 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 19 ), pcbIUScale.mmToIU( 19 ) ) );
2494 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 19 ) ) );
2495 zone->AddPolygon( outline.COutline( 0 ) );
2496
2497 m_board->Add( zone );
2498 return zone;
2499 };
2500
2501 auto initDRC =
2502 [&]()
2503 {
2504 m_board->BuildConnectivity();
2505 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
2506 drcEngine->InitEngine( wxFileName() );
2507 bds.m_DRCEngine = drcEngine;
2508 };
2509
2510 // The thermal relief adds a circular ring around the via that covers hatch holes which
2511 // would otherwise be open. With viaRadius=1.0mm, thermalGap=0.5mm, spokeWidth=0.5mm:
2512 // ring outer radius = 1.75mm, inner radius = 1.25mm
2513 // ring area added inside hatch holes > knockout area removed from webbing
2514 // net result: THERMAL fill area > FULL fill area by ~0.4 sq mm
2515 // FULL connection skips both the knockout and the ring addition, so the THERMAL fill
2516 // should be measurably larger than the FULL fill.
2517
2518 double fullFillArea = 0.0;
2519 double thermalFillArea = 0.0;
2520
2521 // Test 1: FULL connection
2522 {
2523 PCB_VIA* via = makeVia();
2524 ZONE* zone = makeHatchZone( ZONE_CONNECTION::FULL );
2525
2526 initDRC();
2527 KI_TEST::FillZones( m_board.get() );
2528
2529 BOOST_REQUIRE_MESSAGE( zone->HasFilledPolysForLayer( F_Cu ),
2530 "Zone should have fill on F.Cu with FULL connection" );
2531
2532 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_Cu );
2533
2534 for( int i = 0; i < fill->OutlineCount(); i++ )
2535 fullFillArea += std::abs( fill->Outline( i ).Area() );
2536
2537 m_board->Remove( via );
2538 m_board->Remove( zone );
2539 delete via;
2540 delete zone;
2541 }
2542
2543 // Test 2: THERMAL connection
2544 {
2545 PCB_VIA* via = makeVia();
2546 ZONE* zone = makeHatchZone( ZONE_CONNECTION::THERMAL );
2547
2548 initDRC();
2549 KI_TEST::FillZones( m_board.get() );
2550
2551 BOOST_REQUIRE_MESSAGE( zone->HasFilledPolysForLayer( F_Cu ),
2552 "Zone should have fill on F.Cu with THERMAL connection" );
2553
2554 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_Cu );
2555
2556 for( int i = 0; i < fill->OutlineCount(); i++ )
2557 thermalFillArea += std::abs( fill->Outline( i ).Area() );
2558
2559 m_board->Remove( via );
2560 m_board->Remove( zone );
2561 delete via;
2562 delete zone;
2563 }
2564
2565 // The THERMAL fill should have more area than the FULL fill because a thermal ring was
2566 // added around the via, filling hatch holes that would otherwise be open.
2567 // Use a 0.2 sq mm threshold to avoid sensitivity to small edge effects.
2568 double iuPerMM = pcbIUScale.IU_PER_MM;
2569 double areaThreshold = 0.2 * iuPerMM * iuPerMM; // 0.2 sq mm in IU^2
2570
2571 double areaIU2toMM2 = 1.0 / ( iuPerMM * iuPerMM );
2572
2573 BOOST_CHECK_MESSAGE( thermalFillArea > fullFillArea + areaThreshold,
2574 wxString::Format(
2575 "THERMAL connection fill area (%.2f sq mm) should be larger "
2576 "than FULL fill area (%.2f sq mm) by at least 0.2 sq mm. "
2577 "If they are equal or FULL is larger, thermal ring was not "
2578 "added for THERMAL connection, or thermal ring was incorrectly "
2579 "added for FULL connection (issue 23516 regression).",
2580 thermalFillArea * areaIU2toMM2, fullFillArea * areaIU2toMM2 ) );
2581}
2582
2583
2590BOOST_FIXTURE_TEST_CASE( HatchZoneFullViaStaysConnected, ZONE_FILL_TEST_FIXTURE )
2591{
2592 m_board = std::make_unique<BOARD>();
2593 m_board->SetCopperLayerCount( 2 );
2594
2595 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
2596 bds.SetCopperLayerCount( 2 );
2597 bds.m_MinClearance = pcbIUScale.mmToIU( 0.2 );
2598
2599 NETINFO_ITEM* gndNet = new NETINFO_ITEM( m_board.get(), wxT( "GND" ) );
2600 m_board->Add( gndNet );
2601 int gndNetCode = gndNet->GetNetCode();
2602
2603 // Via diameter (0.4mm) is much smaller than the hatch gap (2.0mm), so a via centred in a
2604 // hole sits entirely inside that hole with no copper around it unless the hole is dropped.
2605 int viaDiam = pcbIUScale.mmToIU( 0.4 );
2606 int viaDrill = pcbIUScale.mmToIU( 0.2 );
2607
2608 int hatchGap = pcbIUScale.mmToIU( 2.0 );
2609 int hatchThickness = pcbIUScale.mmToIU( 0.3 );
2610
2611 auto makeHatchZone = [&]() -> ZONE*
2612 {
2613 ZONE* zone = new ZONE( m_board.get() );
2614 zone->SetLayer( F_Cu );
2615 zone->SetNetCode( gndNetCode );
2617 zone->SetHatchGap( hatchGap );
2618 zone->SetHatchThickness( hatchThickness );
2620 zone->SetMinThickness( pcbIUScale.mmToIU( 0.2 ) );
2621
2622 SHAPE_POLY_SET outline;
2623 outline.NewOutline();
2624 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 0 ), pcbIUScale.mmToIU( 0 ) ) );
2625 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 0 ) ) );
2626 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 20 ) ) );
2627 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 0 ), pcbIUScale.mmToIU( 20 ) ) );
2628 zone->AddPolygon( outline.COutline( 0 ) );
2629
2630 m_board->Add( zone );
2631 return zone;
2632 };
2633
2634 // Sweep over one full grid period (gridsize = hatchThickness + hatchGap = 2.3mm) so the
2635 // via is guaranteed to land inside a hole at several positions regardless of grid phase.
2636 const int steps = 8;
2637 const double startMM = 9.0;
2638 const double stepMM = 2.3 / steps;
2639
2640 int isolatedCount = 0;
2641 int testedCount = 0;
2642
2643 for( int ix = 0; ix < steps; ix++ )
2644 {
2645 for( int iy = 0; iy < steps; iy++ )
2646 {
2647 VECTOR2I viaPos( pcbIUScale.mmToIU( startMM + ix * stepMM ), pcbIUScale.mmToIU( startMM + iy * stepMM ) );
2648
2649 PCB_VIA* via = new PCB_VIA( m_board.get() );
2650 via->SetPosition( viaPos );
2651 via->SetLayerPair( F_Cu, B_Cu );
2652 via->SetDrill( viaDrill );
2653 via->SetWidth( PADSTACK::ALL_LAYERS, viaDiam );
2654 via->SetNetCode( gndNetCode );
2655 m_board->Add( via );
2656
2657 ZONE* zone = makeHatchZone();
2658
2659 m_board->BuildConnectivity();
2660 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
2661 drcEngine->InitEngine( wxFileName() );
2662 bds.m_DRCEngine = drcEngine;
2663
2664 KI_TEST::FillZones( m_board.get() );
2665
2667
2668 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_Cu );
2669 std::shared_ptr<SHAPE> viaShape = via->GetEffectiveShape( F_Cu );
2670
2671 // The zone fill must touch the via. If it does not, the via is isolated copper
2672 // inside a hatch hole (the issue 24559 regression).
2673 if( !fill->Collide( viaShape.get(), 0 ) )
2674 isolatedCount++;
2675
2676 testedCount++;
2677
2678 m_board->Remove( via );
2679 m_board->Remove( zone );
2680 delete via;
2681 delete zone;
2682 }
2683 }
2684
2685 BOOST_CHECK_MESSAGE( isolatedCount == 0, wxString::Format( "%d of %d FULL-connection via positions were left "
2686 "isolated from the hatch fill (issue 24559).",
2687 isolatedCount, testedCount ) );
2688}
2689
2690
2708BOOST_FIXTURE_TEST_CASE( RegressionCascadingIslandRefill, ZONE_FILL_TEST_FIXTURE )
2709{
2710 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
2711 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
2712 cfg.m_ZoneFillIterativeRefill = true;
2713
2714 struct ScopeGuard
2715 {
2716 bool& ref;
2717 bool orig;
2718 ~ScopeGuard() { ref = orig; }
2719 } guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
2720
2721 KI_TEST::LoadBoard( m_settingsManager, "zone_refill_cascading_islands", m_board );
2722 KI_TEST::FillZones( m_board.get() );
2723
2724 const std::vector<std::string> checkedNames = { "hi1", "hi2", "hi3", "hi4", "hi5", "hi6", "hi7",
2725 "lo1", "lo2", "lo3", "lo4", "lo5", "lo6" };
2726 std::map<std::string, ZONE*> zoneByName;
2727
2728 for( ZONE* zone : m_board->Zones() )
2729 zoneByName[zone->GetZoneName().ToStdString()] = zone;
2730
2731 for( const std::string& name : checkedNames )
2732 {
2733 BOOST_REQUIRE_MESSAGE( zoneByName.count( name ), "Zone '" + name + "' not found in test board" );
2734 BOOST_REQUIRE_MESSAGE( zoneByName[name]->HasFilledPolysForLayer( F_Cu ),
2735 "Zone '" + name + "' has no fill on F.Cu" );
2736 }
2737
2738 // hi3, hi5, hi7 each split into two copper islands (one standalone, one merged with lo2/lo4/lo6).
2739 for( const std::string& name : { "hi3", "hi5", "hi7" } )
2740 {
2741 int islands = zoneByName[name]->GetFilledPolysList( F_Cu )->OutlineCount();
2742
2743 BOOST_CHECK_MESSAGE( islands == 2, wxString::Format( "Zone '%s' should have 2 filled islands but has %d. "
2744 "Cascading island removal did not converge correctly.",
2745 name, islands ) );
2746 }
2747
2748 // All lo zones and hi2/hi4/hi6 are single zones.
2749 for( const std::string& name : { "lo1", "lo2", "lo3", "lo4", "lo5", "lo6", "hi2", "hi4", "hi6" } )
2750 {
2751 int islands = zoneByName[name]->GetFilledPolysList( F_Cu )->OutlineCount();
2752
2753 BOOST_CHECK_MESSAGE( islands == 1, wxString::Format( "Zone '%s' should have 1 filled island but has %d. "
2754 "Iterative refill may have incorrectly blocked or "
2755 "expanded this zone.",
2756 name, islands ) );
2757 }
2758}
2759
2760
2767BOOST_FIXTURE_TEST_CASE( CopperThievingZone_HatchSurvivesTrackBisection, ZONE_FILL_TEST_FIXTURE )
2768{
2769 KI_TEST::LoadBoard( m_settingsManager, "zone_thieving_track_bisection", m_board );
2770 KI_TEST::FillZones( m_board.get() );
2771
2772 ZONE* thievingZone = nullptr;
2773
2774 for( ZONE* z : m_board->Zones() )
2775 {
2776 if( z->GetFillMode() == ZONE_FILL_MODE::COPPER_THIEVING )
2777 {
2778 thievingZone = z;
2779 break;
2780 }
2781 }
2782
2783 BOOST_REQUIRE( thievingZone );
2784
2785 const std::shared_ptr<SHAPE_POLY_SET>& fill = thievingZone->GetFilledPolysList( F_Cu );
2786 BOOST_REQUIRE( fill );
2787
2788 // The track splits the fill area in two; before the fix the connectivity
2789 // pass classified the narrow side as an isolated island and deleted it.
2790 // Expect at least two outlines covering both halves of the original zone.
2791 BOOST_CHECK_GE( fill->OutlineCount(), 2 );
2792
2793 // The fill must span the full zone width (left edge through right edge).
2794 BOX2I fillBox = fill->BBox();
2795 BOX2I zoneBox = thievingZone->Outline()->BBox();
2796
2797 BOOST_CHECK_LT( fillBox.GetLeft(), zoneBox.GetLeft() + pcbIUScale.mmToIU( 2.0 ) );
2798 BOOST_CHECK_GT( fillBox.GetRight(), zoneBox.GetRight() - pcbIUScale.mmToIU( 2.0 ) );
2799
2800 // The mesh must have real structure on both sides.
2801 BOOST_CHECK_GT( fill->TotalVertices(), 200 );
2802}
2803
2804
2817BOOST_FIXTURE_TEST_CASE( IterativeRefillConvergenceLimit, ZONE_FILL_TEST_FIXTURE )
2818{
2819 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
2820 bool originalIterativeRefill = cfg.m_ZoneFillIterativeRefill;
2821 cfg.m_ZoneFillIterativeRefill = true;
2822
2823 struct ScopeGuard
2824 {
2825 bool& ref;
2826 bool orig;
2827 ~ScopeGuard() { ref = orig; }
2828 } guard{ cfg.m_ZoneFillIterativeRefill, originalIterativeRefill };
2829
2830 // Capture wxLogWarning calls so we can assert that the iteration cap fires.
2831 class WarningCapture : public wxLog
2832 {
2833 public:
2834 bool m_hadWarning = false;
2835
2836 protected:
2837 void DoLogRecord( wxLogLevel aLevel, const wxString&, const wxLogRecordInfo& ) override
2838 {
2839 if( aLevel == wxLOG_Warning )
2840 m_hadWarning = true;
2841 }
2842 };
2843
2844 auto* capture = new WarningCapture();
2845 wxLog* oldLog = wxLog::SetActiveTarget( capture );
2846
2847 struct LogGuard
2848 {
2849 wxLog* old;
2850 ~LogGuard() { wxLog::SetActiveTarget( old ); }
2851 } logGuard{ oldLog };
2852
2853 KI_TEST::LoadBoard( m_settingsManager, "zone_refill_convergence_limit", m_board );
2854 KI_TEST::FillZones( m_board.get() );
2855
2856 BOOST_CHECK_MESSAGE( capture->m_hadWarning, "Expected a wxLogWarning when iterative refill hits the iteration "
2857 "limit, but none was emitted. The convergence-limit board may no "
2858 "longer trigger the cap, or the warning path has changed." );
2859}
2860
2861
2867BOOST_FIXTURE_TEST_CASE( CopperThievingZone_NonCopperLayerStampsNotSolid, ZONE_FILL_TEST_FIXTURE )
2868{
2869 m_board = std::make_unique<BOARD>();
2870
2871 ZONE* zone = new ZONE( m_board.get() );
2872 zone->SetLayer( F_SilkS );
2873 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
2874 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
2875 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
2876 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 10 ) ), -1 );
2878
2879 THIEVING_SETTINGS thieving;
2881 thieving.element_size = pcbIUScale.mmToIU( 0.5 );
2882 thieving.gap = pcbIUScale.mmToIU( 1.5 );
2883 zone->SetThievingSettings( thieving );
2885 m_board->Add( zone );
2886
2887 KI_TEST::FillZones( m_board.get() );
2888
2889 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_SilkS );
2890 BOOST_REQUIRE( fill );
2891
2892 // A solid fill would have one outline (the zone polygon); a dots grid
2893 // produces dozens. Lower bound is conservative to avoid edge-clipping flakiness.
2894 BOOST_CHECK_GT( fill->OutlineCount(), 5 );
2895}
2896
2897
2906{
2907 m_board = std::make_unique<BOARD>();
2908 m_board->SetCopperLayerCount( 2 );
2909
2910 // 10 mm x 10 mm zone outline
2911 ZONE* zone = new ZONE( m_board.get() );
2912 zone->SetLayer( F_Cu );
2913 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
2914 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
2915 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
2916 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 10 ) ), -1 );
2917
2919
2920 THIEVING_SETTINGS thieving;
2922 thieving.element_size = pcbIUScale.mmToIU( 0.5 );
2923 thieving.gap = pcbIUScale.mmToIU( 2.0 );
2924 thieving.line_width = pcbIUScale.mmToIU( 0.3 );
2925 thieving.stagger = false;
2926 thieving.orientation = ANGLE_0;
2927 zone->SetThievingSettings( thieving );
2928
2930
2931 m_board->Add( zone );
2932
2933 KI_TEST::FillZones( m_board.get() );
2934
2935 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_Cu );
2936 BOOST_REQUIRE( fill );
2937 BOOST_REQUIRE_GT( fill->OutlineCount(), 0 );
2938
2939 // 2.5 mm pitch, 0.5 mm dot. The four positions whose disc touches the
2940 // zone edge (x or y at 0 or 10 mm) are dropped, leaving a 3 x 3 grid.
2941 BOOST_CHECK_GE( fill->OutlineCount(), 6 );
2942 BOOST_CHECK_LE( fill->OutlineCount(), 12 );
2943
2944 // 10% slack covers the polygonal circle approximation plus post-fill corner rounding.
2945 const double fullDotArea = M_PI * std::pow( pcbIUScale.mmToIU( 0.25 ), 2 );
2946 CheckAllOutlineAreasAtLeast( fill, 0.9 * fullDotArea, wxT( "Dot" ) );
2947}
2948
2949
2956BOOST_FIXTURE_TEST_CASE( CopperThievingZone_StaggerProducesDifferentLayout, ZONE_FILL_TEST_FIXTURE )
2957{
2958 auto countDots = []( bool stagger ) -> int
2959 {
2960 auto board = std::make_unique<BOARD>();
2961 board->SetCopperLayerCount( 2 );
2962
2963 ZONE* zone = new ZONE( board.get() );
2964 zone->SetLayer( F_Cu );
2965 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
2966 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 20 ), 0 ), -1 );
2967 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 20 ) ), -1 );
2968 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 20 ) ), -1 );
2970
2971 THIEVING_SETTINGS thieving;
2973 thieving.element_size = pcbIUScale.mmToIU( 0.5 );
2974 thieving.gap = pcbIUScale.mmToIU( 2.0 );
2975 thieving.stagger = stagger;
2976 zone->SetThievingSettings( thieving );
2978 board->Add( zone );
2979
2980 KI_TEST::FillZones( board.get() );
2981 return zone->GetFilledPolysList( F_Cu )->OutlineCount();
2982 };
2983
2984 int plain = countDots( false );
2985 int staggered = countDots( true );
2986
2987 BOOST_TEST_MESSAGE( "plain dots: " << plain << " staggered dots: " << staggered );
2988
2989 // Within a factor of two — catches the offset walking dots off the board
2990 // (returning ~0) without being brittle about edge-clipping rounding.
2991 BOOST_CHECK_NE( plain, staggered );
2992 BOOST_CHECK_GE( staggered, plain / 2 );
2993 BOOST_CHECK_LE( staggered, plain * 2 );
2994}
2995
2996
3002BOOST_FIXTURE_TEST_CASE( CopperThievingZone_SquaresGrid, ZONE_FILL_TEST_FIXTURE )
3003{
3004 m_board = std::make_unique<BOARD>();
3005 m_board->SetCopperLayerCount( 2 );
3006
3007 ZONE* zone = new ZONE( m_board.get() );
3008 zone->SetLayer( F_Cu );
3009 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
3010 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
3011 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
3012 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 10 ) ), -1 );
3014
3015 THIEVING_SETTINGS thieving;
3017 thieving.element_size = pcbIUScale.mmToIU( 0.6 );
3018 thieving.gap = pcbIUScale.mmToIU( 2.0 );
3019 zone->SetThievingSettings( thieving );
3021 m_board->Add( zone );
3022
3023 KI_TEST::FillZones( m_board.get() );
3024
3025 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_Cu );
3026 BOOST_REQUIRE( fill );
3027 BOOST_REQUIRE_GT( fill->OutlineCount(), 0 );
3028
3029 // 2.6 mm pitch, 0.6 mm square. Same edge-drop behavior as the dots test:
3030 // strict-containment leaves a 3 x 3 grid of full squares.
3031 BOOST_CHECK_GE( fill->OutlineCount(), 6 );
3032 BOOST_CHECK_LE( fill->OutlineCount(), 12 );
3033
3034 const double fullSquareArea = std::pow( pcbIUScale.mmToIU( 0.6 ), 2 );
3035 CheckAllOutlineAreasAtLeast( fill, 0.9 * fullSquareArea, wxT( "Square" ) );
3036}
3037
3038
3047BOOST_FIXTURE_TEST_CASE( CopperThievingZone_HighDensityPerformance, ZONE_FILL_TEST_FIXTURE )
3048{
3049 m_board = std::make_unique<BOARD>();
3050 m_board->SetCopperLayerCount( 2 );
3051
3052 ZONE* zone = new ZONE( m_board.get() );
3053 zone->SetLayer( F_Cu );
3054 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
3055 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 100 ), 0 ), -1 );
3056 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 100 ), pcbIUScale.mmToIU( 100 ) ), -1 );
3057 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 100 ) ), -1 );
3059
3060 THIEVING_SETTINGS thieving;
3062 thieving.element_size = pcbIUScale.mmToIU( 0.3 );
3063 thieving.gap = pcbIUScale.mmToIU( 1.0 );
3064 zone->SetThievingSettings( thieving );
3066 m_board->Add( zone );
3067
3068 auto start = std::chrono::steady_clock::now();
3069 KI_TEST::FillZones( m_board.get() );
3070 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
3071 std::chrono::steady_clock::now() - start )
3072 .count();
3073
3074 BOOST_TEST_MESSAGE( "5.9k-dot fill elapsed: " << elapsed << " ms" );
3075
3077 BOOST_CHECK_GT( zone->GetFilledPolysList( F_Cu )->OutlineCount(), 4000 );
3078
3079 // 30 s upper bound on QABUILD with assertions on; current implementation
3080 // measures in low seconds.
3081 BOOST_CHECK_LT( elapsed, 30000 );
3082}
3083
3084
3091BOOST_FIXTURE_TEST_CASE( CopperThievingZone_HatchPattern, ZONE_FILL_TEST_FIXTURE )
3092{
3093 m_board = std::make_unique<BOARD>();
3094 m_board->SetCopperLayerCount( 2 );
3095
3096 ZONE* zone = new ZONE( m_board.get() );
3097 zone->SetLayer( F_Cu );
3098 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
3099 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
3100 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
3101 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 10 ) ), -1 );
3103
3104 THIEVING_SETTINGS thieving;
3106 thieving.gap = pcbIUScale.mmToIU( 2.0 );
3107 thieving.line_width = pcbIUScale.mmToIU( 0.3 );
3108 zone->SetThievingSettings( thieving );
3110 m_board->Add( zone );
3111
3112 KI_TEST::FillZones( m_board.get() );
3113
3114 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( F_Cu );
3115 BOOST_REQUIRE( fill );
3116 BOOST_REQUIRE_GT( fill->TotalVertices(), 0 );
3117
3118 // Subtractive hatch produces a single connected outline after fracturing
3119 // (perimeter border + interior mesh linked through bridges). A dot grid
3120 // in the same outline would have dozens of disconnected pieces.
3121 BOOST_CHECK_EQUAL( fill->OutlineCount(), 1 );
3122
3123 // The fill bounding box must reach the zone corners — the perimeter
3124 // border is what differentiates hatch from a dot grid. Solid would also
3125 // reach the corners; the high vertex count below catches that case.
3126 BOX2I fillBox = fill->BBox();
3127 BOOST_CHECK_LT( fillBox.GetLeft(), pcbIUScale.mmToIU( 0.5 ) );
3128 BOOST_CHECK_GT( fillBox.GetRight(), pcbIUScale.mmToIU( 9.5 ) );
3129 BOOST_CHECK_LT( fillBox.GetTop(), pcbIUScale.mmToIU( 0.5 ) );
3130 BOOST_CHECK_GT( fillBox.GetBottom(), pcbIUScale.mmToIU( 9.5 ) );
3131
3132 // A solid 10x10 mm rectangle would have ~4 vertices. A hatched mesh has
3133 // many vertices because each void cut adds outline segments.
3134 BOOST_CHECK_GT( fill->TotalVertices(), 30 );
3135}
3136
3137
3145BOOST_FIXTURE_TEST_CASE( RegressionNonCopperZoneKeepoutIslands, ZONE_FILL_TEST_FIXTURE )
3146{
3147 KI_TEST::LoadBoard( m_settingsManager, "issue24089/issue24089", m_board );
3148
3149 auto countIslands =
3150 [this]() -> int
3151 {
3152 int total = 0;
3153
3154 for( ZONE* zone : m_board->Zones() )
3155 {
3156 if( zone->GetIsRuleArea() )
3157 continue;
3158
3159 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
3160 {
3161 if( !zone->HasFilledPolysForLayer( layer ) )
3162 continue;
3163
3164 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
3165
3166 if( fill )
3167 total += fill->OutlineCount();
3168 }
3169 }
3170
3171 return total;
3172 };
3173
3174 int storedIslands = countIslands();
3175
3176 BOOST_REQUIRE_MESSAGE( storedIslands >= 3,
3177 wxString::Format( "Stored v9 fill should have at least 3 silk islands; "
3178 "found %d",
3179 storedIslands ) );
3180
3181 KI_TEST::FillZones( m_board.get() );
3182
3183 int refilledIslands = countIslands();
3184
3185 BOOST_CHECK_MESSAGE( refilledIslands == storedIslands,
3186 wxString::Format( "Refill lost silk islands: stored=%d, refilled=%d. "
3187 "Outline 0 of every non-copper multi-island zone "
3188 "was being incorrectly removed (issue 24089).",
3189 storedIslands, refilledIslands ) );
3190}
3191
3192
3198BOOST_FIXTURE_TEST_CASE( OverlappingPriorityPadFlashing, ZONE_FILL_TEST_FIXTURE )
3199{
3200 m_board = std::make_unique<BOARD>();
3201 m_board->SetCopperLayerCount( 4 );
3202
3203 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
3204 bds.SetCopperLayerCount( 4 );
3205 bds.m_MinClearance = pcbIUScale.mmToIU( 0.2 );
3206
3207 NETINFO_ITEM* gndNet = new NETINFO_ITEM( m_board.get(), wxT( "GND" ) );
3208 m_board->Add( gndNet );
3209 int gndNetCode = gndNet->GetNetCode();
3210
3211 NETINFO_ITEM* vccNet = new NETINFO_ITEM( m_board.get(), wxT( "VCC" ) );
3212 m_board->Add( vccNet );
3213 int vccNetCode = vccNet->GetNetCode();
3214
3215 ZONE* gndZone = new ZONE( m_board.get() );
3216 gndZone->SetLayer( In1_Cu );
3217 gndZone->SetNetCode( gndNetCode );
3218 gndZone->SetAssignedPriority( 0 );
3219 gndZone->SetMinThickness( pcbIUScale.mmToIU( 0.2 ) );
3220 gndZone->SetThermalReliefGap( pcbIUScale.mmToIU( 0.5 ) );
3221 gndZone->SetThermalReliefSpokeWidth( pcbIUScale.mmToIU( 0.5 ) );
3223 {
3224 SHAPE_POLY_SET outline;
3225 outline.NewOutline();
3226 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 0 ), pcbIUScale.mmToIU( 0 ) ) );
3227 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 30 ), pcbIUScale.mmToIU( 0 ) ) );
3228 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 30 ), pcbIUScale.mmToIU( 20 ) ) );
3229 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 0 ), pcbIUScale.mmToIU( 20 ) ) );
3230 gndZone->AddPolygon( outline.COutline( 0 ) );
3231 }
3232 m_board->Add( gndZone );
3233
3234 ZONE* vccZone = new ZONE( m_board.get() );
3235 vccZone->SetLayer( In1_Cu );
3236 vccZone->SetNetCode( vccNetCode );
3237 vccZone->SetAssignedPriority( 5 );
3238 vccZone->SetMinThickness( pcbIUScale.mmToIU( 4.0 ) );
3239 vccZone->SetThermalReliefGap( pcbIUScale.mmToIU( 0.5 ) );
3240 vccZone->SetThermalReliefSpokeWidth( pcbIUScale.mmToIU( 0.5 ) );
3242 {
3243 // A "barbell": a bulky right lobe joined to a thin left neck by a 0.5mm-tall corridor.
3244 // VCC's 4mm min-thickness prunes the neck and corridor in the deflate/inflate pass, so
3245 // VCC fills only the right lobe while its outline still encloses the pad at (15, 10).
3246 SHAPE_POLY_SET outline;
3247 outline.NewOutline();
3248 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 13.5 ), pcbIUScale.mmToIU( 9.75 ) ) );
3249 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 18 ), pcbIUScale.mmToIU( 9.75 ) ) );
3250 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 18 ), pcbIUScale.mmToIU( 0 ) ) );
3251 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 30 ), pcbIUScale.mmToIU( 0 ) ) );
3252 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 30 ), pcbIUScale.mmToIU( 20 ) ) );
3253 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 18 ), pcbIUScale.mmToIU( 20 ) ) );
3254 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 18 ), pcbIUScale.mmToIU( 10.25 ) ) );
3255 outline.Append( VECTOR2I( pcbIUScale.mmToIU( 13.5 ), pcbIUScale.mmToIU( 10.25 ) ) );
3256 vccZone->AddPolygon( outline.COutline( 0 ) );
3257 }
3258 m_board->Add( vccZone );
3259
3260 // REMOVE_EXCEPT_START_AND_END makes inner-layer flashing conditional on a same-net
3261 // connection, which is what issue 24175 gets wrong.
3262 auto footprint = std::make_unique<FOOTPRINT>( m_board.get() );
3263
3264 PAD* pad = new PAD( footprint.get() );
3265 pad->SetAttribute( PAD_ATTRIB::PTH );
3266 pad->SetLayerSet( LSET::AllCuMask() );
3267 pad->SetSize( PADSTACK::ALL_LAYERS,
3268 VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
3269 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.8 ), pcbIUScale.mmToIU( 0.8 ) ) );
3270 pad->SetPosition( VECTOR2I( pcbIUScale.mmToIU( 15 ), pcbIUScale.mmToIU( 10 ) ) );
3271 pad->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
3272 pad->SetNetCode( gndNetCode );
3273
3274 footprint->Add( pad );
3275 footprint->SetPosition( VECTOR2I( 0, 0 ) );
3276 m_board->Add( footprint.release() );
3277
3278 m_board->BuildConnectivity();
3279 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
3280 drcEngine->InitEngine( wxFileName() );
3281 bds.m_DRCEngine = drcEngine;
3282
3283 KI_TEST::FillZones( m_board.get() );
3284
3285 // Guard the preconditions so a future fill change cannot make this pass for the wrong
3286 // reason: VCC's outline must enclose the pad while its fill must not reach it.
3287 BOOST_REQUIRE_MESSAGE( vccZone->Outline()->Contains( pad->GetPosition() ),
3288 "VCC outline must contain the pad position to reproduce issue 24175." );
3289 BOOST_REQUIRE_MESSAGE( vccZone->HasFilledPolysForLayer( In1_Cu ),
3290 "VCC zone should still have fill in its right lobe." );
3291
3292 {
3293 const std::shared_ptr<SHAPE_POLY_SET>& vccFill = vccZone->GetFilledPolysList( In1_Cu );
3294
3295 BOOST_REQUIRE_MESSAGE( !vccFill->Contains( pad->GetPosition() ),
3296 "VCC fill should NOT contain the pad position (corridor must be "
3297 "pruned by min-thickness for the test to exercise issue 24175)." );
3298 }
3299
3300 // Before the fix the higher-priority VCC outline forced ZLO_FORCE_NO_ZONE_CONNECTION on
3301 // the pad; now the same-net GND zone wins the flashing decision.
3302 BOOST_CHECK_MESSAGE( pad->FlashLayer( In1_Cu ),
3303 "PTH pad inside higher-priority different-net zone must still flash "
3304 "when a same-net lower-priority zone covers it (issue 24175)." );
3305
3306 BOOST_REQUIRE_MESSAGE( gndZone->HasFilledPolysForLayer( In1_Cu ),
3307 "GND zone should have fill on In1.Cu" );
3308
3309 const std::shared_ptr<SHAPE_POLY_SET>& gndFill = gndZone->GetFilledPolysList( In1_Cu );
3310
3311 // Sampling a ring just outside the pad proves the GND fill actually surrounds it.
3312 int samples = 16;
3313 int sampleR = pcbIUScale.mmToIU( 1.6 ); // just outside the pad (radius 0.75) + clearance
3314 bool foundCopperAround = false;
3315
3316 for( int i = 0; i < samples; i++ )
3317 {
3318 double angle = ( 2.0 * M_PI * i ) / samples;
3319 VECTOR2I p( pad->GetPosition().x + KiROUND( sampleR * std::cos( angle ) ),
3320 pad->GetPosition().y + KiROUND( sampleR * std::sin( angle ) ) );
3321
3322 if( gndFill->Contains( p ) )
3323 {
3324 foundCopperAround = true;
3325 break;
3326 }
3327 }
3328
3329 BOOST_CHECK_MESSAGE( foundCopperAround,
3330 "Lower-priority GND zone should have copper around GND pad even when "
3331 "a higher-priority different-net zone outline contains the pad "
3332 "(issue 24175)." );
3333}
3334
3335
3336// Reproduces the scripting/API zone-fill path used by KiKit panelization (issue 24643).
3337//
3338// The interactive GUI and the board loader always create and initialize the board's DRC engine
3339// before filling. The Python/API ZONE_FILLER path can reach Fill() with no engine, so the
3340// worker-thread EvalRules() calls dereferenced a null engine and crashed the process. This test
3341// drops the engine after loading to drive that path, then verifies Fill() completes and leaves a
3342// usable engine behind.
3343BOOST_FIXTURE_TEST_CASE( RegressionApiSubsetFillPanelized, ZONE_FILL_TEST_FIXTURE )
3344{
3345 KI_TEST::LoadBoard( m_settingsManager, "issue24643/issue24643", m_board );
3346
3347 // The test harness loads boards with an initialized engine; the headless API path does not.
3348 // Drop it so Fill() must reconstruct one, which is the condition that crashed.
3349 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
3350 bds.m_DRCEngine.reset();
3351 BOOST_REQUIRE( !bds.m_DRCEngine );
3352
3353 // Mirror the script: select non-rule-area zones on B.Cu that are not already filled.
3354 PCB_LAYER_ID targetLayer = m_board->GetLayerID( wxT( "B.Cu" ) );
3355 std::vector<ZONE*> toFill;
3356
3357 for( ZONE* zone : m_board->Zones() )
3358 {
3359 if( zone->GetIsRuleArea() )
3360 continue;
3361
3362 if( !zone->IsOnLayer( targetLayer ) )
3363 continue;
3364
3365 if( zone->IsFilled() )
3366 continue;
3367
3368 toFill.push_back( zone );
3369 }
3370
3371 BOOST_REQUIRE_MESSAGE( !toFill.empty(),
3372 "Expected at least one unfilled B.Cu zone to exercise the API path." );
3373
3374 // The API path builds the filler with a null commit (see new_ZONE_FILLER in the SWIG
3375 // wrapper) and fills only the selected subset. This must complete without crashing
3376 // (issue 24643).
3377 ZONE_FILLER filler( m_board.get(), nullptr );
3378
3379 BOOST_CHECK_NO_THROW( filler.Fill( toFill ) );
3380
3381 // Fill() must have created and initialized a usable engine in place of the one we dropped.
3383 BOOST_CHECK( bds.m_DRCEngine->RulesValid() );
3384}
3385
3386
3387// Issue 23790: overlapping same-net zones must merge across a notch a higher-priority
3388// different-net zone carved into the higher-priority same-net zone.
3389BOOST_FIXTURE_TEST_CASE( RegressionSameNetMergeAroundHigherPriorityZone, ZONE_FILL_TEST_FIXTURE )
3390{
3391 // The reconciliation only runs inside the iterative refill.
3392 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
3393 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
3395 cfg.m_ZoneFillIterativeRefill = true;
3396
3397 KI_TEST::LoadBoard( m_settingsManager, "issue23790/issue23790", m_board );
3398 KI_TEST::FillZones( m_board.get() );
3399
3400 const PCB_LAYER_ID layer = F_Cu;
3401 const int margin = pcbIUScale.mmToIU( 0.05 );
3402
3403 std::map<int, SHAPE_POLY_SET> mergedByNet;
3404
3405 for( ZONE* zone : m_board->Zones() )
3406 {
3407 if( zone->GetIsRuleArea() || !zone->HasFilledPolysForLayer( layer ) )
3408 continue;
3409
3410 mergedByNet[zone->GetNetCode()].BooleanAdd( *zone->GetFilledPolysList( layer ) );
3411 }
3412
3413 // Areas legitimately free of this net's copper: keepouts and higher-priority
3414 // different-net fills (grown by a clearance allowance).
3415 auto buildLegitVoids =
3416 [&]( const ZONE* aLower, const ZONE* aHigher ) -> SHAPE_POLY_SET
3417 {
3418 SHAPE_POLY_SET voids;
3419 int allowance = pcbIUScale.mmToIU( 0.6 );
3420
3421 for( ZONE* other : m_board->Zones() )
3422 {
3423 if( !other->GetLayerSet().Contains( layer ) )
3424 continue;
3425
3426 if( other->GetIsRuleArea() )
3427 {
3428 if( other->GetDoNotAllowZoneFills() )
3429 voids.BooleanAdd( *other->Outline() );
3430
3431 continue;
3432 }
3433
3434 if( other->GetNetCode() == aLower->GetNetCode()
3435 || other->GetAssignedPriority() <= aLower->GetAssignedPriority()
3436 || other->GetAssignedPriority() <= aHigher->GetAssignedPriority()
3437 || !other->HasFilledPolysForLayer( layer ) )
3438 {
3439 continue;
3440 }
3441
3442 SHAPE_POLY_SET fill = *other->GetFilledPolysList( layer );
3444 voids.BooleanAdd( fill );
3445 }
3446
3447 return voids;
3448 };
3449
3450 std::vector<ZONE*> zones;
3451
3452 for( ZONE* zone : m_board->Zones() )
3453 {
3454 if( !zone->GetIsRuleArea() && zone->GetNetCode() > 0 && zone->GetLayerSet().Contains( layer ) )
3455 zones.push_back( zone );
3456 }
3457
3458 int checkedPairs = 0;
3459
3460 for( size_t i = 0; i < zones.size(); ++i )
3461 {
3462 for( size_t j = i + 1; j < zones.size(); ++j )
3463 {
3464 ZONE* a = zones[i];
3465 ZONE* b = zones[j];
3466
3467 if( a->GetNetCode() != b->GetNetCode() )
3468 continue;
3469
3470 SHAPE_POLY_SET overlap = *a->Outline();
3471 overlap.BooleanIntersection( *b->Outline() );
3472
3473 if( overlap.OutlineCount() == 0 )
3474 continue;
3475
3476 const ZONE* lower = a->GetAssignedPriority() <= b->GetAssignedPriority() ? a : b;
3477 const ZONE* higher = ( lower == a ) ? b : a;
3478
3479 overlap.BooleanSubtract( buildLegitVoids( lower, higher ) );
3480
3481 // Stay clear of outer-boundary min-width rounding.
3483
3484 if( overlap.OutlineCount() == 0 )
3485 continue;
3486
3487 SHAPE_POLY_SET uncovered = overlap;
3488 uncovered.BooleanSubtract( mergedByNet[a->GetNetCode()] );
3489
3490 double uncoveredArea =
3491 uncovered.Area() / ( pcbIUScale.IU_PER_MM * (double) pcbIUScale.IU_PER_MM );
3492
3493 BOOST_CHECK_MESSAGE( uncoveredArea < 0.01,
3494 wxString::Format( "Same-net zones (priorities %d and %d) left %.4f mm^2 of "
3495 "their overlap unfilled; overlapping same-net zones must "
3496 "merge (issue 23790).",
3498 uncoveredArea ) );
3499 checkedPairs++;
3500 }
3501 }
3502
3503 BOOST_CHECK_MESSAGE( checkedPairs >= 2,
3504 wxString::Format( "Expected at least two overlapping same-net zone pairs "
3505 "to exercise the merge, found %d.", checkedPairs ) );
3506}
3507
3508
3509// Issue 24758: this board is densely tiled with same-net zones, so the zone-fill dependency-DAG
3510// scheduler builds a large successor graph. The scheduler returned once its logical work counter
3511// reached zero while detached worker tasks -- which captured the successor/in-degree vectors by
3512// reference -- were still in flight, dereferencing the freed locals inside ZONE_FILLER::Fill.
3513// Filling repeatedly drives that window; under AddressSanitizer the use-after-free is reported
3514// deterministically without the fix.
3515BOOST_FIXTURE_TEST_CASE( RegressionSameNetZoneFillScheduler, ZONE_FILL_TEST_FIXTURE )
3516{
3517 ADVANCED_CFG& cfg = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() );
3518 struct ScopeGuard { bool& ref; bool orig; ~ScopeGuard() { ref = orig; } }
3520 cfg.m_ZoneFillIterativeRefill = true;
3521
3522 KI_TEST::LoadBoard( m_settingsManager, "issue24758/issue24758", m_board );
3523
3524 const PCB_LAYER_ID layer = F_Cu;
3525
3526 for( int pass = 0; pass < 64; ++pass )
3527 {
3528 BOOST_REQUIRE_NO_THROW( KI_TEST::FillZones( m_board.get() ) );
3529
3530 // Every same-net pour must come back with copper; a torn-down scheduler also corrupts
3531 // or drops fills, so assert the result is usable on every pass.
3532 SHAPE_POLY_SET merged;
3533
3534 for( ZONE* zone : m_board->Zones() )
3535 {
3536 if( zone->GetIsRuleArea() || !zone->HasFilledPolysForLayer( layer ) )
3537 continue;
3538
3539 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
3540
3541 BOOST_REQUIRE( fill != nullptr );
3542 merged.BooleanAdd( *fill );
3543 }
3544
3545 BOOST_CHECK_MESSAGE( merged.Area() > 0.0,
3546 wxString::Format( "Fill pass %d produced no copper.", pass ) );
3547 }
3548}
3549
3550
3551// Issue 24758: a hatch zone must keep its solid border where a higher-priority zone carves into
3552// it, not run the mesh into the carved edge. Board issue24758 carves net-B zones into net-A hatch.
3553BOOST_FIXTURE_TEST_CASE( RegressionHatchBorderAroundOverlap, ZONE_FILL_TEST_FIXTURE )
3554{
3555 KI_TEST::LoadBoard( m_settingsManager, "issue24758/issue24758", m_board );
3556 KI_TEST::FillZones( m_board.get() );
3557
3558 const PCB_LAYER_ID layer = F_Cu;
3559
3560 auto outlineNoArcs =
3561 []( ZONE* z )
3562 {
3563 SHAPE_POLY_SET o = *z->Outline();
3564 o.ClearArcs();
3565 return o;
3566 };
3567
3568 int checkedPairs = 0;
3569
3570 for( ZONE* hatch : m_board->Zones() )
3571 {
3572 if( hatch->GetIsRuleArea() || hatch->GetFillMode() != ZONE_FILL_MODE::HATCH_PATTERN
3573 || !hatch->HasFilledPolysForLayer( layer ) )
3574 {
3575 continue;
3576 }
3577
3578 SHAPE_POLY_SET hatchOutline = outlineNoArcs( hatch );
3579 SHAPE_POLY_SET fill = *hatch->GetFilledPolysList( layer );
3580
3581 for( ZONE* other : m_board->Zones() )
3582 {
3583 if( other == hatch || other->GetIsRuleArea() || !other->GetLayerSet().Contains( layer )
3584 || other->GetAssignedPriority() <= hatch->GetAssignedPriority() )
3585 {
3586 continue;
3587 }
3588
3589 SHAPE_POLY_SET carved = outlineNoArcs( other );
3590 carved.BooleanIntersection( hatchOutline );
3591
3592 // Need real claimed area to have a border to test.
3593 if( carved.Area() < pcbIUScale.mmToIU( 0.1 ) * (double) pcbIUScale.mmToIU( 0.1 ) )
3594 continue;
3595
3596 // Ring past the clearance void: solid with the border, ~half hatch holes without it.
3597 SHAPE_POLY_SET outer = carved;
3599
3600 SHAPE_POLY_SET inner = carved;
3602
3603 SHAPE_POLY_SET band = outer;
3604 band.BooleanSubtract( inner );
3605 band.BooleanIntersection( hatchOutline );
3606
3607 if( band.Area() <= 0 )
3608 continue;
3609
3610 SHAPE_POLY_SET covered = band;
3611 covered.BooleanIntersection( fill );
3612
3613 double coverage = covered.Area() / band.Area();
3614 checkedPairs++;
3615
3616 BOOST_CHECK_MESSAGE( coverage >= 0.85,
3617 wxString::Format( "Hatch zone %s carved by %s: border ring only %.0f%% filled; "
3618 "the hatch border was not re-established around the carved "
3619 "area (issue 24758).",
3620 hatch->GetZoneName(), other->GetZoneName(),
3621 coverage * 100.0 ) );
3622 }
3623 }
3624
3625 BOOST_CHECK_MESSAGE( checkedPairs >= 3,
3626 wxString::Format( "Expected at least three carved hatch borders to check, "
3627 "found %d.", checkedPairs ) );
3628}
3629
3630
3631// A pair separated by more than the clearance but less than the knockout reach used to fill
3632// unordered, so the knocked-out copper depended on which task finished first.
3633BOOST_FIXTURE_TEST_CASE( ZoneFillDependencyKnockoutMargin, ZONE_FILL_TEST_FIXTURE )
3634{
3635 m_board = std::make_unique<BOARD>();
3636
3637 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
3638 const int clearance = pcbIUScale.mmToIU( 2 );
3639
3640 // Also the board's worst clearance, so the separation below lands between the worst
3641 // clearance and the knockout reach.
3643
3644 NETINFO_ITEM* netA = new NETINFO_ITEM( m_board.get(), wxT( "NET_A" ), 1 );
3645 NETINFO_ITEM* netB = new NETINFO_ITEM( m_board.get(), wxT( "NET_B" ), 2 );
3646 m_board->Add( netA );
3647 m_board->Add( netB );
3648
3649 // Separation lands inside the max-error part of the reach, so the gate's error term and
3650 // the fill ordering are both exercised.
3651 const int extraMargin = pcbIUScale.mmToIU( ADVANCED_CFG::GetCfg().m_ExtraClearance );
3652 const int maxError = bds.m_MaxError;
3653 const int sep = clearance + extraMargin + maxError / 2;
3654 const int ax = pcbIUScale.mmToIU( 100 ) + sep;
3655
3656 ZONE* zoneA = new ZONE( m_board.get() );
3657 zoneA->SetLayer( F_Cu );
3658 zoneA->SetNet( netA );
3659 zoneA->SetAssignedPriority( 0 );
3660 zoneA->AppendCorner( VECTOR2I( ax, 0 ), -1 );
3661 zoneA->AppendCorner( VECTOR2I( ax + pcbIUScale.mmToIU( 2 ), 0 ), -1 );
3662 zoneA->AppendCorner( VECTOR2I( ax + pcbIUScale.mmToIU( 2 ), pcbIUScale.mmToIU( 10 ) ), -1 );
3663 zoneA->AppendCorner( VECTOR2I( ax, pcbIUScale.mmToIU( 10 ) ), -1 );
3664 m_board->Add( zoneA );
3665
3666 // The sawtooth keeps this fill busy long enough that, without a dependency edge, the
3667 // small zone (seeded first) reliably fills before this fill publishes.
3668 ZONE* zoneB = new ZONE( m_board.get() );
3669 zoneB->SetLayer( F_Cu );
3670 zoneB->SetNet( netB );
3671 zoneB->SetAssignedPriority( 1 );
3672 zoneB->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 1 ), 0 ), -1 );
3673 zoneB->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 100 ), 0 ), -1 );
3674 zoneB->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 100 ), pcbIUScale.mmToIU( 100 ) ), -1 );
3675 zoneB->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 100 ) ), -1 );
3676
3677 for( int ii = 0; ii < 1000; ++ii )
3678 {
3679 int yTop = pcbIUScale.mmToIU( 100 ) - ii * pcbIUScale.mmToIU( 0.1 );
3680
3681 zoneB->AppendCorner( VECTOR2I( 0, yTop - pcbIUScale.mmToIU( 0.05 ) ), -1 );
3682 zoneB->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 1 ), yTop - pcbIUScale.mmToIU( 0.1 ) ), -1 );
3683 }
3684
3685 m_board->Add( zoneB );
3686
3687 KI_TEST::FillZones( m_board.get() );
3688
3689 std::shared_ptr<SHAPE_POLY_SET> fillA = zoneA->GetFilledPolysList( F_Cu );
3690 std::shared_ptr<SHAPE_POLY_SET> fillB = zoneB->GetFilledPolysList( F_Cu );
3691
3692 BOOST_REQUIRE( fillA && fillA->OutlineCount() > 0 );
3693 BOOST_REQUIRE( fillB && fillB->OutlineCount() > 0 );
3694
3695 // Threshold sits between the knocked-out gap and the un-knocked outline separation, so the
3696 // check distinguishes an ordered fill from a raced one.
3697 BOOST_CHECK_MESSAGE( !fillA->Collide( fillB.get(), clearance + extraMargin + maxError * 3 / 4 ),
3698 "Lower-priority zone filled before the higher-priority knockout was "
3699 "published; the fill depends on thread scheduling." );
3700}
3701
3702
3712BOOST_FIXTURE_TEST_CASE( RegressionZoneFillNarrowBridge, ZONE_FILL_TEST_FIXTURE )
3713{
3714 KI_TEST::LoadBoard( m_settingsManager, "issue24312/issue24312", m_board );
3715
3716 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
3717
3718 // Force connection-width severity so the regression assertion does not silently
3719 // weaken if the reproduction project is updated to ignore this code.
3721
3722 KI_TEST::FillZones( m_board.get() );
3723
3724 std::vector<DRC_ITEM> violations;
3725
3727 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
3728 const std::function<void( PCB_MARKER* )>& aPathGenerator )
3729 {
3730 if( aItem->GetErrorCode() == DRCE_CONNECTION_WIDTH )
3731 violations.push_back( *aItem );
3732 } );
3733
3734 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
3735
3736 if( !violations.empty() )
3737 {
3738 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
3739
3740 std::map<KIID, EDA_ITEM*> itemMap;
3741 m_board->FillItemMap( itemMap );
3742
3743 for( const DRC_ITEM& item : violations )
3744 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
3745 }
3746
3747 BOOST_CHECK_MESSAGE( violations.empty(),
3748 wxString::Format( "Zone fill produced %zu connection_width violations; "
3749 "expected 0 (issue 24312).",
3750 violations.size() ) );
3751}
const char * name
@ ERROR_OUTSIDE
constexpr int ARC_HIGH_DEF
Definition base_units.h:137
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void SetCopperLayerCount(int aNewLayerCount)
Set the copper layer count to aNewLayerCount.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
constexpr coord_type GetLeft() const
Definition box2.h:224
constexpr coord_type GetRight() const
Definition box2.h:213
constexpr coord_type GetTop() const
Definition box2.h:225
constexpr coord_type GetBottom() const
Definition box2.h:218
bool Empty() const
Definition commit.h:134
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:196
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:164
bool RulesValid()
Definition drc_engine.h:274
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
const KIID m_Uuid
Definition eda_item.h:531
Definition kiid.h:44
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
T Min() const
Definition minoptmax.h:29
void SetClearance(int aClearance)
Definition netclass.h:125
Handle the data for a net.
Definition netinfo.h:46
int GetNetCode() const
Definition netinfo.h:94
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
Definition pad.h:61
const wxString & GetNumber() const
Definition pad.h:143
VECTOR2I GetPosition() const override
Definition pad.cpp:245
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
Definition pad.cpp:2945
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:287
Definition seg.h:38
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition seg.cpp:442
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
double Area(bool aAbsolute=true) const
Return the area of this chain.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
double Area()
Return the area of this poly set.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
int OutlineCount() const
Return the number of outlines in the set.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
SHAPE_POLY_SET CloneDropTriangulation() const
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
TEARDROP_MANAGER manage and build teardrop areas A teardrop area is a polygonal area (a copper ZONE) ...
Definition teardrop.h:90
void UpdateTeardrops(BOARD_COMMIT &aCommit, const std::vector< BOARD_ITEM * > *dirtyPadsAndVias, const std::set< PCB_TRACK * > *dirtyTracks, bool aForceFullUpdate=false)
Update teardrops on a list of items.
Definition teardrop.cpp:225
Master controller class:
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:279
bool Fill(const std::vector< ZONE * > &aZones, bool aCheck=false, wxWindow *aParent=nullptr)
Fills the given list of zones.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetHatchThickness(int aThickness)
Definition zone.h:326
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
Definition zone.cpp:1393
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:697
void SetMinThickness(int aMinThickness)
Definition zone.h:316
double GetFilledArea()
This area is cached from the most recent call to CalculateFilledArea().
Definition zone.h:279
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition zone.h:251
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:619
SHAPE_POLY_SET * Outline()
Definition zone.h:418
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
Definition zone.cpp:601
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition zone.cpp:625
bool HasFilledPolysForLayer(PCB_LAYER_ID aLayer) const
Definition zone.h:688
void SetThievingSettings(const THIEVING_SETTINGS &aSettings)
Definition zone.h:352
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
Definition zone.cpp:610
void SetThermalReliefGap(int aThermalReliefGap)
Definition zone.h:240
bool AppendCorner(VECTOR2I aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition zone.cpp:1410
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
Definition zone.cpp:1841
void SetAssignedPriority(unsigned aPriority)
Definition zone.h:117
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition zone.h:313
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition zone.h:836
void SetHatchGap(int aStep)
Definition zone.h:329
unsigned GetAssignedPriority() const
Definition zone.h:122
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
@ ROUND_ALL_CORNERS
All angles are rounded.
@ DRCE_CLEARANCE
Definition drc_item.h:40
@ DRCE_COPPER_SLIVER
Definition drc_item.h:90
@ DRCE_CONNECTION_WIDTH
Definition drc_item.h:56
@ CLEARANCE_CONSTRAINT
Definition drc_rule.h:51
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
bool m_ZoneFillIterativeRefill
Enable iterative zone filling to handle isolated islands in higher priority zones.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ F_SilkS
Definition layer_ids.h:96
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
@ PTH
Plated through hole pad.
Definition padstack.h:98
CITER next(CITER it)
Definition ptree.cpp:120
@ RPT_SEVERITY_ERROR
const double epsilon
#define SKIP_SET_DIRTY
Definition sch_commit.h:38
#define SKIP_UNDO
Definition sch_commit.h:36
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
Parameters that drive copper-thieving fill generation.
EDA_ANGLE orientation
THIEVING_PATTERN pattern
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
VECTOR3I v1(5, 5, 5)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
const SHAPE_LINE_CHAIN chain
int clearance
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2I v2(1, 0)
static const std::vector< wxString > RegressionZoneFillTests_tests
int delta
static const std::vector< std::pair< wxString, int > > RegressionTeardropFill_tests
BOOST_DATA_TEST_CASE_F(ZONE_FILL_TEST_FIXTURE, RegressionZoneFillTests, boost::unit_test::data::make(RegressionZoneFillTests_tests), relPath)
static void CheckAllOutlineAreasAtLeast(const std::shared_ptr< SHAPE_POLY_SET > &aFill, double aMinArea, const wxString &aLabel)
Assert every outline in aFill has at least aMinArea — used to verify thieving stamps survived the fil...
static const std::vector< wxString > RegressionSliverZoneFillTests_tests
BOOST_FIXTURE_TEST_CASE(BasicZoneFills, ZONE_FILL_TEST_FIXTURE)
#define M_PI
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition zones.h:43
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ FULL
pads are covered by copper
Definition zones.h:47