KiCad PCB EDA Suite
test_lib_arc.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 (C) 2020 KiCad Developers, see CHANGELOG.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 
30 #include <trigo.h>
31 #include <convert_to_biu.h>
32 
33 // Code under test
34 #include <lib_arc.h>
35 
37 {
38 public:
40  m_arc( nullptr )
41  {
42  }
43 
46 };
47 
48 
52 BOOST_FIXTURE_TEST_SUITE( LibArc, TEST_LIB_ARC_FIXTURE )
53 
54 
55 
58 BOOST_AUTO_TEST_CASE( DefaultProperties )
59 {
60  BOOST_CHECK_EQUAL( m_arc.Type(), LIB_ARC_T );
61  BOOST_CHECK_EQUAL( m_arc.GetClass(), "LIB_ARC" );
62  BOOST_CHECK_EQUAL( m_arc.GetPosition(), wxPoint( 0, 0 ) );
63 }
64 
65 
69 BOOST_AUTO_TEST_CASE( TestCalcRadiusAngles )
70 {
71  double radius = 5.0; // Use millimeters and convert to internal units.
72  int startX = Millimeter2iu( radius * cos( DEG2RAD( 10.0 ) ) );
73  int startY = Millimeter2iu( radius * sin( DEG2RAD( 10.0 ) ) );
74  int endX = Millimeter2iu( radius * cos( DEG2RAD( 45.0 ) ) );
75  int endY = Millimeter2iu( radius * sin( DEG2RAD( 45.0 ) ) );
76 
77  m_arc.SetStart( wxPoint( startX, startY ) );
78  m_arc.SetEnd( wxPoint( endX, endY ) );
79 
80  m_arc.CalcRadiusAngles();
81  BOOST_CHECK_EQUAL( m_arc.GetFirstRadiusAngle(), 100 );
82  BOOST_CHECK_EQUAL( m_arc.GetSecondRadiusAngle(), 450 );
83 
84  // Set arc end point in the second quadrant.
85  endX = Millimeter2iu( radius * cos( DEG2RAD( 145.0 ) ) );
86  endY = Millimeter2iu( radius * sin( DEG2RAD( 145.0 ) ) );
87  m_arc.SetEnd( wxPoint( endX, endY ) );
88  m_arc.CalcRadiusAngles();
89  BOOST_CHECK_EQUAL( m_arc.GetFirstRadiusAngle(), 100 );
90  BOOST_CHECK_EQUAL( m_arc.GetSecondRadiusAngle(), 1450 );
91 }
92 
93 
98 BOOST_AUTO_TEST_CASE( TestCalcMidPoint )
99 {
100  // Midpoint angle is 77.5 degrees.
101  m_arc.SetRadius( Millimeter2iu( 5.0 ) );
102  m_arc.SetFirstRadiusAngle( 100 );
103  m_arc.SetSecondRadiusAngle( 1450 );
104  BOOST_CHECK_EQUAL( m_arc.CalcMidPoint(), VECTOR2I( 10822, 48815 ) );
105  m_arc.SetFirstRadiusAngle( 850 );
106  m_arc.SetSecondRadiusAngle( 950 );
107  BOOST_CHECK_EQUAL( m_arc.CalcMidPoint(), VECTOR2I( 0, 50000 ) );
108  m_arc.SetFirstRadiusAngle( 1700 );
109  m_arc.SetSecondRadiusAngle( 1900 );
110  BOOST_CHECK_EQUAL( m_arc.CalcMidPoint(), VECTOR2I( -50000, 0 ) );
111  m_arc.SetFirstRadiusAngle( 2500 );
112  m_arc.SetSecondRadiusAngle( 2900 );
113  BOOST_CHECK_EQUAL( m_arc.CalcMidPoint(), VECTOR2I( 0, -50000 ) );
114  m_arc.SetFirstRadiusAngle( 3500 );
115  m_arc.SetSecondRadiusAngle( 100 );
116  BOOST_CHECK_EQUAL( m_arc.CalcMidPoint(), VECTOR2I( 50000, 0 ) );
117 }
118 
119 
120 BOOST_AUTO_TEST_SUITE_END()
LIB_ARC m_arc
Part with no extra data set
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
double DEG2RAD(double deg)
Definition: trigo.h:231
static constexpr int Millimeter2iu(double mm)