KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_clip_line_to_pad.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
21#include <board.h>
22#include <footprint.h>
23#include <pad.h>
25#include <geometry/shape_arc.h>
27
28#include <iostream>
29
30
32{
38
39 std::unique_ptr<PAD> MakePad()
40 {
41 auto pad = std::make_unique<PAD>( &m_footprint );
42 pad->SetAttribute( PAD_ATTRIB::SMD );
44 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( 2540000, 1270000 ) );
45 pad->SetPosition( VECTOR2I( 189190000, 46760000 ) );
46 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, 0.15 );
47 pad->SetLayerSet( LSET( { F_Cu } ) );
48 return pad;
49 }
50
53};
54
55
56BOOST_FIXTURE_TEST_SUITE( ClipLineToPad, CLIP_LINE_TO_PAD_FIXTURE )
57
58
59BOOST_AUTO_TEST_CASE( Issue22612_ArcStartsAtPadCenter )
60{
61 auto pad = MakePad();
62
63 const VECTOR2I arcStart( 189190000, 46760000 );
64 const VECTOR2I arcMid( 190382763, 46815467 );
65 const VECTOR2I arcEnd( 189758445, 47833301 );
66
68 chain.Append( arcStart );
69
70 SHAPE_ARC arc( arcStart, arcMid, arcEnd, 0 );
71 chain.Append( arc );
72
73 SHAPE_LINE_CHAIN chainForward = chain;
74 SHAPE_LINE_CHAIN chainBackward = chain;
75 chainBackward.Reverse();
76
77 BOOST_REQUIRE_EQUAL( chainForward.Length(), chainBackward.Length() );
78
81
82 int64_t lengthForward = chainForward.Length();
83 int64_t lengthBackward = chainBackward.Length();
84
85 BOOST_CHECK_CLOSE( static_cast<double>( lengthForward ), static_cast<double>( lengthBackward ), 0.5 );
86
87 BOOST_CHECK_CLOSE( lengthForward / 1000000.0, 2.4778, 2.0 );
88}
89
90BOOST_AUTO_TEST_CASE( Issue22612_TwoArcsFromPadCenter )
91{
92 auto pad = MakePad();
93
94 // Arc 1: starts at pad center
95 const VECTOR2I arc1Start( 189190000, 46760000 );
96 const VECTOR2I arc1Mid( 189810000, 46140000 );
97 const VECTOR2I arc1End( 190430000, 46760000 );
98
99 // Arc 2: connects to arc1 end, defined in chain direction
100 const VECTOR2I arc2Start( 190430000, 46760000 );
101 const VECTOR2I arc2Mid( 191310000, 47640000 );
102 const VECTOR2I arc2End( 192190000, 46760000 );
103
105 chain.Append( arc1Start );
106
107 SHAPE_ARC arc1( arc1Start, arc1Mid, arc1End, 0 );
108 chain.Append( arc1 );
109
110 SHAPE_ARC arc2( arc2Start, arc2Mid, arc2End, 0 );
111 chain.Append( arc2 );
112
113 SHAPE_LINE_CHAIN chainForward = chain;
114 SHAPE_LINE_CHAIN chainBackward = chain;
115 chainBackward.Reverse();
116
117 BOOST_REQUIRE_EQUAL( chainForward.Length(), chainBackward.Length() );
118
121
122 int64_t lengthForward = chainForward.Length();
123 int64_t lengthBackward = chainBackward.Length();
124
125 BOOST_CHECK_CLOSE( static_cast<double>( lengthForward ), static_cast<double>( lengthBackward ), 0.5 );
126
127 BOOST_CHECK_CLOSE( lengthForward / 1000000.0, 3.8246, 2.0 );
128}
129
130
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
static void OptimiseTraceInPad(SHAPE_LINE_CHAIN &aLine, const PAD *aPad, PCB_LAYER_ID aPcbLayer)
Optimises the given trace / line to minimise the electrical path length within the given pad.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_LINE_CHAIN Reverse() const
Reverse point order in the line chain.
long long int Length() const
Return length of the line chain in Euclidean metric.
@ F_Cu
Definition layer_ids.h:60
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:99
@ ROUNDRECT
Definition padstack.h:57
std::unique_ptr< PAD > MakePad()
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(Issue22612_ArcStartsAtPadCenter)
BOOST_AUTO_TEST_SUITE_END()
SHAPE_ARC arc2(c.m_arc2.GenerateArc())
const SHAPE_LINE_CHAIN chain
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683