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, you may find one here:
18* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19* or you may search the http://www.gnu.org website for the version 2 license,
20* or you may write to the Free Software Foundation, Inc.,
21* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22*/
23
25#include <board.h>
26#include <footprint.h>
27#include <pad.h>
29#include <geometry/shape_arc.h>
31
32#include <iostream>
33
34
36{
42
43 std::unique_ptr<PAD> MakePad()
44 {
45 auto pad = std::make_unique<PAD>( &m_footprint );
46 pad->SetAttribute( PAD_ATTRIB::SMD );
48 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( 2540000, 1270000 ) );
49 pad->SetPosition( VECTOR2I( 189190000, 46760000 ) );
50 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, 0.15 );
51 pad->SetLayerSet( LSET( { F_Cu } ) );
52 return pad;
53 }
54
57};
58
59
60BOOST_FIXTURE_TEST_SUITE( ClipLineToPad, CLIP_LINE_TO_PAD_FIXTURE )
61
62
63BOOST_AUTO_TEST_CASE( Issue22612_ArcStartsAtPadCenter )
64{
65 auto pad = MakePad();
66
67 const VECTOR2I arcStart( 189190000, 46760000 );
68 const VECTOR2I arcMid( 190382763, 46815467 );
69 const VECTOR2I arcEnd( 189758445, 47833301 );
70
72 chain.Append( arcStart );
73
74 SHAPE_ARC arc( arcStart, arcMid, arcEnd, 0 );
75 chain.Append( arc );
76
77 SHAPE_LINE_CHAIN chainForward = chain;
78 SHAPE_LINE_CHAIN chainBackward = chain;
79 chainBackward.Reverse();
80
81 BOOST_REQUIRE_EQUAL( chainForward.Length(), chainBackward.Length() );
82
85
86 int64_t lengthForward = chainForward.Length();
87 int64_t lengthBackward = chainBackward.Length();
88
89 BOOST_CHECK_CLOSE( static_cast<double>( lengthForward ), static_cast<double>( lengthBackward ), 0.5 );
90
91 BOOST_CHECK_CLOSE( lengthForward / 1000000.0, 2.4778, 2.0 );
92}
93
94BOOST_AUTO_TEST_CASE( Issue22612_TwoArcsFromPadCenter )
95{
96 auto pad = MakePad();
97
98 // Arc 1: starts at pad center
99 const VECTOR2I arc1Start( 189190000, 46760000 );
100 const VECTOR2I arc1Mid( 189810000, 46140000 );
101 const VECTOR2I arc1End( 190430000, 46760000 );
102
103 // Arc 2: connects to arc1 end, defined in chain direction
104 const VECTOR2I arc2Start( 190430000, 46760000 );
105 const VECTOR2I arc2Mid( 191310000, 47640000 );
106 const VECTOR2I arc2End( 192190000, 46760000 );
107
109 chain.Append( arc1Start );
110
111 SHAPE_ARC arc1( arc1Start, arc1Mid, arc1End, 0 );
112 chain.Append( arc1 );
113
114 SHAPE_ARC arc2( arc2Start, arc2Mid, arc2End, 0 );
115 chain.Append( arc2 );
116
117 SHAPE_LINE_CHAIN chainForward = chain;
118 SHAPE_LINE_CHAIN chainBackward = chain;
119 chainBackward.Reverse();
120
121 BOOST_REQUIRE_EQUAL( chainForward.Length(), chainBackward.Length() );
122
125
126 int64_t lengthForward = chainForward.Length();
127 int64_t lengthBackward = chainBackward.Length();
128
129 BOOST_CHECK_CLOSE( static_cast<double>( lengthForward ), static_cast<double>( lengthBackward ), 0.5 );
130
131 BOOST_CHECK_CLOSE( lengthForward / 1000000.0, 3.8246, 2.0 );
132}
133
134
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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:64
@ 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:695