KiCad PCB EDA Suite
test_lib_arc.cpp File Reference

Test suite for LIB_ARC. More...

#include <unit_test_utils/unit_test_utils.h>
#include <trigo.h>
#include <convert_to_biu.h>
#include <lib_arc.h>

Go to the source code of this file.

Classes

class  TEST_LIB_ARC_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (DefaultProperties)
 Declare the test suite. More...
 
 BOOST_AUTO_TEST_CASE (TestCalcRadiusAngles)
 Test the function that calculates the radius angles based on the center, start, and end points. More...
 
 BOOST_AUTO_TEST_CASE (TestCalcMidPoint)
 Test the function that calculates the mid point based on the start and end angles and radius length. More...
 

Detailed Description

Test suite for LIB_ARC.

Definition in file test_lib_arc.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( DefaultProperties  )

Declare the test suite.

Check that we can get the default properties out as expected

Definition at line 58 of file test_lib_arc.cpp.

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 }

References LIB_ARC_T.

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( TestCalcRadiusAngles  )

Test the function that calculates the radius angles based on the center, start, and end points.

Definition at line 69 of file test_lib_arc.cpp.

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 }
double DEG2RAD(double deg)
Definition: trigo.h:231
static constexpr int Millimeter2iu(double mm)

References DEG2RAD(), and Millimeter2iu().

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( TestCalcMidPoint  )

Test the function that calculates the mid point based on the start and end angles and radius length.

Definition at line 98 of file test_lib_arc.cpp.

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 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
static constexpr int Millimeter2iu(double mm)

References Millimeter2iu().