21#include <boost/test/data/test_case.hpp>
51 double aMinArea,
const wxString& aLabel )
53 for(
int ii = 0; ii < aFill->OutlineCount(); ++ii )
55 const double area =
std::abs( aFill->Outline( ii ).Area() );
58 wxString::Format(
"%s %d area %.0f IU^2 below %.0f IU^2; partial "
59 "stamps should not survive.",
60 aLabel, ii, area, aMinArea ) );
90 for(
PAD*
pad : m_board->Footprints()[0]->Pads() )
92 if(
pad->GetNumber() ==
"2" ||
pad->GetNumber() ==
"4" ||
pad->GetNumber() ==
"6" )
103 for(
PCB_TRACK* track : m_board->Tracks() )
111 arc8 = track->m_Uuid;
112 track->SetWidth( track->GetWidth() +
delta +
delta );
116 arc12 = track->m_Uuid;
122 bool foundPad2Error =
false;
123 bool foundPad4Error =
false;
124 bool foundPad6Error =
false;
125 bool foundArc8Error =
false;
126 bool foundArc12Error =
false;
127 bool foundOtherError =
false;
132 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
133 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
137 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
138 PAD* pad_a =
dynamic_cast<PAD*
>( item_a );
141 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
142 PAD* pad_b =
dynamic_cast<PAD*
>( item_b );
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;
185 for(
ZONE* zone : m_board->Zones() )
187 if( zone->GetLayerSet().Contains(
F_Cu ) )
224 std::vector<DRC_ITEM> violations;
227 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
228 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
231 violations.push_back( *aItem );
236 if( violations.empty() )
245 std::map<KIID, EDA_ITEM*> itemMap;
246 m_board->FillItemMap( itemMap );
248 for(
const DRC_ITEM& item : violations )
251 BOOST_ERROR( wxString::Format(
"Zone fill regression: %s failed", relPath ) );
270 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
273 auto runDrcClearanceCheck =
274 [
this](
bool aIterative ) ->
int
285 std::vector<DRC_ITEM> violations;
287 std::map<KIID, EDA_ITEM*> itemMap;
288 m_board->FillItemMap( itemMap );
292 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
294 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
298 BOARD_ITEM* itemA = m_board->ResolveItem( aItem->GetMainItemID() );
299 BOARD_ITEM* itemB = m_board->ResolveItem( aItem->GetAuxItemID() );
301 if(
dynamic_cast<ZONE*
>( itemA ) &&
dynamic_cast<ZONE*
>( itemB ) )
303 violations.push_back( *aItem );
306 aItem->ShowReport( &unitsProvider,
314 return static_cast<int>( violations.size() );
317 int iterativeViolations = runDrcClearanceCheck(
true );
320 wxString::Format(
"Iterative refill produced %d zone-to-zone clearance "
321 "violations (expected 0)", iterativeViolations ) );
323 int nonIterativeViolations = runDrcClearanceCheck(
false );
326 wxString::Format(
"Non-iterative refill produced %d zone-to-zone clearance "
327 "violations (expected 0)", nonIterativeViolations ) );
346 std::vector<DRC_ITEM> violations;
349 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
350 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
353 violations.push_back( *aItem );
358 if( violations.empty() )
361 BOOST_TEST_MESSAGE( wxString::Format(
"Zone fill copper sliver regression: %s passed", relPath ) );
367 std::map<KIID, EDA_ITEM*> itemMap;
368 m_board->FillItemMap( itemMap );
370 for(
const DRC_ITEM& item : violations )
373 BOOST_ERROR( wxString::Format(
"Zone fill copper sliver regression: %s failed", relPath ) );
379 {
"teardrop_issue_JPC2", 5 },
386 const wxString& relPath =
test.first;
387 const int count =
test.second;
397 for(
ZONE* zone : m_board->Zones() )
399 if( zone->IsTeardropArea() )
404 << relPath <<
", found "
412 std::vector<wxString> tests = { {
"issue19956/issue19956" }
415 for(
const wxString& relPath : tests )
421 for(
ZONE* zone : m_board->Zones() )
425 std::shared_ptr<SHAPE> a_shape( zone->GetEffectiveShape( layer ) );
427 for(
PAD*
pad : m_board->GetPads() )
429 std::shared_ptr<SHAPE> pad_shape(
pad->GetEffectiveShape( layer ) );
430 int clearance = pad_shape->GetClearance( a_shape.get() );
432 wxString::Format(
"Pad %s from Footprint %s has net code %s and "
433 "is connected to zone with net code %s",
435 pad->GetParentFootprint()->GetReferenceAsString(),
437 zone->GetNetname() ) );
467 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } } guard{ cfg.
m_ZoneFillIterativeRefill, originalIterativeRefill };
474 ZONE* gndZone =
nullptr;
476 for(
ZONE* zone : m_board->Zones() )
478 if( zone->GetNetname() ==
"GND" )
485 BOOST_REQUIRE_MESSAGE( gndZone !=
nullptr,
"GND zone not found in test board" );
489 bool hasOutline = m_board->GetBoardPolygonOutlines( boardOutline,
true );
490 BOOST_REQUIRE_MESSAGE( hasOutline,
"Board outline not found" );
492 double boardArea = 0.0;
503 double fillRatio = gndFilledArea / boardArea;
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 ) );
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 "
515 fillRatio * 100.0 ) );
540 int viasWithUnreachableFlashing = 0;
541 int totalConditionalVias = 0;
543 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT(
"In1.Cu" ) );
544 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT(
"In2.Cu" ) );
546 for(
PCB_TRACK* track : m_board->Tracks() )
553 if( !
via->GetRemoveUnconnected() )
556 totalConditionalVias++;
559 bool flashedOnIn1 =
via->FlashLayer( in1Cu );
560 bool flashedOnIn2 =
via->FlashLayer( in2Cu );
562 if( !flashedOnIn1 && !flashedOnIn2 )
566 int holeRadius =
via->GetDrillValue() / 2;
569 bool zoneReachesVia =
false;
571 for(
ZONE* zone : m_board->Zones() )
573 if( zone->GetIsRuleArea() )
576 if( zone->GetNetCode() !=
via->GetNetCode() )
581 if( !zone->IsOnLayer( layer ) )
584 if( !zone->HasFilledPolysForLayer( layer ) )
587 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
589 if( fill->Contains( viaCenter, -1, holeRadius ) )
591 zoneReachesVia =
true;
601 if( !zoneReachesVia && ( flashedOnIn1 || flashedOnIn2 ) )
602 viasWithUnreachableFlashing++;
605 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional vias: %d, Vias with unreachable "
606 "flashing: %d", totalConditionalVias,
607 viasWithUnreachableFlashing ) );
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 ) );
635 int viasShortingZones = 0;
636 int totalConditionalVias = 0;
638 for(
PCB_TRACK* track : m_board->Tracks() )
645 if( !
via->GetRemoveUnconnected() )
648 totalConditionalVias++;
652 for(
ZONE* zone : m_board->Zones() )
654 if( zone->GetIsRuleArea() )
657 if( zone->GetNetCode() ==
via->GetNetCode() )
662 if( !
via->FlashLayer( layer ) )
665 if( !zone->HasFilledPolysForLayer( layer ) )
668 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
669 int viaRadius =
via->GetWidth( layer ) / 2;
671 if( fill->Contains( viaCenter, -1, viaRadius ) )
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() ) );
684 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional vias: %d, Vias shorting zones: %d",
685 totalConditionalVias, viasShortingZones ) );
688 wxString::Format(
"Found %d vias flashed on layers where they short to "
689 "zones with different nets. This indicates issue 12964 "
691 viasShortingZones ) );
709 KI_TEST::LoadBoard( m_settingsManager,
"hatch_thermal_connectivity/hatch_thermal_connectivity",
714 m_board->BuildConnectivity();
716 int unconnectedCount = m_board->GetConnectivity()->GetUnconnectedCount(
false );
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 ) );
746 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT(
"In1.Cu" ) );
748 ZONE* gndZone =
nullptr;
750 for(
ZONE* zone : m_board->Zones() )
752 if( zone->GetNetname() ==
"GND" && zone->IsOnLayer( in1Cu ) )
759 BOOST_REQUIRE_MESSAGE( gndZone !=
nullptr,
"GND zone on In1.Cu not found in test board" );
767 "GND zone has no fill on In1.Cu" );
775 double zoneOutlineArea = gndZone->
Outline()->
Area();
777 BOOST_REQUIRE_MESSAGE( zoneOutlineArea > 0.0,
"Zone outline area must be positive" );
779 double fillArea = 0.0;
781 for(
int i = 0; i < fill->OutlineCount(); i++ )
782 fillArea +=
std::abs( fill->Outline( i ).Area() );
784 double fillRatio = fillArea / zoneOutlineArea;
788 BOOST_CHECK_GE( fillRatio, 0.90 );
811 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
819 std::vector<ZONE*> keepouts;
821 for(
ZONE* zone : m_board->Zones() )
823 if( zone->GetIsRuleArea() && zone->GetDoNotAllowZoneFills() )
824 keepouts.push_back( zone );
827 BOOST_REQUIRE_MESSAGE( !keepouts.empty(),
"No zone keepouts found in test board" );
830 int violationCount = 0;
832 for(
ZONE* keepout : keepouts )
834 for(
PCB_LAYER_ID layer : keepout->GetLayerSet().Seq() )
839 for(
ZONE* zone : m_board->Zones() )
841 if( zone->GetIsRuleArea() )
844 if( !zone->IsOnLayer( layer ) )
847 if( !zone->HasFilledPolysForLayer( layer ) )
850 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
858 double intersectionArea = 0;
864 if( intersectionArea > 1e6 )
867 "Zone %s fill on layer %s overlaps keepout by %.2f sq mm",
869 m_board->GetLayerName( layer ),
870 intersectionArea / 1e6 ) );
879 wxString::Format(
"Found %d zone fills overlapping keepout areas. "
880 "This indicates issue 22809 - iterative refiller "
881 "ignores zone keepouts.", violationCount ) );
904 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT(
"In2.Cu" ) );
905 int padsWithMissingFlashing = 0;
906 int totalConditionalPads = 0;
908 for(
FOOTPRINT* footprint : m_board->Footprints() )
910 for(
PAD*
pad : footprint->Pads() )
912 if( !
pad->GetRemoveUnconnected() )
915 if( !
pad->HasHole() )
918 if(
pad->GetNetname() !=
"VBUS_DUT" &&
pad->GetNetname() !=
"VBUS_DBG" )
921 totalConditionalPads++;
924 bool shouldFlash =
false;
926 for(
ZONE* zone : m_board->Zones() )
928 if( zone->GetIsRuleArea() )
931 if( zone->GetNetCode() !=
pad->GetNetCode() )
934 if( !zone->IsOnLayer( in2Cu ) )
937 if( zone->Outline()->Contains(
pad->GetPosition() ) )
944 if( shouldFlash && !
pad->FlashLayer( in2Cu ) )
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++;
955 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional pads: %d, Pads with missing "
956 "flashing: %d", totalConditionalPads,
957 padsWithMissingFlashing ) );
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 ) );
980 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
990 if( !commit.
Empty() )
994 int teardropCount = 0;
995 bool foundBadTeardrop =
false;
997 for(
ZONE* zone : m_board->Zones() )
999 if( !zone->IsTeardropArea() )
1016 int concaveCount = 0;
1018 for(
int i = 0; i <
chain.PointCount(); i++ )
1020 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1021 int next = ( i + 1 ) %
chain.PointCount();
1027 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1037 if( concaveCount > 5 )
1040 "indicating possible corner intersection",
1042 foundBadTeardrop =
true;
1049 "Found teardrop with excessive concave vertices, indicating "
1050 "issue 19405 - teardrop curve intersecting rounded rectangle corner" );
1064 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1073 if( !commit.
Empty() )
1076 int teardropCount = 0;
1077 bool foundSpike =
false;
1079 const int maxError = m_board->GetDesignSettings().m_MaxError;
1081 for(
ZONE* zone : m_board->Zones() )
1083 if( !zone->IsTeardropArea() )
1089 int netcode = zone->GetNetCode();
1097 for(
FOOTPRINT* fp : m_board->Footprints() )
1099 for(
PAD*
pad : fp->Pads() )
1101 if(
pad->GetNetCode() == netcode &&
pad->IsOnLayer( layer ) )
1102 pad->TransformShapeToPolygon( corridor, layer, 0, maxError,
ERROR_OUTSIDE );
1106 for(
PCB_TRACK* track : m_board->Tracks() )
1108 if( track->GetNetCode() == netcode && track->IsOnLayer( layer ) )
1109 track->TransformShapeToPolygon( corridor, layer, 0, maxError,
ERROR_OUTSIDE );
1121 double tdArea =
std::abs( zone->Outline()->Area() );
1123 double ratio = tdArea > 0 ? outArea / tdArea : 0.0;
1126 "Teardrop on layer %d: area %.0f, area outside corridor %.0f (%.1f%%)",
1127 (
int) layer, tdArea, outArea, ratio * 100.0 ) );
1133 "Teardrop on layer %d sweeps %.1f%% of its area outside the track/pad "
1135 (
int) layer, ratio * 100.0 ) );
1141 "A teardrop vertex spikes outside the track/pad corridor it should "
1159 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1169 if( !commit.
Empty() )
1173 int teardropCount = 0;
1174 bool foundBadTeardrop =
false;
1176 for(
ZONE* zone : m_board->Zones() )
1178 if( !zone->IsTeardropArea() )
1192 int concaveCount = 0;
1194 for(
int i = 0; i <
chain.PointCount(); i++ )
1196 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1197 int next = ( i + 1 ) %
chain.PointCount();
1202 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1208 if( concaveCount > 5 )
1212 foundBadTeardrop =
true;
1219 "Found teardrop with excessive concave vertices on oval pad, "
1220 "indicating curve is not tangent to semicircular end" );
1237 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1247 if( !commit.
Empty() )
1251 PAD* largePad =
nullptr;
1253 for(
FOOTPRINT* fp : m_board->Footprints() )
1255 for(
PAD*
pad : fp->Pads() )
1265 BOOST_REQUIRE_MESSAGE( largePad !=
nullptr,
"Expected a circular pad in test board" );
1271 int teardropCount = 0;
1272 bool foundBadTeardrop =
false;
1274 for(
ZONE* zone : m_board->Zones() )
1276 if( !zone->IsTeardropArea() )
1289 int concaveCount = 0;
1291 for(
int i = 0; i <
chain.PointCount(); i++ )
1293 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1294 int next = ( i + 1 ) %
chain.PointCount();
1299 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1305 if( concaveCount > 5 )
1307 BOOST_TEST_MESSAGE( wxString::Format(
"Large circle teardrop has %d concave vertices",
1309 foundBadTeardrop =
true;
1314 int maxError = m_board->GetDesignSettings().m_MaxError;
1316 for(
int i = 0; i <
chain.PointCount(); i++ )
1319 double dist = ( pt - padCenter ).EuclideanNorm();
1322 if( dist > padRadius * 0.5 && dist < padRadius * 1.5 )
1324 double deviation =
std::abs( dist - padRadius );
1327 if( deviation > maxError * 5 && deviation < padRadius * 0.2 )
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 ) );
1341 "Found teardrop with excessive concave vertices on large circle, "
1342 "indicating anchor points may not be on circle edge" );
1366 for(
ZONE* zone : m_board->Zones() )
1368 if( zone->GetIsRuleArea() )
1373 if( !zone->HasFilledPolysForLayer( layer ) )
1376 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
1378 for(
PAD*
pad : m_board->GetPads() )
1380 if( !
pad->IsOnLayer( layer ) )
1383 if(
pad->GetNetCode() == zone->GetNetCode() )
1386 std::shared_ptr<SHAPE> padShape =
pad->GetEffectiveShape( layer );
1387 int clearance = padShape->GetClearance( fill.get() );
1392 "Pad %s (net %s) at (%d, %d) has zero clearance to zone %s "
1394 pad->GetNumber(),
pad->GetNetname(),
1395 pad->GetPosition().x,
pad->GetPosition().y,
1396 zone->GetNetname(), m_board->GetLayerName( layer ) ) );
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.",
1428 std::vector<DRC_ITEM> violations;
1433 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
1434 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
1438 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
1439 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
1441 ZONE* zone_a =
dynamic_cast<ZONE*
>( item_a );
1442 ZONE* zone_b =
dynamic_cast<ZONE*
>( item_b );
1444 if( zone_a || zone_b )
1445 violations.push_back( *aItem );
1472 ZONE* hvZone =
nullptr;
1473 ZONE* lvZone =
nullptr;
1475 for(
ZONE* zone : m_board->Zones() )
1477 if( zone->GetNetname() ==
"HV_NET" )
1479 else if( zone->GetNetname() ==
"LV_NET" )
1488 hvZone, lvZone,
F_Cu );
1491 <<
" (expected " <<
pcbIUScale.mmToIU( 4.6 ) <<
")" );
1496 hvZone, lvZone,
In1_Cu );
1499 <<
" (expected " <<
pcbIUScale.mmToIU( 2.3 ) <<
")" );
1506 std::vector<DRC_ITEM> violations;
1511 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
1512 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
1516 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
1517 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
1519 ZONE* zone_a =
dynamic_cast<ZONE*
>( item_a );
1520 ZONE* zone_b =
dynamic_cast<ZONE*
>( item_b );
1522 if( zone_a && zone_b )
1525 << aLayer <<
": " << aItem->GetErrorMessage(
true ) );
1526 violations.push_back( *aItem );
1539 KI_TEST::LoadBoard( m_settingsManager,
"issue23332_min_width/issue23332_min_width", m_board );
1545 for(
ZONE* zone : m_board->Zones() )
1547 int half_min_width = zone->GetMinThickness() / 2;
1554 if( !zone->HasFilledPolysForLayer( layer ) )
1557 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1559 if( !fill || fill->OutlineCount() == 0 )
1564 for(
int ii = 0; ii < fill->OutlineCount(); ii++ )
1569 for(
int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1570 island.
AddHole( fill->Hole( ii, jj ) );
1572 double originalArea = island.
Area();
1574 if( originalArea <= 0 )
1585 double prunedArea =
test.Area();
1586 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1589 "Zone %s layer %d island %d: area=%.0f, loss=%.4f%%",
1590 zone->GetNetname(),
static_cast<int>( layer ), ii,
1591 originalArea, areaLoss * 100.0 ) );
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,
1599 zone->GetMinThickness()
1600 /
static_cast<double>(
pcbIUScale.IU_PER_MM ) ) );
1615 for(
ZONE* zone : m_board->Zones() )
1617 int half_min_width = zone->GetMinThickness() / 2;
1624 if( !zone->HasFilledPolysForLayer( layer ) )
1627 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1629 if( !fill || fill->OutlineCount() == 0 )
1632 for(
int ii = 0; ii < fill->OutlineCount(); ii++ )
1637 for(
int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1638 island.
AddHole( fill->Hole( ii, jj ) );
1640 double originalArea = island.
Area();
1642 if( originalArea <= 0 )
1653 double prunedArea =
test.Area();
1654 double areaLoss = ( originalArea - prunedArea ) / originalArea;
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",
1662 zone->GetAssignedPriority(),
1663 static_cast<int>( layer ), ii,
1664 areaLoss * 100.0 ) );
1676 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
1679 auto runAreaLossCheck =
1680 [
this](
bool aIterative )
1690 for(
ZONE* zone : m_board->Zones() )
1692 int half_min_width = zone->GetMinThickness() / 2;
1699 if( !zone->HasFilledPolysForLayer( layer ) )
1702 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1704 if( !fill || fill->OutlineCount() == 0 )
1707 for(
int ii = 0; ii < fill->OutlineCount(); ii++ )
1712 for(
int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1713 island.
AddHole( fill->Hole( ii, jj ) );
1715 double originalArea = island.
Area();
1717 if( originalArea <= 0 )
1728 double prunedArea =
test.Area();
1729 double areaLoss = ( originalArea - prunedArea ) / originalArea;
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,
1745 runAreaLossCheck(
false );
1746 runAreaLossCheck(
true );
1771 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
1774 KI_TEST::LoadBoard( m_settingsManager,
"issue23535_minimal/issue23535_minimal", m_board );
1778 ZONE* gndZone =
nullptr;
1780 for(
ZONE* zone : m_board->Zones() )
1782 if( zone->GetNetname() ==
"GND" )
1800 bool hasSpokeToNowhere = gndFill->Contains( spokeTestPoint );
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)." );
1811 bool hasValidSpoke = gndFill->Contains( validSpokePoint );
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." );
1833 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1842 if( !commit.
Empty() )
1850 int teardropCount = 0;
1852 for(
ZONE* zone : m_board->Zones() )
1854 if( !zone->IsTeardropArea() )
1872 for(
int i = 0; i <
chain.PointCount(); i++ )
1874 int dy =
chain.CPoint( i ).y - trackY;
1877 maxAbove = std::max( maxAbove, -dy );
1879 maxBelow = std::max( maxBelow, dy );
1884 "Teardrop should extend on both sides of the track axis" );
1886 if( maxAbove > 0 && maxBelow > 0 )
1890 double ratio =
static_cast<double>( std::min( maxAbove, maxBelow ) )
1891 /
static_cast<double>( std::max( maxAbove, maxBelow ) );
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 ) );
1901 BOOST_CHECK_MESSAGE( teardropCount > 0,
"Expected at least one teardrop zone for off-center track" );
1918 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1927 if( !commit.
Empty() )
1933 PAD* testPad =
nullptr;
1935 for(
FOOTPRINT* fp : m_board->Footprints() )
1937 for(
PAD*
pad : fp->Pads() )
1939 if(
pad->GetNumber() ==
"7" )
1947 BOOST_REQUIRE_MESSAGE( testPad !=
nullptr,
"Could not find pad 7 in test board" );
1950 int tolerance = std::max( m_board->GetDesignSettings().m_MaxError,
1956 int teardropCount = 0;
1958 for(
ZONE* zone : m_board->Zones() )
1960 if( !zone->IsTeardropArea() )
1965 BOOST_REQUIRE_MESSAGE( outline && outline->
OutlineCount() > 0,
1966 "Teardrop zone has no outline" );
1980 for(
int i = 0; i <
chain.PointCount(); i++ )
1983 double distToPad = (
VECTOR2D( pt ) -
VECTOR2D( padCenter ) ).EuclideanNorm();
1984 double distToTrack = (
VECTOR2D( pt ) -
VECTOR2D( trackAnchor ) ).EuclideanNorm();
1987 if( distToPad < distToTrack )
1991 wxString::Format(
"Teardrop vertex (%d, %d) is outside the pad "
1992 "outline with %d nm tolerance",
1993 pt.
x, pt.
y, tolerance ) );
1999 "Expected at least one teardrop zone for elongated pad" );
2013 auto runVariant = [&](
bool aCurvedEdges )
2017 for(
PCB_TRACK* track : m_board->Tracks() )
2021 static_cast<PCB_VIA*
>( track )->SetTeardropCurved( aCurvedEdges );
2027 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
2036 if( !commit.
Empty() )
2039 int teardropCount = 0;
2040 bool foundSelfIntersection =
false;
2042 for(
ZONE* zone : m_board->Zones() )
2044 if( !zone->IsTeardropArea() )
2055 int n =
chain.PointCount();
2057 for(
int i = 0; i < n && !foundSelfIntersection; i++ )
2059 SEG segA(
chain.CPoint( i ),
chain.CPoint( ( i + 1 ) % n ) );
2061 for(
int j = i + 2; j < n; j++ )
2063 if( i == 0 && j == n - 1 )
2066 SEG segB(
chain.CPoint( j ),
chain.CPoint( ( j + 1 ) % n ) );
2069 if( hit.has_value() )
2072 "Self-intersection at (%d, %d) between edges %d and %d "
2074 hit->x, hit->y, i, j,
2075 aCurvedEdges ?
"yes" :
"no" ) );
2077 for(
int k = 0; k < n; k++ )
2080 " pt[%d] = (%d, %d)", k,
2081 chain.CPoint( k ).x,
chain.CPoint( k ).y ) );
2084 foundSelfIntersection =
true;
2092 wxString::Format(
"Expected at least one teardrop zone "
2094 aCurvedEdges ?
"yes" :
"no" ) );
2097 wxString::Format(
"Teardrop polygon has self-intersecting "
2098 "edges (curved=%s)",
2099 aCurvedEdges ?
"yes" :
"no" ) );
2103 runVariant(
false );
2127 auto runVariant = [&](
bool aCurvedEdges )
2134 for(
PCB_TRACK* track : m_board->Tracks() )
2139 via->SetTeardropCurved( aCurvedEdges );
2140 viaPos =
via->GetPosition();
2149 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
2158 if( !commit.
Empty() )
2163 const double maxBackSideDist = viaRadius * 1.2;
2164 int teardropCount = 0;
2165 int spikingPoints = 0;
2167 double worstDistance = 0.0;
2169 for(
ZONE* zone : m_board->Zones() )
2171 if( !zone->IsTeardropArea() )
2183 for(
int i = 0; i <
chain.PointCount(); i++ )
2194 if( dist > maxBackSideDist )
2198 if( dist > worstDistance )
2200 worstDistance = dist;
2208 wxString::Format(
"Expected no teardrop on grazing-entry "
2209 "track (emergence below track width), got "
2212 aCurvedEdges ?
"yes" :
"no" ) );
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)",
2219 worstPoint.
x, worstPoint.
y,
2221 aCurvedEdges ?
"yes" :
"no" ) );
2225 runVariant(
false );
2243 auto runVariant = [&](
bool aCurvedEdges )
2247 for(
PCB_TRACK* track : m_board->Tracks() )
2251 static_cast<PCB_VIA*
>( track )->SetTeardropCurved( aCurvedEdges );
2257 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
2266 if( !commit.
Empty() )
2269 int teardropCount = 0;
2270 int selfIntersectingCount = 0;
2273 for(
ZONE* zone : m_board->Zones() )
2275 if( !zone->IsTeardropArea() )
2286 int n =
chain.PointCount();
2287 bool intersected =
false;
2289 for(
int i = 0; i < n && !intersected; i++ )
2291 SEG segA(
chain.CPoint( i ),
chain.CPoint( ( i + 1 ) % n ) );
2293 for(
int j = i + 2; j < n; j++ )
2295 if( i == 0 && j == n - 1 )
2298 SEG segB(
chain.CPoint( j ),
chain.CPoint( ( j + 1 ) % n ) );
2301 if( hit.has_value() )
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" ) );
2308 worstPoint = hit.value();
2316 selfIntersectingCount++;
2320 wxString::Format(
"Expected at least one teardrop zone "
2322 aCurvedEdges ?
"yes" :
"no" ) );
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" ) );
2333 runVariant(
false );
2349 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
2352 auto getTotalFilledArea =
2357 for(
ZONE* zone : m_board->Zones() )
2359 if( zone->GetIsRuleArea() )
2364 if( !zone->HasFilledPolysForLayer( layer ) )
2367 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
2377 auto refillAndMeasure =
2378 [
this, &cfg, &getTotalFilledArea](
bool aIterative ) ->
double
2384 double storedArea = getTotalFilledArea();
2386 BOOST_REQUIRE_MESSAGE( storedArea > 0,
"Stored v9 fill has zero area" );
2389 return getTotalFilledArea();
2394 double storedArea = getTotalFilledArea();
2396 BOOST_REQUIRE_MESSAGE( storedArea > 0,
"Stored v9 fill has zero area" );
2398 double nonIterativeArea = refillAndMeasure(
false );
2399 double iterativeArea = refillAndMeasure(
true );
2400 double nonIterativeAreaRatio = nonIterativeArea / storedArea;
2401 double iterativeAreaRatio = iterativeArea / storedArea;
2404 nonIterativeAreaRatio > 0.99999,
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 ) );
2413 iterativeAreaRatio > 0.99999,
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 ) );
2433 m_board = std::make_unique<BOARD>();
2436 m_board->SetCopperLayerCount( 2 );
2445 m_board->Add( gndNet );
2457 int hatchThickness =
pcbIUScale.mmToIU( 0.3 );
2466 via->SetPosition( viaPos );
2468 via->SetDrill( viaDrill );
2470 via->SetNetCode( gndNetCode );
2471 m_board->Add(
via );
2475 auto makeHatchZone =
2478 ZONE* zone =
new ZONE( m_board.get() );
2497 m_board->Add( zone );
2504 m_board->BuildConnectivity();
2505 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
2506 drcEngine->InitEngine( wxFileName() );
2518 double fullFillArea = 0.0;
2519 double thermalFillArea = 0.0;
2530 "Zone should have fill on F.Cu with FULL connection" );
2534 for(
int i = 0; i < fill->OutlineCount(); i++ )
2535 fullFillArea +=
std::abs( fill->Outline( i ).Area() );
2537 m_board->Remove(
via );
2538 m_board->Remove( zone );
2552 "Zone should have fill on F.Cu with THERMAL connection" );
2556 for(
int i = 0; i < fill->OutlineCount(); i++ )
2557 thermalFillArea +=
std::abs( fill->Outline( i ).Area() );
2559 m_board->Remove(
via );
2560 m_board->Remove( zone );
2569 double areaThreshold = 0.2 * iuPerMM * iuPerMM;
2571 double areaIU2toMM2 = 1.0 / ( iuPerMM * iuPerMM );
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 ) );
2592 m_board = std::make_unique<BOARD>();
2593 m_board->SetCopperLayerCount( 2 );
2600 m_board->Add( gndNet );
2609 int hatchThickness =
pcbIUScale.mmToIU( 0.3 );
2611 auto makeHatchZone = [&]() ->
ZONE*
2613 ZONE* zone =
new ZONE( m_board.get() );
2630 m_board->Add( zone );
2636 const int steps = 8;
2637 const double startMM = 9.0;
2638 const double stepMM = 2.3 / steps;
2640 int isolatedCount = 0;
2641 int testedCount = 0;
2643 for(
int ix = 0; ix < steps; ix++ )
2645 for(
int iy = 0; iy < steps; iy++ )
2650 via->SetPosition( viaPos );
2652 via->SetDrill( viaDrill );
2654 via->SetNetCode( gndNetCode );
2655 m_board->Add(
via );
2657 ZONE* zone = makeHatchZone();
2659 m_board->BuildConnectivity();
2660 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
2661 drcEngine->InitEngine( wxFileName() );
2669 std::shared_ptr<SHAPE> viaShape =
via->GetEffectiveShape(
F_Cu );
2673 if( !fill->Collide( viaShape.get(), 0 ) )
2678 m_board->Remove(
via );
2679 m_board->Remove( zone );
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 ) );
2718 ~ScopeGuard() { ref = orig; }
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;
2728 for(
ZONE* zone : m_board->Zones() )
2729 zoneByName[zone->GetZoneName().ToStdString()] = zone;
2731 for(
const std::string&
name : checkedNames )
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" );
2739 for(
const std::string&
name : {
"hi3",
"hi5",
"hi7" } )
2741 int islands = zoneByName[
name]->GetFilledPolysList(
F_Cu )->OutlineCount();
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.",
2749 for(
const std::string&
name : {
"lo1",
"lo2",
"lo3",
"lo4",
"lo5",
"lo6",
"hi2",
"hi4",
"hi6" } )
2751 int islands = zoneByName[
name]->GetFilledPolysList(
F_Cu )->OutlineCount();
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.",
2772 ZONE* thievingZone =
nullptr;
2774 for(
ZONE* z : m_board->Zones() )
2791 BOOST_CHECK_GE( fill->OutlineCount(), 2 );
2794 BOX2I fillBox = fill->BBox();
2801 BOOST_CHECK_GT( fill->TotalVertices(), 200 );
2827 ~ScopeGuard() { ref = orig; }
2831 class WarningCapture :
public wxLog
2834 bool m_hadWarning =
false;
2837 void DoLogRecord( wxLogLevel aLevel,
const wxString&,
const wxLogRecordInfo& )
override
2839 if( aLevel == wxLOG_Warning )
2840 m_hadWarning =
true;
2844 auto* capture =
new WarningCapture();
2845 wxLog* oldLog = wxLog::SetActiveTarget( capture );
2850 ~LogGuard() { wxLog::SetActiveTarget( old ); }
2851 } logGuard{ oldLog };
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." );
2869 m_board = std::make_unique<BOARD>();
2871 ZONE* zone =
new ZONE( m_board.get() );
2885 m_board->Add( zone );
2894 BOOST_CHECK_GT( fill->OutlineCount(), 5 );
2907 m_board = std::make_unique<BOARD>();
2908 m_board->SetCopperLayerCount( 2 );
2911 ZONE* zone =
new ZONE( m_board.get() );
2931 m_board->Add( zone );
2937 BOOST_REQUIRE_GT( fill->OutlineCount(), 0 );
2941 BOOST_CHECK_GE( fill->OutlineCount(), 6 );
2942 BOOST_CHECK_LE( fill->OutlineCount(), 12 );
2945 const double fullDotArea =
M_PI * std::pow(
pcbIUScale.mmToIU( 0.25 ), 2 );
2958 auto countDots = [](
bool stagger ) ->
int
2960 auto board = std::make_unique<BOARD>();
2961 board->SetCopperLayerCount( 2 );
2963 ZONE* zone =
new ZONE( board.get() );
2984 int plain = countDots(
false );
2985 int staggered = countDots(
true );
2991 BOOST_CHECK_NE( plain, staggered );
2992 BOOST_CHECK_GE( staggered, plain / 2 );
2993 BOOST_CHECK_LE( staggered, plain * 2 );
3004 m_board = std::make_unique<BOARD>();
3005 m_board->SetCopperLayerCount( 2 );
3007 ZONE* zone =
new ZONE( m_board.get() );
3021 m_board->Add( zone );
3027 BOOST_REQUIRE_GT( fill->OutlineCount(), 0 );
3031 BOOST_CHECK_GE( fill->OutlineCount(), 6 );
3032 BOOST_CHECK_LE( fill->OutlineCount(), 12 );
3034 const double fullSquareArea = std::pow(
pcbIUScale.mmToIU( 0.6 ), 2 );
3049 m_board = std::make_unique<BOARD>();
3050 m_board->SetCopperLayerCount( 2 );
3052 ZONE* zone =
new ZONE( m_board.get() );
3066 m_board->Add( zone );
3068 auto start = std::chrono::steady_clock::now();
3070 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
3071 std::chrono::steady_clock::now() - start )
3081 BOOST_CHECK_LT( elapsed, 30000 );
3093 m_board = std::make_unique<BOARD>();
3094 m_board->SetCopperLayerCount( 2 );
3096 ZONE* zone =
new ZONE( m_board.get() );
3110 m_board->Add( zone );
3116 BOOST_REQUIRE_GT( fill->TotalVertices(), 0 );
3126 BOX2I fillBox = fill->BBox();
3134 BOOST_CHECK_GT( fill->TotalVertices(), 30 );
3154 for(
ZONE* zone : m_board->Zones() )
3156 if( zone->GetIsRuleArea() )
3161 if( !zone->HasFilledPolysForLayer( layer ) )
3164 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
3167 total += fill->OutlineCount();
3174 int storedIslands = countIslands();
3176 BOOST_REQUIRE_MESSAGE( storedIslands >= 3,
3177 wxString::Format(
"Stored v9 fill should have at least 3 silk islands; "
3183 int refilledIslands = countIslands();
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 ) );
3200 m_board = std::make_unique<BOARD>();
3201 m_board->SetCopperLayerCount( 4 );
3208 m_board->Add( gndNet );
3212 m_board->Add( vccNet );
3215 ZONE* gndZone =
new ZONE( m_board.get() );
3232 m_board->Add( gndZone );
3234 ZONE* vccZone =
new ZONE( m_board.get() );
3258 m_board->Add( vccZone );
3262 auto footprint = std::make_unique<FOOTPRINT>( m_board.get() );
3272 pad->SetNetCode( gndNetCode );
3274 footprint->Add(
pad );
3275 footprint->SetPosition(
VECTOR2I( 0, 0 ) );
3276 m_board->Add( footprint.release() );
3278 m_board->BuildConnectivity();
3279 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
3280 drcEngine->InitEngine( wxFileName() );
3288 "VCC outline must contain the pad position to reproduce issue 24175." );
3290 "VCC zone should still have fill in its right lobe." );
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)." );
3303 "PTH pad inside higher-priority different-net zone must still flash "
3304 "when a same-net lower-priority zone covers it (issue 24175)." );
3307 "GND zone should have fill on In1.Cu" );
3314 bool foundCopperAround =
false;
3316 for(
int i = 0; i < samples; i++ )
3318 double angle = ( 2.0 *
M_PI * i ) / samples;
3320 pad->GetPosition().y +
KiROUND( sampleR * std::sin( angle ) ) );
3322 if( gndFill->Contains( p ) )
3324 foundCopperAround =
true;
3330 "Lower-priority GND zone should have copper around GND pad even when "
3331 "a higher-priority different-net zone outline contains the pad "
3354 PCB_LAYER_ID targetLayer = m_board->GetLayerID( wxT(
"B.Cu" ) );
3355 std::vector<ZONE*> toFill;
3357 for(
ZONE* zone : m_board->Zones() )
3359 if( zone->GetIsRuleArea() )
3362 if( !zone->IsOnLayer( targetLayer ) )
3365 if( zone->IsFilled() )
3368 toFill.push_back( zone );
3371 BOOST_REQUIRE_MESSAGE( !toFill.empty(),
3372 "Expected at least one unfilled B.Cu zone to exercise the API path." );
3379 BOOST_CHECK_NO_THROW( filler.
Fill( toFill ) );
3393 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
3401 const int margin =
pcbIUScale.mmToIU( 0.05 );
3403 std::map<int, SHAPE_POLY_SET> mergedByNet;
3405 for(
ZONE* zone : m_board->Zones() )
3407 if( zone->GetIsRuleArea() || !zone->HasFilledPolysForLayer( layer ) )
3410 mergedByNet[zone->GetNetCode()].BooleanAdd( *zone->GetFilledPolysList( layer ) );
3415 auto buildLegitVoids =
3421 for(
ZONE* other : m_board->Zones() )
3423 if( !other->GetLayerSet().Contains( layer ) )
3426 if( other->GetIsRuleArea() )
3428 if( other->GetDoNotAllowZoneFills() )
3434 if( other->GetNetCode() == aLower->
GetNetCode()
3436 || other->GetAssignedPriority() <= aHigher->GetAssignedPriority()
3437 || !other->HasFilledPolysForLayer( layer ) )
3450 std::vector<ZONE*> zones;
3452 for(
ZONE* zone : m_board->Zones() )
3454 if( !zone->GetIsRuleArea() && zone->GetNetCode() > 0 && zone->GetLayerSet().Contains( layer ) )
3455 zones.push_back( zone );
3458 int checkedPairs = 0;
3460 for(
size_t i = 0; i < zones.size(); ++i )
3462 for(
size_t j = i + 1; j < zones.size(); ++j )
3477 const ZONE* higher = ( lower == a ) ? b : a;
3490 double uncoveredArea =
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).",
3504 wxString::Format(
"Expected at least two overlapping same-net zone pairs "
3505 "to exercise the merge, found %d.", checkedPairs ) );
3518 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
3526 for(
int pass = 0; pass < 64; ++pass )
3534 for(
ZONE* zone : m_board->Zones() )
3536 if( zone->GetIsRuleArea() || !zone->HasFilledPolysForLayer( layer ) )
3539 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
3546 wxString::Format(
"Fill pass %d produced no copper.", pass ) );
3560 auto outlineNoArcs =
3568 int checkedPairs = 0;
3570 for(
ZONE* hatch : m_board->Zones() )
3573 || !hatch->HasFilledPolysForLayer( layer ) )
3581 for(
ZONE* other : m_board->Zones() )
3583 if( other == hatch || other->GetIsRuleArea() || !other->GetLayerSet().Contains( layer )
3584 || other->GetAssignedPriority() <= hatch->GetAssignedPriority() )
3607 if( band.
Area() <= 0 )
3613 double coverage = covered.
Area() / band.
Area();
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 ) );
3626 wxString::Format(
"Expected at least three carved hatch borders to check, "
3627 "found %d.", checkedPairs ) );
3635 m_board = std::make_unique<BOARD>();
3646 m_board->Add( netA );
3647 m_board->Add( netB );
3653 const int sep =
clearance + extraMargin + maxError / 2;
3654 const int ax =
pcbIUScale.mmToIU( 100 ) + sep;
3656 ZONE* zoneA =
new ZONE( m_board.get() );
3664 m_board->Add( zoneA );
3668 ZONE* zoneB =
new ZONE( m_board.get() );
3677 for(
int ii = 0; ii < 1000; ++ii )
3685 m_board->Add( zoneB );
3698 "Lower-priority zone filled before the higher-priority knockout was "
3699 "published; the fill depends on thread scheduling." );
3724 std::vector<DRC_ITEM> violations;
3727 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
3728 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
3731 violations.push_back( *aItem );
3736 if( !violations.empty() )
3740 std::map<KIID, EDA_ITEM*> itemMap;
3741 m_board->FillItemMap( itemMap );
3743 for(
const DRC_ITEM& item : violations )
3748 wxString::Format(
"Zone fill produced %zu connection_width violations; "
3749 "expected 0 (issue 24312).",
3750 violations.size() ) );
constexpr int ARC_HIGH_DEF
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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...
constexpr coord_type GetLeft() const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
const MINOPTMAX< int > & GetValue() const
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).
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.
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
void SetClearance(int aClearance)
Handle the data for a net.
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
const wxString & GetNumber() const
VECTOR2I GetPosition() const override
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.
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
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) ...
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.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
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.
void SetHatchThickness(int aThickness)
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
void SetMinThickness(int aMinThickness)
double GetFilledArea()
This area is cached from the most recent call to CalculateFilledArea().
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
SHAPE_POLY_SET * Outline()
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
void SetFillMode(ZONE_FILL_MODE aFillMode)
bool HasFilledPolysForLayer(PCB_LAYER_ID aLayer) const
void SetThievingSettings(const THIEVING_SETTINGS &aSettings)
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
void SetThermalReliefGap(int aThermalReliefGap)
bool AppendCorner(VECTOR2I aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
void SetAssignedPriority(unsigned aPriority)
void SetPadConnection(ZONE_CONNECTION aPadConnection)
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
void SetHatchGap(int aStep)
unsigned GetAssignedPriority() const
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
@ ROUND_ALL_CORNERS
All angles are rounded.
static constexpr EDA_ANGLE ANGLE_0
bool m_ZoneFillIterativeRefill
Enable iterative zone filling to handle isolated islands in higher priority zones.
PCB_LAYER_ID
A quick note on layer IDs:
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)
@ PTH
Plated through hole pad.
@ REMOVE_EXCEPT_START_AND_END
std::optional< VECTOR2I > OPT_VECTOR2I
Parameters that drive copper-thieving fill generation.
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
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
BOOST_CHECK_EQUAL(result, "25.4")
static const std::vector< wxString > RegressionZoneFillTests_tests
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)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
ZONE_CONNECTION
How pads are covered by copper in zone.
@ THERMAL
Use thermal relief for pads.
@ FULL
pads are covered by copper