KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_arc_arc_edge_clearance.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software, you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
14#include <board.h>
16#include <drc/drc_engine.h>
17#include <drc/drc_item.h>
18#include <pcb_marker.h>
21
22
23/*
24 * Regression test for arc vs arc edge clearance.
25 *
26 * SHAPE_ARC::NearestPoints handles the case where two arc circles intersect or
27 * sit externally to each other, but skips the case where one arc's full circle
28 * sits inside the other's. In that internal containment case the closest pair
29 * of points on the two circles lies along the same ray from C1 through C2,
30 * outward past C2, not on the segment between centers. CIRCLE::NearestPoint
31 * returns the wrong side and the function falls back to endpoint vs arc
32 * distances, which can easily exceed the configured clearance even when the
33 * arcs are essentially touching.
34 *
35 * The fixture has a curved track on F.Cu whose full circle contains an
36 * Edge.Cuts arc cutout. The track conductor edge is essentially touching the
37 * cutout boundary. Edge clearance is set to 0.2 mm so the buggy reported
38 * distance (~0.35 mm) is above the threshold and DRC stays silent. Once
39 * NearestPoints handles the internal containment case, the actual gap
40 * (~0 mm) drops the reported distance below 0.2 mm and DRC flags the
41 * violation.
42 *
43 * Do not raise the edge clearance to the default 0.5 mm. At 0.5 mm the
44 * buggy reported distance falls under the threshold by accident and DRC
45 * appears to work, hiding the bug.
46 */
47
48
56
57
58BOOST_FIXTURE_TEST_CASE( DRCArcArcEdgeClearance_InternalContainment, DRC_ARC_ARC_EDGE_CLEARANCE_FIXTURE )
59{
60 KI_TEST::LoadBoard( m_settingsManager, "drc_arc_arc_edge_clearance/drc_arc_arc_edge_clearance", m_board );
61
62 std::vector<DRC_ITEM> edgeViolations;
63 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
64
65 for( int code = DRCE_FIRST; code <= DRCE_LAST; ++code )
67
69
71 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
72 const std::function<void( PCB_MARKER* )>& )
73 {
74 if( aItem->GetErrorCode() == DRCE_EDGE_CLEARANCE )
75 edgeViolations.push_back( *aItem );
76 } );
77
78 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
79
80 BOOST_CHECK_GE( edgeViolations.size(), 1u );
81
82 if( edgeViolations.empty() )
83 return;
84
85 const KIID trackUuid( "e918352c-937f-4a75-aac0-7856db5d052e" );
86 const KIID cutoutLeftArcUuid( "b9bfe430-49e3-430b-b86f-c88b7c1be60e" );
87
88 bool trackHit = false;
89 bool cutoutHit = false;
90
91 for( const DRC_ITEM& item : edgeViolations )
92 {
93 for( const KIID& uuid : { item.GetMainItemID(), item.GetAuxItemID() } )
94 {
95 if( uuid == trackUuid )
96 trackHit = true;
97 else if( uuid == cutoutLeftArcUuid )
98 cutoutHit = true;
99 }
100 }
101
102 BOOST_CHECK_MESSAGE( trackHit && cutoutHit, "Expected at least one DRCE_EDGE_CLEARANCE violation between the "
103 "F.Cu track arc and the Edge.Cuts left cutout arc" );
104}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:168
Definition kiid.h:48
@ DRCE_EDGE_CLEARANCE
Definition drc_item.h:47
@ DRCE_FIRST
Definition drc_item.h:39
@ DRCE_LAST
Definition drc_item.h:124
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(DRCArcArcEdgeClearance_InternalContainment, DRC_ARC_ARC_EDGE_CLEARANCE_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687