KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_creepage_circle_prune.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
29
30#include <cmath>
31#include <vector>
32
34
35#include <base_units.h>
37
38
39namespace
40{
41
42// Callers select a side by index, so a reachable pair always yields both tangents
43constexpr size_t TANGENTS_PER_PAIR = 2;
44
45} // namespace
46
47
48BOOST_AUTO_TEST_CASE( CreepageCircleToHoleKeepsReachableTangent )
49{
50 const double R1 = pcbIUScale.mmToIU( 0.1 );
51 const int R2 = pcbIUScale.mmToIU( 10.0 );
52 const int dist = pcbIUScale.mmToIU( 10.2 );
53 const double maxWeight = pcbIUScale.mmToIU( 9.0 );
54
55 const double expectedWeight = sqrt( (double) dist * dist - (double) R2 * R2 ) - R1;
56
57 // Outside the hole, centres beyond the target, tangent inside it
58 BOOST_REQUIRE_GT( dist, R2 );
59 BOOST_REQUIRE_GT( dist, maxWeight );
60 BOOST_REQUIRE_LT( expectedWeight, maxWeight );
61
62 CU_SHAPE_CIRCLE copper( VECTOR2I( 0, 0 ), R1 );
63 BE_SHAPE_CIRCLE hole( VECTOR2I( dist, 0 ), R2 );
64
65 std::vector<PATH_CONNECTION> paths = copper.Paths( hole, maxWeight, maxWeight * maxWeight );
66
67 BOOST_REQUIRE_EQUAL( paths.size(), TANGENTS_PER_PAIR );
68
69 for( const PATH_CONNECTION& pc : paths )
70 BOOST_CHECK_CLOSE( pc.weight, expectedWeight, 0.1 );
71}
72
73
74BOOST_AUTO_TEST_CASE( CreepageCircleInsideHoleKeepsRadialGap )
75{
76 const double R1 = pcbIUScale.mmToIU( 0.1 );
77 const int R2 = pcbIUScale.mmToIU( 10.0 );
78 const int dist = pcbIUScale.mmToIU( 9.0 );
79 const double maxWeight = pcbIUScale.mmToIU( 6.0 );
80
81 const double expectedWeight = R2 - dist - R1;
82
83 // Inside the hole, centres beyond the target, radial gap inside it
84 BOOST_REQUIRE_LE( dist, R2 );
85 BOOST_REQUIRE_GT( dist, maxWeight );
86 BOOST_REQUIRE_LT( expectedWeight, maxWeight );
87
88 CU_SHAPE_CIRCLE copper( VECTOR2I( 0, 0 ), R1 );
89 BE_SHAPE_CIRCLE hole( VECTOR2I( dist, 0 ), R2 );
90
91 std::vector<PATH_CONNECTION> paths = copper.Paths( hole, maxWeight, maxWeight * maxWeight );
92
93 BOOST_REQUIRE_EQUAL( paths.size(), TANGENTS_PER_PAIR );
94
95 for( const PATH_CONNECTION& pc : paths )
96 BOOST_CHECK_CLOSE( pc.weight, expectedWeight, 0.1 );
97}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Creepage: a board edge circle.
Creepage: a conductive circle.
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
BOOST_AUTO_TEST_CASE(CreepageCircleToHoleKeepsReachableTangent)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683