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 std::unique_ptr<PAD> pad = std::make_unique<PAD>( &m_footprint );
42 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
43 pad->SetAttribute( PAD_ATTRIB::SMD );
45 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( 2540000, 1270000 ) );
46 pad->SetPosition( VECTOR2I( 189190000, 46760000 ) );
47 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, 0.15 );
48 pad->SetLayerSet( LSET( { F_Cu } ) );
49 return pad;
50 }
51
54};
55
56
57BOOST_FIXTURE_TEST_SUITE( ClipLineToPad, CLIP_LINE_TO_PAD_FIXTURE )
58
59
60BOOST_AUTO_TEST_CASE( Issue22612_ArcStartsAtPadCenter )
61{
62 auto pad = MakePad();
63
64 const VECTOR2I arcStart( 189190000, 46760000 );
65 const VECTOR2I arcMid( 190382763, 46815467 );
66 const VECTOR2I arcEnd( 189758445, 47833301 );
67
69 chain.Append( arcStart );
70
71 SHAPE_ARC arc( arcStart, arcMid, arcEnd, 0 );
72 chain.Append( arc );
73
74 SHAPE_LINE_CHAIN chainForward = chain;
75 SHAPE_LINE_CHAIN chainBackward = chain;
76 chainBackward.Reverse();
77
78 BOOST_REQUIRE_EQUAL( chainForward.Length(), chainBackward.Length() );
79
82
83 int64_t lengthForward = chainForward.Length();
84 int64_t lengthBackward = chainBackward.Length();
85
86 BOOST_CHECK_CLOSE( static_cast<double>( lengthForward ), static_cast<double>( lengthBackward ), 0.5 );
87
88 BOOST_CHECK_CLOSE( lengthForward / 1000000.0, 2.4778, 2.0 );
89}
90
91BOOST_AUTO_TEST_CASE( Issue22612_TwoArcsFromPadCenter )
92{
93 auto pad = MakePad();
94
95 // Arc 1: starts at pad center
96 const VECTOR2I arc1Start( 189190000, 46760000 );
97 const VECTOR2I arc1Mid( 189810000, 46140000 );
98 const VECTOR2I arc1End( 190430000, 46760000 );
99
100 // Arc 2: connects to arc1 end, defined in chain direction
101 const VECTOR2I arc2Start( 190430000, 46760000 );
102 const VECTOR2I arc2Mid( 191310000, 47640000 );
103 const VECTOR2I arc2End( 192190000, 46760000 );
104
106 chain.Append( arc1Start );
107
108 SHAPE_ARC arc1( arc1Start, arc1Mid, arc1End, 0 );
109 chain.Append( arc1 );
110
111 SHAPE_ARC arc2( arc2Start, arc2Mid, arc2End, 0 );
112 chain.Append( arc2 );
113
114 SHAPE_LINE_CHAIN chainForward = chain;
115 SHAPE_LINE_CHAIN chainBackward = chain;
116 chainBackward.Reverse();
117
118 BOOST_REQUIRE_EQUAL( chainForward.Length(), chainBackward.Length() );
119
122
123 int64_t lengthForward = chainForward.Length();
124 int64_t lengthBackward = chainBackward.Length();
125
126 BOOST_CHECK_CLOSE( static_cast<double>( lengthForward ), static_cast<double>( lengthBackward ), 0.5 );
127
128 BOOST_CHECK_CLOSE( lengthForward / 1000000.0, 3.8246, 2.0 );
129}
130
131
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
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
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:170
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
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:98
@ ROUNDRECT
Definition padstack.h:56
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