KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_creepage_issue25821.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
26
27#include <optional>
28#include <vector>
29
31
33
34
35namespace
36{
37
38constexpr double MAX_WEIGHT = 1e9;
39
40
41std::optional<PATH_CONNECTION> lowestWeightCandidate( const CU_SHAPE_SEGMENT& aSegment, const CU_SHAPE_ARC& aArc )
42{
43 const double maxSquaredWeight = MAX_WEIGHT * MAX_WEIGHT;
44 const double segmentHalfWidth = aSegment.GetWidth() / 2;
45 const double arcHalfWidth = aArc.GetWidth() / 2;
46
47 CU_SHAPE_CIRCLE atArcStart( aArc.GetStartPoint(), arcHalfWidth );
48 CU_SHAPE_CIRCLE atArcEnd( aArc.GetEndPoint(), arcHalfWidth );
49 CU_SHAPE_CIRCLE atSegmentStart( aSegment.GetStart(), segmentHalfWidth );
50 CU_SHAPE_CIRCLE atSegmentEnd( aSegment.GetEnd(), segmentHalfWidth );
51
52 std::vector<std::vector<PATH_CONNECTION>> candidateSets;
53
54 candidateSets.push_back( aSegment.Paths( atArcStart, MAX_WEIGHT, maxSquaredWeight ) );
55 candidateSets.push_back( aSegment.Paths( atArcEnd, MAX_WEIGHT, maxSquaredWeight ) );
56 candidateSets.push_back( atSegmentStart.Paths( aArc, MAX_WEIGHT, maxSquaredWeight ) );
57 candidateSets.push_back( atSegmentEnd.Paths( aArc, MAX_WEIGHT, maxSquaredWeight ) );
58
59 std::optional<PATH_CONNECTION> best;
60
61 for( const std::vector<PATH_CONNECTION>& candidateSet : candidateSets )
62 {
63 for( const PATH_CONNECTION& candidate : candidateSet )
64 {
65 if( !best || best->weight > candidate.weight )
66 best = candidate;
67 }
68 }
69
70 return best;
71}
72
73} // namespace
74
75
76BOOST_AUTO_TEST_CASE( CreepageSegmentToArcFallbackPicksLowestWeight )
77{
78 const double radius = 1000000.0;
79
80 // The segment sits off the arc's angular span, so the fallback runs instead of returning early.
82 VECTOR2D( radius, 0 ), VECTOR2D( 0, radius ) );
83
84 CU_SHAPE_SEGMENT segment( VECTOR2I( -3000000, -2600000 ), VECTOR2I( -1200000, -2600000 ), 200000 );
85
86 std::vector<PATH_CONNECTION> toFullCircle = segment.Paths(
87 CU_SHAPE_CIRCLE( arc.GetPos(), radius + arc.GetWidth() / 2 ), MAX_WEIGHT, MAX_WEIGHT * MAX_WEIGHT );
88
89 BOOST_REQUIRE( !toFullCircle.empty() );
90 BOOST_REQUIRE( arc.AngleBetweenStartAndEnd( toFullCircle[0].a1 ) >= arc.GetEndAngle() );
91
92 std::optional<PATH_CONNECTION> expected = lowestWeightCandidate( segment, arc );
93 BOOST_REQUIRE( expected.has_value() );
94
95 std::vector<PATH_CONNECTION> paths = segment.Paths( arc, MAX_WEIGHT, MAX_WEIGHT * MAX_WEIGHT );
96
97 BOOST_REQUIRE_EQUAL( paths.size(), 1 );
98 BOOST_CHECK_CLOSE( paths[0].weight, expected->weight, 1e-6 );
99 BOOST_CHECK( paths[0].a1 == expected->a1 );
100 BOOST_CHECK( paths[0].a2 == expected->a2 );
101}
VECTOR2I GetPos() const
Creepage: a conductive arc.
VECTOR2I GetStartPoint() const override
EDA_ANGLE AngleBetweenStartAndEnd(const VECTOR2I aPoint) const
VECTOR2I GetEndPoint() const override
double GetWidth() const
EDA_ANGLE GetEndAngle() const override
Creepage: a conductive circle.
Creepage: a conductive segment.
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
VECTOR2I GetStart() const
double GetWidth() const
VECTOR2I GetEnd() const
@ DEGREES_T
Definition eda_angle.h:30
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_CASE(CreepageSegmentToArcFallbackPicksLowestWeight)
VECTOR3I expected(15, 30, 45)
int radius
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707