KiCad PCB EDA Suite
test_circle.cpp File Reference

Go to the source code of this file.

Classes

struct  CIR_PT_PT_CASE
 Struct to hold test cases for a given circle, a point and an expected return point. More...
 
struct  CIR_CIR_VECPT_CASE
 Struct to hold test cases for two circles, and an vector of points. More...
 
struct  SEG_SEG_VECPT_CASE
 Struct to hold test cases for a circle, a line and an expected vector of points. More...
 
struct  CIR_SEG_VECPT_CASE
 Struct to hold test cases for two lines, a point and an expected returned circle. More...
 

Functions

bool CompareLength (int aLengthA, int aLengthB)
 
bool CompareVector2I (const VECTOR2I &aVecA, const VECTOR2I &aVecB)
 
 BOOST_AUTO_TEST_CASE (ParameterCtorMod)
 Checks whether the construction of a circle referencing external parameters works and that the parameters can be modified directly. More...
 
 BOOST_AUTO_TEST_CASE (NearestPoint)
 
 BOOST_AUTO_TEST_CASE (IntersectCircle)
 
 BOOST_AUTO_TEST_CASE (IntersectLine)
 
 BOOST_AUTO_TEST_CASE (ConstructFromTanTanPt)
 

Variables

static const std::vector< CIR_PT_PT_CASEnearest_point_cases
 Test cases for CIRCLE::NearestPoint. More...
 
static const std::vector< CIR_CIR_VECPT_CASEintersect_circle_cases
 Test cases for #CIRCLE::Intersect( const CIRCLE& aCircle ) More...
 
static const std::vector< SEG_SEG_VECPT_CASEintersect_line_cases
 Test cases for #CIRCLE::Intersect( const SEG& aSeg ) More...
 
static const std::vector< CIR_SEG_VECPT_CASEconstruct_tan_tan_pt_cases
 Test cases for #CIRCLE::Intersect( const SEG& aSeg ) More...
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( ParameterCtorMod  )

Checks whether the construction of a circle referencing external parameters works and that the parameters can be modified directly.

Definition at line 54 of file test_circle.cpp.

55 {
56  const VECTOR2I center( 10, 20 );
57  const int radius = 10;
58 
59  // Build a circle referencing the previous values
60  CIRCLE circle( center, radius );
61 
62  BOOST_CHECK_EQUAL( circle.Center, VECTOR2I( 10, 20 ) );
63  BOOST_CHECK_EQUAL( circle.Radius, 10 );
64 
65  // Modify the parameters
66  circle.Center += VECTOR2I( 10, 10 );
67  circle.Radius += 20;
68 
69  // Check the parameters were modified
70  BOOST_CHECK_EQUAL( circle.Center, VECTOR2I( 20, 30 ) );
71  BOOST_CHECK_EQUAL( circle.Radius, 30 );
72 }
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
Class Circle Represents basic circle geometry with utility geometry functions.
Definition: circle.h:33

References CIRCLE::Center, and CIRCLE::Radius.

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( NearestPoint  )

Definition at line 119 of file test_circle.cpp.

120 {
121  for( const auto& c : nearest_point_cases )
122  {
123  BOOST_TEST_CONTEXT( c.m_case_name )
124  {
125  VECTOR2I ret = c.m_circle.NearestPoint( c.m_point );
126  BOOST_CHECK_EQUAL( ret, c.m_exp_result );
127  }
128  }
129 }
Define a general 2D-vector/point.
Definition: vector2d.h:61
static const std::vector< CIR_PT_PT_CASE > nearest_point_cases
Test cases for CIRCLE::NearestPoint.
Definition: test_circle.cpp:90
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, and nearest_point_cases.

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( IntersectCircle  )

Definition at line 186 of file test_circle.cpp.

187 {
188  for( const auto& c : intersect_circle_cases )
189  {
190  BOOST_TEST_CONTEXT( c.m_case_name + " Case 1" )
191  {
192  std::vector<VECTOR2I> ret1 = c.m_circle1.Intersect( c.m_circle2 );
193  BOOST_CHECK_EQUAL( c.m_exp_result.size(), ret1.size() );
194  KI_TEST::CheckUnorderedMatches( c.m_exp_result, ret1, CompareVector2I );
195  }
196 
197  BOOST_TEST_CONTEXT( c.m_case_name + " Case 2" )
198  {
199  // Test the other direction
200  std::vector<VECTOR2I> ret2 = c.m_circle2.Intersect( c.m_circle1 );
201  BOOST_CHECK_EQUAL( c.m_exp_result.size(), ret2.size() );
202  KI_TEST::CheckUnorderedMatches( c.m_exp_result, ret2, CompareVector2I );
203  }
204  }
205 }
static const std::vector< CIR_CIR_VECPT_CASE > intersect_circle_cases
Test cases for #CIRCLE::Intersect( const CIRCLE& aCircle )
bool CompareVector2I(const VECTOR2I &aVecA, const VECTOR2I &aVecB)
Definition: test_circle.cpp:37
void CheckUnorderedMatches(const EXP_CONT &aExpected, const FOUND_CONT &aFound, MATCH_PRED aMatchPredicate)
Check that a container of "found" objects matches a container of "expected" objects.
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, KI_TEST::CheckUnorderedMatches(), CompareVector2I(), and intersect_circle_cases.

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( IntersectLine  )

Definition at line 262 of file test_circle.cpp.

263 {
264  for( const auto& c : intersect_line_cases )
265  {
266  BOOST_TEST_CONTEXT( c.m_case_name )
267  {
268  std::vector<VECTOR2I> ret = c.m_circle.Intersect( c.m_seg );
269  BOOST_CHECK_EQUAL( c.m_exp_result.size(), ret.size() );
270  KI_TEST::CheckUnorderedMatches( c.m_exp_result, ret, CompareVector2I );
271  }
272  }
273 }
static const std::vector< SEG_SEG_VECPT_CASE > intersect_line_cases
Test cases for #CIRCLE::Intersect( const SEG& aSeg )
bool CompareVector2I(const VECTOR2I &aVecA, const VECTOR2I &aVecB)
Definition: test_circle.cpp:37
void CheckUnorderedMatches(const EXP_CONT &aExpected, const FOUND_CONT &aFound, MATCH_PRED aMatchPredicate)
Check that a container of "found" objects matches a container of "expected" objects.
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, KI_TEST::CheckUnorderedMatches(), CompareVector2I(), and intersect_line_cases.

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( ConstructFromTanTanPt  )

Definition at line 347 of file test_circle.cpp.

348 {
349  for( const auto& c : construct_tan_tan_pt_cases )
350  {
351  BOOST_TEST_CONTEXT( c.m_case_name )
352  {
353  CIRCLE circle;
354  circle.ConstructFromTanTanPt( c.m_segA, c.m_segB, c.m_pt );
355  BOOST_CHECK_MESSAGE( CompareVector2I( c.m_exp_result.Center, circle.Center ),
356  "\nCenter point mismatch: "
357  << "\n Got: " << circle.Center
358  << "\n Expected: " << c.m_exp_result.Center );
359 
360  BOOST_CHECK_MESSAGE( CompareLength( c.m_exp_result.Radius, circle.Radius ),
361  "\nRadius mismatch: "
362  << "\n Got: " << circle.Radius
363  << "\n Expected: " << c.m_exp_result.Radius );
364  }
365  }
366 }
CIRCLE & ConstructFromTanTanPt(const SEG &aLineA, const SEG &aLineB, const VECTOR2I &aP)
Constructs this circle such that it is tangent to the given segmetns and passes through the given poi...
Definition: circle.cpp:51
bool CompareVector2I(const VECTOR2I &aVecA, const VECTOR2I &aVecB)
Definition: test_circle.cpp:37
int Radius
Public to make access simpler.
Definition: circle.h:36
Class Circle Represents basic circle geometry with utility geometry functions.
Definition: circle.h:33
bool CompareLength(int aLengthA, int aLengthB)
Definition: test_circle.cpp:27
#define BOOST_TEST_CONTEXT(A)
static const std::vector< CIR_SEG_VECPT_CASE > construct_tan_tan_pt_cases
Test cases for #CIRCLE::Intersect( const SEG& aSeg )
VECTOR2I Center
Public to make access simpler.
Definition: circle.h:37

References BOOST_TEST_CONTEXT, CIRCLE::Center, CompareLength(), CompareVector2I(), construct_tan_tan_pt_cases, CIRCLE::ConstructFromTanTanPt(), and CIRCLE::Radius.

◆ CompareLength()

bool CompareLength ( int  aLengthA,
int  aLengthB 
)

Definition at line 27 of file test_circle.cpp.

28 {
29  if( aLengthA > ( aLengthB + SHAPE::MIN_PRECISION_IU ) )
30  return false;
31  else if( aLengthA < ( aLengthB - SHAPE::MIN_PRECISION_IU ) )
32  return false;
33  else
34  return true;
35 }
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in a shape.
Definition: shape.h:122

References SHAPE::MIN_PRECISION_IU.

Referenced by BOOST_AUTO_TEST_CASE(), and CompareVector2I().

◆ CompareVector2I()

bool CompareVector2I ( const VECTOR2I aVecA,
const VECTOR2I aVecB 
)

Definition at line 37 of file test_circle.cpp.

38 {
39  if( !CompareLength(aVecA.x, aVecB.x) )
40  return false;
41  else if( !CompareLength( aVecA.y, aVecB.y ) )
42  return false;
43  else
44  return true;
45 }
bool CompareLength(int aLengthA, int aLengthB)
Definition: test_circle.cpp:27

References CompareLength(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE().

Variable Documentation

◆ construct_tan_tan_pt_cases

const std::vector<CIR_SEG_VECPT_CASE> construct_tan_tan_pt_cases
static

Test cases for #CIRCLE::Intersect( const SEG& aSeg )

Definition at line 291 of file test_circle.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ intersect_circle_cases

const std::vector<CIR_CIR_VECPT_CASE> intersect_circle_cases
static

Test cases for #CIRCLE::Intersect( const CIRCLE& aCircle )

Definition at line 147 of file test_circle.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ intersect_line_cases

const std::vector<SEG_SEG_VECPT_CASE> intersect_line_cases
static

Test cases for #CIRCLE::Intersect( const SEG& aSeg )

Definition at line 223 of file test_circle.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ nearest_point_cases

const std::vector<CIR_PT_PT_CASE> nearest_point_cases
static
Initial value:
= {
{
"on center",
{ { 10, 10 }, 20 },
{ 10, 10 },
{ 30, 10 },
},
{
"inside",
{ { 10, 10 }, 20 },
{ 10, 20 },
{ 10, 30 },
},
{
"outside",
{ { 10, 10 }, 20 },
{ 10, 50 },
{ 10, 30 },
},
{
"angled",
{ { 10, 10 }, 20 },
{ 50, 50 },
{ 24, 24 },
},
}

Test cases for CIRCLE::NearestPoint.

Definition at line 90 of file test_circle.cpp.

Referenced by BOOST_AUTO_TEST_CASE().