21#include <boost/test/data/test_case.hpp>
48 double aMinArea,
const wxString& aLabel )
50 for(
int ii = 0; ii < aFill->OutlineCount(); ++ii )
52 const double area =
std::abs( aFill->Outline( ii ).Area() );
55 wxString::Format(
"%s %d area %.0f IU^2 below %.0f IU^2; partial "
56 "stamps should not survive.",
57 aLabel, ii, area, aMinArea ) );
87 for(
PAD*
pad : m_board->Footprints()[0]->Pads() )
89 if(
pad->GetNumber() ==
"2" ||
pad->GetNumber() ==
"4" ||
pad->GetNumber() ==
"6" )
100 for(
PCB_TRACK* track : m_board->Tracks() )
108 arc8 = track->m_Uuid;
109 track->SetWidth( track->GetWidth() +
delta +
delta );
113 arc12 = track->m_Uuid;
119 bool foundPad2Error =
false;
120 bool foundPad4Error =
false;
121 bool foundPad6Error =
false;
122 bool foundArc8Error =
false;
123 bool foundArc12Error =
false;
124 bool foundOtherError =
false;
129 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
130 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
134 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
135 PAD* pad_a =
dynamic_cast<PAD*
>( item_a );
138 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
139 PAD* pad_b =
dynamic_cast<PAD*
>( item_b );
142 if( pad_a && pad_a->
GetNumber() ==
"2" ) foundPad2Error =
true;
143 else if( pad_a && pad_a->
GetNumber() ==
"4" ) foundPad4Error =
true;
144 else if( pad_a && pad_a->
GetNumber() ==
"6" ) foundPad6Error =
true;
145 else if( pad_b && pad_b->
GetNumber() ==
"2" ) foundPad2Error =
true;
146 else if( pad_b && pad_b->
GetNumber() ==
"4" ) foundPad4Error =
true;
147 else if( pad_b && pad_b->
GetNumber() ==
"6" ) foundPad6Error =
true;
148 else if( trk_a && trk_a->
m_Uuid == arc8 ) foundArc8Error =
true;
149 else if( trk_a && trk_a->
m_Uuid == arc12 ) foundArc12Error =
true;
150 else if( trk_b && trk_b->
m_Uuid == arc8 ) foundArc8Error =
true;
151 else if( trk_b && trk_b->
m_Uuid == arc12 ) foundArc12Error =
true;
152 else foundOtherError =
true;
182 for(
ZONE* zone : m_board->Zones() )
184 if( zone->GetLayerSet().Contains(
F_Cu ) )
221 std::vector<DRC_ITEM> violations;
224 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
225 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
228 violations.push_back( *aItem );
233 if( violations.empty() )
242 std::map<KIID, EDA_ITEM*> itemMap;
243 m_board->FillItemMap( itemMap );
245 for(
const DRC_ITEM& item : violations )
248 BOOST_ERROR( wxString::Format(
"Zone fill regression: %s failed", relPath ) );
267 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
270 auto runDrcClearanceCheck =
271 [
this](
bool aIterative ) ->
int
282 std::vector<DRC_ITEM> violations;
284 std::map<KIID, EDA_ITEM*> itemMap;
285 m_board->FillItemMap( itemMap );
289 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
291 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
295 BOARD_ITEM* itemA = m_board->ResolveItem( aItem->GetMainItemID() );
296 BOARD_ITEM* itemB = m_board->ResolveItem( aItem->GetAuxItemID() );
298 if(
dynamic_cast<ZONE*
>( itemA ) &&
dynamic_cast<ZONE*
>( itemB ) )
300 violations.push_back( *aItem );
303 aItem->ShowReport( &unitsProvider,
311 return static_cast<int>( violations.size() );
314 int iterativeViolations = runDrcClearanceCheck(
true );
317 wxString::Format(
"Iterative refill produced %d zone-to-zone clearance "
318 "violations (expected 0)", iterativeViolations ) );
320 int nonIterativeViolations = runDrcClearanceCheck(
false );
323 wxString::Format(
"Non-iterative refill produced %d zone-to-zone clearance "
324 "violations (expected 0)", nonIterativeViolations ) );
343 std::vector<DRC_ITEM> violations;
346 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
347 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
350 violations.push_back( *aItem );
355 if( violations.empty() )
358 BOOST_TEST_MESSAGE( wxString::Format(
"Zone fill copper sliver regression: %s passed", relPath ) );
364 std::map<KIID, EDA_ITEM*> itemMap;
365 m_board->FillItemMap( itemMap );
367 for(
const DRC_ITEM& item : violations )
370 BOOST_ERROR( wxString::Format(
"Zone fill copper sliver regression: %s failed", relPath ) );
376 {
"teardrop_issue_JPC2", 5 },
383 const wxString& relPath =
test.first;
384 const int count =
test.second;
394 for(
ZONE* zone : m_board->Zones() )
396 if( zone->IsTeardropArea() )
401 << relPath <<
", found "
409 std::vector<wxString> tests = { {
"issue19956/issue19956" }
412 for(
const wxString& relPath : tests )
418 for(
ZONE* zone : m_board->Zones() )
422 std::shared_ptr<SHAPE> a_shape( zone->GetEffectiveShape( layer ) );
424 for(
PAD*
pad : m_board->GetPads() )
426 std::shared_ptr<SHAPE> pad_shape(
pad->GetEffectiveShape( layer ) );
427 int clearance = pad_shape->GetClearance( a_shape.get() );
429 wxString::Format(
"Pad %s from Footprint %s has net code %s and "
430 "is connected to zone with net code %s",
432 pad->GetParentFootprint()->GetReferenceAsString(),
434 zone->GetNetname() ) );
464 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } } guard{ cfg.
m_ZoneFillIterativeRefill, originalIterativeRefill };
471 ZONE* gndZone =
nullptr;
473 for(
ZONE* zone : m_board->Zones() )
475 if( zone->GetNetname() ==
"GND" )
482 BOOST_REQUIRE_MESSAGE( gndZone !=
nullptr,
"GND zone not found in test board" );
486 bool hasOutline = m_board->GetBoardPolygonOutlines( boardOutline,
true );
487 BOOST_REQUIRE_MESSAGE( hasOutline,
"Board outline not found" );
489 double boardArea = 0.0;
500 double fillRatio = gndFilledArea / boardArea;
502 BOOST_TEST_MESSAGE( wxString::Format(
"Board area: %.2f sq mm, GND filled area: %.2f sq mm, "
503 "Fill ratio: %.1f%%",
504 boardArea / 1e6, gndFilledArea / 1e6,
505 fillRatio * 100.0 ) );
508 wxString::Format(
"GND zone fill ratio %.1f%% is less than expected 25%%. "
509 "This indicates issue 21746 - lower priority zones not "
510 "filling areas where higher priority isolated islands "
512 fillRatio * 100.0 ) );
537 int viasWithUnreachableFlashing = 0;
538 int totalConditionalVias = 0;
540 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT(
"In1.Cu" ) );
541 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT(
"In2.Cu" ) );
543 for(
PCB_TRACK* track : m_board->Tracks() )
550 if( !
via->GetRemoveUnconnected() )
553 totalConditionalVias++;
556 bool flashedOnIn1 =
via->FlashLayer( in1Cu );
557 bool flashedOnIn2 =
via->FlashLayer( in2Cu );
559 if( !flashedOnIn1 && !flashedOnIn2 )
563 int holeRadius =
via->GetDrillValue() / 2;
566 bool zoneReachesVia =
false;
568 for(
ZONE* zone : m_board->Zones() )
570 if( zone->GetIsRuleArea() )
573 if( zone->GetNetCode() !=
via->GetNetCode() )
578 if( !zone->IsOnLayer( layer ) )
581 if( !zone->HasFilledPolysForLayer( layer ) )
584 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
586 if( fill->Contains( viaCenter, -1, holeRadius ) )
588 zoneReachesVia =
true;
598 if( !zoneReachesVia && ( flashedOnIn1 || flashedOnIn2 ) )
599 viasWithUnreachableFlashing++;
602 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional vias: %d, Vias with unreachable "
603 "flashing: %d", totalConditionalVias,
604 viasWithUnreachableFlashing ) );
607 wxString::Format(
"Found %d vias flashed on zone layers where the zone "
608 "fill doesn't actually reach them. This indicates "
609 "issue 22010 is not fixed.",
610 viasWithUnreachableFlashing ) );
632 int viasShortingZones = 0;
633 int totalConditionalVias = 0;
635 for(
PCB_TRACK* track : m_board->Tracks() )
642 if( !
via->GetRemoveUnconnected() )
645 totalConditionalVias++;
649 for(
ZONE* zone : m_board->Zones() )
651 if( zone->GetIsRuleArea() )
654 if( zone->GetNetCode() ==
via->GetNetCode() )
659 if( !
via->FlashLayer( layer ) )
662 if( !zone->HasFilledPolysForLayer( layer ) )
665 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
666 int viaRadius =
via->GetWidth( layer ) / 2;
668 if( fill->Contains( viaCenter, -1, viaRadius ) )
671 "Via at (%d, %d) on net %s is flashing on layer %s where zone "
672 "net %s is filled - this creates a short!",
673 viaCenter.
x, viaCenter.
y,
via->GetNetname(),
674 m_board->GetLayerName( layer ), zone->GetNetname() ) );
681 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional vias: %d, Vias shorting zones: %d",
682 totalConditionalVias, viasShortingZones ) );
685 wxString::Format(
"Found %d vias flashed on layers where they short to "
686 "zones with different nets. This indicates issue 12964 "
688 viasShortingZones ) );
706 KI_TEST::LoadBoard( m_settingsManager,
"hatch_thermal_connectivity/hatch_thermal_connectivity",
711 m_board->BuildConnectivity();
713 int unconnectedCount = m_board->GetConnectivity()->GetUnconnectedCount(
false );
716 wxString::Format(
"Found %d unconnected items after zone fill. "
717 "Hatch zone thermal reliefs should maintain connectivity "
718 "even with large hatch gaps.",
719 unconnectedCount ) );
743 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT(
"In1.Cu" ) );
745 ZONE* gndZone =
nullptr;
747 for(
ZONE* zone : m_board->Zones() )
749 if( zone->GetNetname() ==
"GND" && zone->IsOnLayer( in1Cu ) )
756 BOOST_REQUIRE_MESSAGE( gndZone !=
nullptr,
"GND zone on In1.Cu not found in test board" );
764 "GND zone has no fill on In1.Cu" );
772 double zoneOutlineArea = gndZone->
Outline()->
Area();
774 BOOST_REQUIRE_MESSAGE( zoneOutlineArea > 0.0,
"Zone outline area must be positive" );
776 double fillArea = 0.0;
778 for(
int i = 0; i < fill->OutlineCount(); i++ )
779 fillArea +=
std::abs( fill->Outline( i ).Area() );
781 double fillRatio = fillArea / zoneOutlineArea;
785 BOOST_CHECK_GE( fillRatio, 0.90 );
808 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
816 std::vector<ZONE*> keepouts;
818 for(
ZONE* zone : m_board->Zones() )
820 if( zone->GetIsRuleArea() && zone->GetDoNotAllowZoneFills() )
821 keepouts.push_back( zone );
824 BOOST_REQUIRE_MESSAGE( !keepouts.empty(),
"No zone keepouts found in test board" );
827 int violationCount = 0;
829 for(
ZONE* keepout : keepouts )
831 for(
PCB_LAYER_ID layer : keepout->GetLayerSet().Seq() )
836 for(
ZONE* zone : m_board->Zones() )
838 if( zone->GetIsRuleArea() )
841 if( !zone->IsOnLayer( layer ) )
844 if( !zone->HasFilledPolysForLayer( layer ) )
847 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
855 double intersectionArea = 0;
861 if( intersectionArea > 1e6 )
864 "Zone %s fill on layer %s overlaps keepout by %.2f sq mm",
866 m_board->GetLayerName( layer ),
867 intersectionArea / 1e6 ) );
876 wxString::Format(
"Found %d zone fills overlapping keepout areas. "
877 "This indicates issue 22809 - iterative refiller "
878 "ignores zone keepouts.", violationCount ) );
901 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT(
"In2.Cu" ) );
902 int padsWithMissingFlashing = 0;
903 int totalConditionalPads = 0;
905 for(
FOOTPRINT* footprint : m_board->Footprints() )
907 for(
PAD*
pad : footprint->Pads() )
909 if( !
pad->GetRemoveUnconnected() )
912 if( !
pad->HasHole() )
915 if(
pad->GetNetname() !=
"VBUS_DUT" &&
pad->GetNetname() !=
"VBUS_DBG" )
918 totalConditionalPads++;
921 bool shouldFlash =
false;
923 for(
ZONE* zone : m_board->Zones() )
925 if( zone->GetIsRuleArea() )
928 if( zone->GetNetCode() !=
pad->GetNetCode() )
931 if( !zone->IsOnLayer( in2Cu ) )
934 if( zone->Outline()->Contains(
pad->GetPosition() ) )
941 if( shouldFlash && !
pad->FlashLayer( in2Cu ) )
944 "Pad %s at (%d, %d) on net %s is inside zone but not flashing on In2.Cu",
945 pad->GetNumber(),
pad->GetPosition().x,
pad->GetPosition().y,
946 pad->GetNetname() ) );
947 padsWithMissingFlashing++;
952 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional pads: %d, Pads with missing "
953 "flashing: %d", totalConditionalPads,
954 padsWithMissingFlashing ) );
957 wxString::Format(
"Found %d TH pads that should flash on inner layers "
958 "but don't. This indicates issue 22826 is not fixed.",
959 padsWithMissingFlashing ) );
977 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
987 if( !commit.
Empty() )
991 int teardropCount = 0;
992 bool foundBadTeardrop =
false;
994 for(
ZONE* zone : m_board->Zones() )
996 if( !zone->IsTeardropArea() )
1013 int concaveCount = 0;
1015 for(
int i = 0; i <
chain.PointCount(); i++ )
1017 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1018 int next = ( i + 1 ) %
chain.PointCount();
1024 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1034 if( concaveCount > 5 )
1037 "indicating possible corner intersection",
1039 foundBadTeardrop =
true;
1046 "Found teardrop with excessive concave vertices, indicating "
1047 "issue 19405 - teardrop curve intersecting rounded rectangle corner" );
1061 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1070 if( !commit.
Empty() )
1073 int teardropCount = 0;
1074 bool foundSpike =
false;
1076 const int maxError = m_board->GetDesignSettings().m_MaxError;
1078 for(
ZONE* zone : m_board->Zones() )
1080 if( !zone->IsTeardropArea() )
1086 int netcode = zone->GetNetCode();
1094 for(
FOOTPRINT* fp : m_board->Footprints() )
1096 for(
PAD*
pad : fp->Pads() )
1098 if(
pad->GetNetCode() == netcode &&
pad->IsOnLayer( layer ) )
1099 pad->TransformShapeToPolygon( corridor, layer, 0, maxError,
ERROR_OUTSIDE );
1103 for(
PCB_TRACK* track : m_board->Tracks() )
1105 if( track->GetNetCode() == netcode && track->IsOnLayer( layer ) )
1106 track->TransformShapeToPolygon( corridor, layer, 0, maxError,
ERROR_OUTSIDE );
1118 double tdArea =
std::abs( zone->Outline()->Area() );
1120 double ratio = tdArea > 0 ? outArea / tdArea : 0.0;
1123 "Teardrop on layer %d: area %.0f, area outside corridor %.0f (%.1f%%)",
1124 (
int) layer, tdArea, outArea, ratio * 100.0 ) );
1130 "Teardrop on layer %d sweeps %.1f%% of its area outside the track/pad "
1132 (
int) layer, ratio * 100.0 ) );
1138 "A teardrop vertex spikes outside the track/pad corridor it should "
1156 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1166 if( !commit.
Empty() )
1170 int teardropCount = 0;
1171 bool foundBadTeardrop =
false;
1173 for(
ZONE* zone : m_board->Zones() )
1175 if( !zone->IsTeardropArea() )
1189 int concaveCount = 0;
1191 for(
int i = 0; i <
chain.PointCount(); i++ )
1193 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1194 int next = ( i + 1 ) %
chain.PointCount();
1199 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1205 if( concaveCount > 5 )
1209 foundBadTeardrop =
true;
1216 "Found teardrop with excessive concave vertices on oval pad, "
1217 "indicating curve is not tangent to semicircular end" );
1234 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1244 if( !commit.
Empty() )
1248 PAD* largePad =
nullptr;
1250 for(
FOOTPRINT* fp : m_board->Footprints() )
1252 for(
PAD*
pad : fp->Pads() )
1262 BOOST_REQUIRE_MESSAGE( largePad !=
nullptr,
"Expected a circular pad in test board" );
1268 int teardropCount = 0;
1269 bool foundBadTeardrop =
false;
1271 for(
ZONE* zone : m_board->Zones() )
1273 if( !zone->IsTeardropArea() )
1286 int concaveCount = 0;
1288 for(
int i = 0; i <
chain.PointCount(); i++ )
1290 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1291 int next = ( i + 1 ) %
chain.PointCount();
1296 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1302 if( concaveCount > 5 )
1304 BOOST_TEST_MESSAGE( wxString::Format(
"Large circle teardrop has %d concave vertices",
1306 foundBadTeardrop =
true;
1311 int maxError = m_board->GetDesignSettings().m_MaxError;
1313 for(
int i = 0; i <
chain.PointCount(); i++ )
1316 double dist = ( pt - padCenter ).EuclideanNorm();
1319 if( dist > padRadius * 0.5 && dist < padRadius * 1.5 )
1321 double deviation =
std::abs( dist - padRadius );
1324 if( deviation > maxError * 5 && deviation < padRadius * 0.2 )
1327 "Teardrop point at distance %.2f from pad center (radius %.2f), "
1328 "deviation %.2f exceeds tolerance",
1329 dist / 1000.0, padRadius / 1000.0, deviation / 1000.0 ) );
1338 "Found teardrop with excessive concave vertices on large circle, "
1339 "indicating anchor points may not be on circle edge" );
1363 for(
ZONE* zone : m_board->Zones() )
1365 if( zone->GetIsRuleArea() )
1370 if( !zone->HasFilledPolysForLayer( layer ) )
1373 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
1375 for(
PAD*
pad : m_board->GetPads() )
1377 if( !
pad->IsOnLayer( layer ) )
1380 if(
pad->GetNetCode() == zone->GetNetCode() )
1383 std::shared_ptr<SHAPE> padShape =
pad->GetEffectiveShape( layer );
1384 int clearance = padShape->GetClearance( fill.get() );
1389 "Pad %s (net %s) at (%d, %d) has zero clearance to zone %s "
1391 pad->GetNumber(),
pad->GetNetname(),
1392 pad->GetPosition().x,
pad->GetPosition().y,
1393 zone->GetNetname(), m_board->GetLayerName( layer ) ) );
1401 wxString::Format(
"Found %d pads with missing zone clearance. "
1402 "Coincident pads with different nets must not be "
1403 "deduplicated in zone fill knockout.",
1425 std::vector<DRC_ITEM> violations;
1430 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
1431 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
1435 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
1436 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
1438 ZONE* zone_a =
dynamic_cast<ZONE*
>( item_a );
1439 ZONE* zone_b =
dynamic_cast<ZONE*
>( item_b );
1441 if( zone_a || zone_b )
1442 violations.push_back( *aItem );
1469 ZONE* hvZone =
nullptr;
1470 ZONE* lvZone =
nullptr;
1472 for(
ZONE* zone : m_board->Zones() )
1474 if( zone->GetNetname() ==
"HV_NET" )
1476 else if( zone->GetNetname() ==
"LV_NET" )
1485 hvZone, lvZone,
F_Cu );
1488 <<
" (expected " <<
pcbIUScale.mmToIU( 4.6 ) <<
")" );
1493 hvZone, lvZone,
In1_Cu );
1496 <<
" (expected " <<
pcbIUScale.mmToIU( 2.3 ) <<
")" );
1503 std::vector<DRC_ITEM> violations;
1508 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
1509 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
1513 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
1514 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
1516 ZONE* zone_a =
dynamic_cast<ZONE*
>( item_a );
1517 ZONE* zone_b =
dynamic_cast<ZONE*
>( item_b );
1519 if( zone_a && zone_b )
1522 << aLayer <<
": " << aItem->GetErrorMessage(
true ) );
1523 violations.push_back( *aItem );
1536 KI_TEST::LoadBoard( m_settingsManager,
"issue23332_min_width/issue23332_min_width", m_board );
1542 for(
ZONE* zone : m_board->Zones() )
1544 int half_min_width = zone->GetMinThickness() / 2;
1551 if( !zone->HasFilledPolysForLayer( layer ) )
1554 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1556 if( !fill || fill->OutlineCount() == 0 )
1561 for(
int ii = 0; ii < fill->OutlineCount(); ii++ )
1566 for(
int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1567 island.
AddHole( fill->Hole( ii, jj ) );
1569 double originalArea = island.
Area();
1571 if( originalArea <= 0 )
1582 double prunedArea =
test.Area();
1583 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1586 "Zone %s layer %d island %d: area=%.0f, loss=%.4f%%",
1587 zone->GetNetname(),
static_cast<int>( layer ), ii,
1588 originalArea, areaLoss * 100.0 ) );
1592 "Zone %s layer %d island %d lost %.2f%% area from "
1593 "min-width pruning (min_width=%.3fmm)",
1594 zone->GetNetname(),
static_cast<int>( layer ), ii,
1596 zone->GetMinThickness()
1597 /
static_cast<double>(
pcbIUScale.IU_PER_MM ) ) );
1612 for(
ZONE* zone : m_board->Zones() )
1614 int half_min_width = zone->GetMinThickness() / 2;
1621 if( !zone->HasFilledPolysForLayer( layer ) )
1624 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1626 if( !fill || fill->OutlineCount() == 0 )
1629 for(
int ii = 0; ii < fill->OutlineCount(); ii++ )
1634 for(
int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1635 island.
AddHole( fill->Hole( ii, jj ) );
1637 double originalArea = island.
Area();
1639 if( originalArea <= 0 )
1650 double prunedArea =
test.Area();
1651 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1655 "Zone %s (priority %d) layer %d island %d lost "
1656 "%.2f%% area from min-width pruning, suggesting "
1657 "degenerate geometry from overlapping same-net zones",
1659 zone->GetAssignedPriority(),
1660 static_cast<int>( layer ), ii,
1661 areaLoss * 100.0 ) );
1673 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
1676 auto runAreaLossCheck =
1677 [
this](
bool aIterative )
1687 for(
ZONE* zone : m_board->Zones() )
1689 int half_min_width = zone->GetMinThickness() / 2;
1696 if( !zone->HasFilledPolysForLayer( layer ) )
1699 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
1701 if( !fill || fill->OutlineCount() == 0 )
1704 for(
int ii = 0; ii < fill->OutlineCount(); ii++ )
1709 for(
int jj = 0; jj < fill->HoleCount( ii ); jj++ )
1710 island.
AddHole( fill->Hole( ii, jj ) );
1712 double originalArea = island.
Area();
1714 if( originalArea <= 0 )
1725 double prunedArea =
test.Area();
1726 double areaLoss = ( originalArea - prunedArea ) / originalArea;
1731 "Zone %s (priority %d) layer %d island %d lost "
1732 "%.2f%% area (iterative=%d), suggesting degenerate "
1733 "geometry from different-net zone knockouts",
1734 zone->GetNetname(), zone->GetAssignedPriority(),
1735 static_cast<int>( layer ), ii, areaLoss * 100.0,
1742 runAreaLossCheck(
false );
1743 runAreaLossCheck(
true );
1768 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
1771 KI_TEST::LoadBoard( m_settingsManager,
"issue23535_minimal/issue23535_minimal", m_board );
1775 ZONE* gndZone =
nullptr;
1777 for(
ZONE* zone : m_board->Zones() )
1779 if( zone->GetNetname() ==
"GND" )
1797 bool hasSpokeToNowhere = gndFill->Contains( spokeTestPoint );
1800 "GND zone fill contains copper at the thermal gap test point (7.4, 5.0), "
1801 "indicating a thermal relief spoke to nowhere (issue 23535)." );
1808 bool hasValidSpoke = gndFill->Contains( validSpokePoint );
1811 "GND zone fill does not contain copper at the valid spoke test point "
1812 "(5.6, 5.0). The fix may have incorrectly removed valid spokes." );
1830 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1839 if( !commit.
Empty() )
1847 int teardropCount = 0;
1849 for(
ZONE* zone : m_board->Zones() )
1851 if( !zone->IsTeardropArea() )
1869 for(
int i = 0; i <
chain.PointCount(); i++ )
1871 int dy =
chain.CPoint( i ).y - trackY;
1874 maxAbove = std::max( maxAbove, -dy );
1876 maxBelow = std::max( maxBelow, dy );
1881 "Teardrop should extend on both sides of the track axis" );
1883 if( maxAbove > 0 && maxBelow > 0 )
1887 double ratio =
static_cast<double>( std::min( maxAbove, maxBelow ) )
1888 /
static_cast<double>( std::max( maxAbove, maxBelow ) );
1891 wxString::Format(
"Teardrop asymmetry ratio %.2f is too low "
1892 "(above=%d, below=%d). Expected roughly "
1893 "symmetric about the track axis.",
1894 ratio, maxAbove, maxBelow ) );
1898 BOOST_CHECK_MESSAGE( teardropCount > 0,
"Expected at least one teardrop zone for off-center track" );
1915 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1924 if( !commit.
Empty() )
1930 PAD* testPad =
nullptr;
1932 for(
FOOTPRINT* fp : m_board->Footprints() )
1934 for(
PAD*
pad : fp->Pads() )
1936 if(
pad->GetNumber() ==
"7" )
1944 BOOST_REQUIRE_MESSAGE( testPad !=
nullptr,
"Could not find pad 7 in test board" );
1947 int tolerance = std::max( m_board->GetDesignSettings().m_MaxError,
1953 int teardropCount = 0;
1955 for(
ZONE* zone : m_board->Zones() )
1957 if( !zone->IsTeardropArea() )
1962 BOOST_REQUIRE_MESSAGE( outline && outline->
OutlineCount() > 0,
1963 "Teardrop zone has no outline" );
1977 for(
int i = 0; i <
chain.PointCount(); i++ )
1980 double distToPad = (
VECTOR2D( pt ) -
VECTOR2D( padCenter ) ).EuclideanNorm();
1981 double distToTrack = (
VECTOR2D( pt ) -
VECTOR2D( trackAnchor ) ).EuclideanNorm();
1984 if( distToPad < distToTrack )
1988 wxString::Format(
"Teardrop vertex (%d, %d) is outside the pad "
1989 "outline with %d nm tolerance",
1990 pt.
x, pt.
y, tolerance ) );
1996 "Expected at least one teardrop zone for elongated pad" );
2010 auto runVariant = [&](
bool aCurvedEdges )
2014 for(
PCB_TRACK* track : m_board->Tracks() )
2018 static_cast<PCB_VIA*
>( track )->SetTeardropCurved( aCurvedEdges );
2024 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
2033 if( !commit.
Empty() )
2036 int teardropCount = 0;
2037 bool foundSelfIntersection =
false;
2039 for(
ZONE* zone : m_board->Zones() )
2041 if( !zone->IsTeardropArea() )
2052 int n =
chain.PointCount();
2054 for(
int i = 0; i < n && !foundSelfIntersection; i++ )
2056 SEG segA(
chain.CPoint( i ),
chain.CPoint( ( i + 1 ) % n ) );
2058 for(
int j = i + 2; j < n; j++ )
2060 if( i == 0 && j == n - 1 )
2063 SEG segB(
chain.CPoint( j ),
chain.CPoint( ( j + 1 ) % n ) );
2066 if( hit.has_value() )
2069 "Self-intersection at (%d, %d) between edges %d and %d "
2071 hit->x, hit->y, i, j,
2072 aCurvedEdges ?
"yes" :
"no" ) );
2074 for(
int k = 0; k < n; k++ )
2077 " pt[%d] = (%d, %d)", k,
2078 chain.CPoint( k ).x,
chain.CPoint( k ).y ) );
2081 foundSelfIntersection =
true;
2089 wxString::Format(
"Expected at least one teardrop zone "
2091 aCurvedEdges ?
"yes" :
"no" ) );
2094 wxString::Format(
"Teardrop polygon has self-intersecting "
2095 "edges (curved=%s)",
2096 aCurvedEdges ?
"yes" :
"no" ) );
2100 runVariant(
false );
2124 auto runVariant = [&](
bool aCurvedEdges )
2131 for(
PCB_TRACK* track : m_board->Tracks() )
2136 via->SetTeardropCurved( aCurvedEdges );
2137 viaPos =
via->GetPosition();
2146 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
2155 if( !commit.
Empty() )
2160 const double maxBackSideDist = viaRadius * 1.2;
2161 int teardropCount = 0;
2162 int spikingPoints = 0;
2164 double worstDistance = 0.0;
2166 for(
ZONE* zone : m_board->Zones() )
2168 if( !zone->IsTeardropArea() )
2180 for(
int i = 0; i <
chain.PointCount(); i++ )
2191 if( dist > maxBackSideDist )
2195 if( dist > worstDistance )
2197 worstDistance = dist;
2205 wxString::Format(
"Expected no teardrop on grazing-entry "
2206 "track (emergence below track width), got "
2209 aCurvedEdges ?
"yes" :
"no" ) );
2212 wxString::Format(
"Found %d teardrop polygon vertex/vertices "
2213 "outside the expected envelope (worst at "
2214 "(%d, %d), %f mm from via center; curved=%s)",
2216 worstPoint.
x, worstPoint.
y,
2218 aCurvedEdges ?
"yes" :
"no" ) );
2222 runVariant(
false );
2240 auto runVariant = [&](
bool aCurvedEdges )
2244 for(
PCB_TRACK* track : m_board->Tracks() )
2248 static_cast<PCB_VIA*
>( track )->SetTeardropCurved( aCurvedEdges );
2254 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
2263 if( !commit.
Empty() )
2266 int teardropCount = 0;
2267 int selfIntersectingCount = 0;
2270 for(
ZONE* zone : m_board->Zones() )
2272 if( !zone->IsTeardropArea() )
2283 int n =
chain.PointCount();
2284 bool intersected =
false;
2286 for(
int i = 0; i < n && !intersected; i++ )
2288 SEG segA(
chain.CPoint( i ),
chain.CPoint( ( i + 1 ) % n ) );
2290 for(
int j = i + 2; j < n; j++ )
2292 if( i == 0 && j == n - 1 )
2295 SEG segB(
chain.CPoint( j ),
chain.CPoint( ( j + 1 ) % n ) );
2298 if( hit.has_value() )
2301 "Teardrop polygon self-intersection at (%d, %d) "
2302 "between edges %d and %d (curved=%s)",
2303 hit->x, hit->y, i, j, aCurvedEdges ?
"yes" :
"no" ) );
2305 worstPoint = hit.value();
2313 selfIntersectingCount++;
2317 wxString::Format(
"Expected at least one teardrop zone "
2319 aCurvedEdges ?
"yes" :
"no" ) );
2322 wxString::Format(
"%d of %d teardrop polygon(s) self-intersect "
2323 "(worst at (%d, %d); curved=%s)",
2324 selfIntersectingCount, teardropCount,
2325 worstPoint.
x, worstPoint.
y,
2326 aCurvedEdges ?
"yes" :
"no" ) );
2330 runVariant(
false );
2346 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
2349 auto getTotalFilledArea =
2354 for(
ZONE* zone : m_board->Zones() )
2356 if( zone->GetIsRuleArea() )
2361 if( !zone->HasFilledPolysForLayer( layer ) )
2364 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
2374 auto refillAndMeasure =
2375 [
this, &cfg, &getTotalFilledArea](
bool aIterative ) ->
double
2381 double storedArea = getTotalFilledArea();
2383 BOOST_REQUIRE_MESSAGE( storedArea > 0,
"Stored v9 fill has zero area" );
2386 return getTotalFilledArea();
2391 double storedArea = getTotalFilledArea();
2393 BOOST_REQUIRE_MESSAGE( storedArea > 0,
"Stored v9 fill has zero area" );
2395 double nonIterativeArea = refillAndMeasure(
false );
2396 double iterativeArea = refillAndMeasure(
true );
2397 double nonIterativeAreaRatio = nonIterativeArea / storedArea;
2398 double iterativeAreaRatio = iterativeArea / storedArea;
2401 nonIterativeAreaRatio > 0.99999,
2403 "Non-iterative refill lost %.4f%% versus stored v9 fill "
2404 "(stored=%.2f mm^2, non-iterative=%.2f mm^2). "
2405 "This suggests missing pieces near keepout boundaries (issue 23515).",
2406 ( 1.0 - nonIterativeAreaRatio ) * 100.0,
2407 storedArea / 1e6, nonIterativeArea / 1e6 ) );
2410 iterativeAreaRatio > 0.99999,
2412 "Iterative refill lost %.4f%% versus stored v9 fill "
2413 "(stored=%.2f mm^2, iterative=%.2f mm^2). "
2414 "This suggests missing pieces near keepout boundaries (issue 23515).",
2415 ( 1.0 - iterativeAreaRatio ) * 100.0,
2416 storedArea / 1e6, iterativeArea / 1e6 ) );
2430 m_board = std::make_unique<BOARD>();
2433 m_board->SetCopperLayerCount( 2 );
2442 m_board->Add( gndNet );
2454 int hatchThickness =
pcbIUScale.mmToIU( 0.3 );
2463 via->SetPosition( viaPos );
2465 via->SetDrill( viaDrill );
2467 via->SetNetCode( gndNetCode );
2468 m_board->Add(
via );
2472 auto makeHatchZone =
2475 ZONE* zone =
new ZONE( m_board.get() );
2494 m_board->Add( zone );
2501 m_board->BuildConnectivity();
2502 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
2503 drcEngine->InitEngine( wxFileName() );
2515 double fullFillArea = 0.0;
2516 double thermalFillArea = 0.0;
2527 "Zone should have fill on F.Cu with FULL connection" );
2531 for(
int i = 0; i < fill->OutlineCount(); i++ )
2532 fullFillArea +=
std::abs( fill->Outline( i ).Area() );
2534 m_board->Remove(
via );
2535 m_board->Remove( zone );
2549 "Zone should have fill on F.Cu with THERMAL connection" );
2553 for(
int i = 0; i < fill->OutlineCount(); i++ )
2554 thermalFillArea +=
std::abs( fill->Outline( i ).Area() );
2556 m_board->Remove(
via );
2557 m_board->Remove( zone );
2566 double areaThreshold = 0.2 * iuPerMM * iuPerMM;
2568 double areaIU2toMM2 = 1.0 / ( iuPerMM * iuPerMM );
2572 "THERMAL connection fill area (%.2f sq mm) should be larger "
2573 "than FULL fill area (%.2f sq mm) by at least 0.2 sq mm. "
2574 "If they are equal or FULL is larger, thermal ring was not "
2575 "added for THERMAL connection, or thermal ring was incorrectly "
2576 "added for FULL connection (issue 23516 regression).",
2577 thermalFillArea * areaIU2toMM2, fullFillArea * areaIU2toMM2 ) );
2589 m_board = std::make_unique<BOARD>();
2590 m_board->SetCopperLayerCount( 2 );
2597 m_board->Add( gndNet );
2606 int hatchThickness =
pcbIUScale.mmToIU( 0.3 );
2608 auto makeHatchZone = [&]() ->
ZONE*
2610 ZONE* zone =
new ZONE( m_board.get() );
2627 m_board->Add( zone );
2633 const int steps = 8;
2634 const double startMM = 9.0;
2635 const double stepMM = 2.3 / steps;
2637 int isolatedCount = 0;
2638 int testedCount = 0;
2640 for(
int ix = 0; ix < steps; ix++ )
2642 for(
int iy = 0; iy < steps; iy++ )
2647 via->SetPosition( viaPos );
2649 via->SetDrill( viaDrill );
2651 via->SetNetCode( gndNetCode );
2652 m_board->Add(
via );
2654 ZONE* zone = makeHatchZone();
2656 m_board->BuildConnectivity();
2657 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
2658 drcEngine->InitEngine( wxFileName() );
2666 std::shared_ptr<SHAPE> viaShape =
via->GetEffectiveShape(
F_Cu );
2670 if( !fill->Collide( viaShape.get(), 0 ) )
2675 m_board->Remove(
via );
2676 m_board->Remove( zone );
2682 BOOST_CHECK_MESSAGE( isolatedCount == 0, wxString::Format(
"%d of %d FULL-connection via positions were left "
2683 "isolated from the hatch fill (issue 24559).",
2684 isolatedCount, testedCount ) );
2715 ~ScopeGuard() { ref = orig; }
2721 const std::vector<std::string> checkedNames = {
"hi1",
"hi2",
"hi3",
"hi4",
"hi5",
"hi6",
"hi7",
2722 "lo1",
"lo2",
"lo3",
"lo4",
"lo5",
"lo6" };
2723 std::map<std::string, ZONE*> zoneByName;
2725 for(
ZONE* zone : m_board->Zones() )
2726 zoneByName[zone->GetZoneName().ToStdString()] = zone;
2728 for(
const std::string&
name : checkedNames )
2730 BOOST_REQUIRE_MESSAGE( zoneByName.count(
name ),
"Zone '" +
name +
"' not found in test board" );
2731 BOOST_REQUIRE_MESSAGE( zoneByName[
name]->HasFilledPolysForLayer(
F_Cu ),
2732 "Zone '" +
name +
"' has no fill on F.Cu" );
2736 for(
const std::string&
name : {
"hi3",
"hi5",
"hi7" } )
2738 int islands = zoneByName[
name]->GetFilledPolysList(
F_Cu )->OutlineCount();
2740 BOOST_CHECK_MESSAGE( islands == 2, wxString::Format(
"Zone '%s' should have 2 filled islands but has %d. "
2741 "Cascading island removal did not converge correctly.",
2746 for(
const std::string&
name : {
"lo1",
"lo2",
"lo3",
"lo4",
"lo5",
"lo6",
"hi2",
"hi4",
"hi6" } )
2748 int islands = zoneByName[
name]->GetFilledPolysList(
F_Cu )->OutlineCount();
2750 BOOST_CHECK_MESSAGE( islands == 1, wxString::Format(
"Zone '%s' should have 1 filled island but has %d. "
2751 "Iterative refill may have incorrectly blocked or "
2752 "expanded this zone.",
2769 ZONE* thievingZone =
nullptr;
2771 for(
ZONE* z : m_board->Zones() )
2788 BOOST_CHECK_GE( fill->OutlineCount(), 2 );
2791 BOX2I fillBox = fill->BBox();
2798 BOOST_CHECK_GT( fill->TotalVertices(), 200 );
2824 ~ScopeGuard() { ref = orig; }
2828 class WarningCapture :
public wxLog
2831 bool m_hadWarning =
false;
2834 void DoLogRecord( wxLogLevel aLevel,
const wxString&,
const wxLogRecordInfo& )
override
2836 if( aLevel == wxLOG_Warning )
2837 m_hadWarning =
true;
2841 auto* capture =
new WarningCapture();
2842 wxLog* oldLog = wxLog::SetActiveTarget( capture );
2847 ~LogGuard() { wxLog::SetActiveTarget( old ); }
2848 } logGuard{ oldLog };
2853 BOOST_CHECK_MESSAGE( capture->m_hadWarning,
"Expected a wxLogWarning when iterative refill hits the iteration "
2854 "limit, but none was emitted. The convergence-limit board may no "
2855 "longer trigger the cap, or the warning path has changed." );
2866 m_board = std::make_unique<BOARD>();
2868 ZONE* zone =
new ZONE( m_board.get() );
2882 m_board->Add( zone );
2891 BOOST_CHECK_GT( fill->OutlineCount(), 5 );
2904 m_board = std::make_unique<BOARD>();
2905 m_board->SetCopperLayerCount( 2 );
2908 ZONE* zone =
new ZONE( m_board.get() );
2928 m_board->Add( zone );
2934 BOOST_REQUIRE_GT( fill->OutlineCount(), 0 );
2938 BOOST_CHECK_GE( fill->OutlineCount(), 6 );
2939 BOOST_CHECK_LE( fill->OutlineCount(), 12 );
2942 const double fullDotArea =
M_PI * std::pow(
pcbIUScale.mmToIU( 0.25 ), 2 );
2955 auto countDots = [](
bool stagger ) ->
int
2957 auto board = std::make_unique<BOARD>();
2958 board->SetCopperLayerCount( 2 );
2960 ZONE* zone =
new ZONE( board.get() );
2981 int plain = countDots(
false );
2982 int staggered = countDots(
true );
2988 BOOST_CHECK_NE( plain, staggered );
2989 BOOST_CHECK_GE( staggered, plain / 2 );
2990 BOOST_CHECK_LE( staggered, plain * 2 );
3001 m_board = std::make_unique<BOARD>();
3002 m_board->SetCopperLayerCount( 2 );
3004 ZONE* zone =
new ZONE( m_board.get() );
3018 m_board->Add( zone );
3024 BOOST_REQUIRE_GT( fill->OutlineCount(), 0 );
3028 BOOST_CHECK_GE( fill->OutlineCount(), 6 );
3029 BOOST_CHECK_LE( fill->OutlineCount(), 12 );
3031 const double fullSquareArea = std::pow(
pcbIUScale.mmToIU( 0.6 ), 2 );
3046 m_board = std::make_unique<BOARD>();
3047 m_board->SetCopperLayerCount( 2 );
3049 ZONE* zone =
new ZONE( m_board.get() );
3063 m_board->Add( zone );
3065 auto start = std::chrono::steady_clock::now();
3067 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
3068 std::chrono::steady_clock::now() - start )
3078 BOOST_CHECK_LT( elapsed, 30000 );
3090 m_board = std::make_unique<BOARD>();
3091 m_board->SetCopperLayerCount( 2 );
3093 ZONE* zone =
new ZONE( m_board.get() );
3107 m_board->Add( zone );
3113 BOOST_REQUIRE_GT( fill->TotalVertices(), 0 );
3123 BOX2I fillBox = fill->BBox();
3131 BOOST_CHECK_GT( fill->TotalVertices(), 30 );
3151 for(
ZONE* zone : m_board->Zones() )
3153 if( zone->GetIsRuleArea() )
3158 if( !zone->HasFilledPolysForLayer( layer ) )
3161 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
3164 total += fill->OutlineCount();
3171 int storedIslands = countIslands();
3173 BOOST_REQUIRE_MESSAGE( storedIslands >= 3,
3174 wxString::Format(
"Stored v9 fill should have at least 3 silk islands; "
3180 int refilledIslands = countIslands();
3183 wxString::Format(
"Refill lost silk islands: stored=%d, refilled=%d. "
3184 "Outline 0 of every non-copper multi-island zone "
3185 "was being incorrectly removed (issue 24089).",
3186 storedIslands, refilledIslands ) );
3197 m_board = std::make_unique<BOARD>();
3198 m_board->SetCopperLayerCount( 4 );
3205 m_board->Add( gndNet );
3209 m_board->Add( vccNet );
3212 ZONE* gndZone =
new ZONE( m_board.get() );
3229 m_board->Add( gndZone );
3231 ZONE* vccZone =
new ZONE( m_board.get() );
3255 m_board->Add( vccZone );
3259 auto footprint = std::make_unique<FOOTPRINT>( m_board.get() );
3269 pad->SetNetCode( gndNetCode );
3271 footprint->Add(
pad );
3272 footprint->SetPosition(
VECTOR2I( 0, 0 ) );
3273 m_board->Add( footprint.release() );
3275 m_board->BuildConnectivity();
3276 auto drcEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
3277 drcEngine->InitEngine( wxFileName() );
3285 "VCC outline must contain the pad position to reproduce issue 24175." );
3287 "VCC zone should still have fill in its right lobe." );
3292 BOOST_REQUIRE_MESSAGE( !vccFill->Contains(
pad->GetPosition() ),
3293 "VCC fill should NOT contain the pad position (corridor must be "
3294 "pruned by min-thickness for the test to exercise issue 24175)." );
3300 "PTH pad inside higher-priority different-net zone must still flash "
3301 "when a same-net lower-priority zone covers it (issue 24175)." );
3304 "GND zone should have fill on In1.Cu" );
3311 bool foundCopperAround =
false;
3313 for(
int i = 0; i < samples; i++ )
3315 double angle = ( 2.0 *
M_PI * i ) / samples;
3317 pad->GetPosition().y +
KiROUND( sampleR * std::sin( angle ) ) );
3319 if( gndFill->Contains( p ) )
3321 foundCopperAround =
true;
3327 "Lower-priority GND zone should have copper around GND pad even when "
3328 "a higher-priority different-net zone outline contains the pad "
3351 PCB_LAYER_ID targetLayer = m_board->GetLayerID( wxT(
"B.Cu" ) );
3352 std::vector<ZONE*> toFill;
3354 for(
ZONE* zone : m_board->Zones() )
3356 if( zone->GetIsRuleArea() )
3359 if( !zone->IsOnLayer( targetLayer ) )
3362 if( zone->IsFilled() )
3365 toFill.push_back( zone );
3368 BOOST_REQUIRE_MESSAGE( !toFill.empty(),
3369 "Expected at least one unfilled B.Cu zone to exercise the API path." );
3376 BOOST_CHECK_NO_THROW( filler.
Fill( toFill ) );
3390 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
3398 const int margin =
pcbIUScale.mmToIU( 0.05 );
3400 std::map<int, SHAPE_POLY_SET> mergedByNet;
3402 for(
ZONE* zone : m_board->Zones() )
3404 if( zone->GetIsRuleArea() || !zone->HasFilledPolysForLayer( layer ) )
3407 mergedByNet[zone->GetNetCode()].BooleanAdd( *zone->GetFilledPolysList( layer ) );
3412 auto buildLegitVoids =
3418 for(
ZONE* other : m_board->Zones() )
3420 if( !other->GetLayerSet().Contains( layer ) )
3423 if( other->GetIsRuleArea() )
3425 if( other->GetDoNotAllowZoneFills() )
3431 if( other->GetNetCode() == aLower->
GetNetCode()
3433 || other->GetAssignedPriority() <= aHigher->GetAssignedPriority()
3434 || !other->HasFilledPolysForLayer( layer ) )
3447 std::vector<ZONE*> zones;
3449 for(
ZONE* zone : m_board->Zones() )
3451 if( !zone->GetIsRuleArea() && zone->GetNetCode() > 0 && zone->GetLayerSet().Contains( layer ) )
3452 zones.push_back( zone );
3455 int checkedPairs = 0;
3457 for(
size_t i = 0; i < zones.size(); ++i )
3459 for(
size_t j = i + 1; j < zones.size(); ++j )
3474 const ZONE* higher = ( lower == a ) ? b : a;
3487 double uncoveredArea =
3491 wxString::Format(
"Same-net zones (priorities %d and %d) left %.4f mm^2 of "
3492 "their overlap unfilled; overlapping same-net zones must "
3493 "merge (issue 23790).",
3501 wxString::Format(
"Expected at least two overlapping same-net zone pairs "
3502 "to exercise the merge, found %d.", checkedPairs ) );
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< 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.
Handle the data for a net.
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 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