KiCad PCB EDA Suite
test_shape_compound_collision.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) 2017 CERN
5  * @author Alejandro GarcĂ­a Montoro <alejandro.garciamontoro@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
26 
28 #include <geometry/shape_circle.h>
29 
30 #include "fixtures_geometry.h"
31 
37 {
38  // Structure to store the common data.
40 
41  // Vectors containing colliding and non-colliding points
42  std::vector<SHAPE*> shapesA, shapesB, shapesC;
43 
47 
52  {
53  shapesA.push_back( new SHAPE_CIRCLE( VECTOR2I( 0, 0 ), 100 ) );
54  shapesA.push_back( new SHAPE_CIRCLE( VECTOR2I( 80, 0 ), 100 ) );
55 
56  shapesB.push_back( new SHAPE_CIRCLE( VECTOR2I( 0, 80 ), 100 ) );
57  shapesB.push_back( new SHAPE_CIRCLE( VECTOR2I( 80, 80 ), 100 ) );
58 
59  shapesC.push_back( new SHAPE_CIRCLE( VECTOR2I( 0, 280 ), 100 ) );
60  shapesC.push_back( new SHAPE_CIRCLE( VECTOR2I( 80, 280 ), 100 ) );
61 
65  }
66 
68  {
69  delete compoundA;
70  delete compoundB;
71  delete compoundC;
72  }
73 };
74 
75 
79 BOOST_FIXTURE_TEST_SUITE( SCompoundCollision, ShapeCompoundCollisionFixture )
80 
81 
82 
86 BOOST_AUTO_TEST_CASE( ShapeCompoundCollide )
87 {
88  int actual;
89  // Check points on corners
90  BOOST_CHECK( compoundA->Collide( compoundB, 0, &actual ) );
91  BOOST_CHECK( actual == 0 );
92 
93  BOOST_CHECK( !compoundA->Collide( compoundC, 0, &actual ) );
94  BOOST_CHECK( actual == 0 );
95 
96  BOOST_CHECK( compoundA->Collide( compoundC, 100, &actual ) );
97  BOOST_CHECK( actual == 80 );
98 
99  BOOST_CHECK( shapesA[0]->Collide( compoundB, 0 ) );
100  BOOST_CHECK( shapesA[1]->Collide( compoundB, 0 ) );
101  BOOST_CHECK( compoundB->Collide( shapesA[0], 0 ) );
102  BOOST_CHECK( compoundB->Collide( shapesA[1], 0 ) );
103 
104  BOOST_CHECK( shapesB[0]->Collide( compoundA, 0 ) );
105  BOOST_CHECK( shapesB[1]->Collide( compoundA, 0 ) );
106  BOOST_CHECK( compoundA->Collide( shapesB[0], 0 ) );
107  BOOST_CHECK( compoundA->Collide( shapesB[1], 0 ) );
108 
109  BOOST_CHECK( ! shapesC[0]->Collide( compoundA, 0 ) );
110  BOOST_CHECK( ! shapesC[1]->Collide( compoundA, 0 ) );
111  BOOST_CHECK( ! compoundA->Collide( shapesC[0], 0 ) );
112  BOOST_CHECK( ! compoundA->Collide( shapesC[1], 0 ) );
113 
114  BOOST_CHECK( ! shapesA[0]->Collide( compoundC, 0 ) );
115  BOOST_CHECK( ! shapesA[1]->Collide( compoundC, 0 ) );
116  BOOST_CHECK( ! compoundC->Collide( shapesA[0], 0 ) );
117  BOOST_CHECK( ! compoundC->Collide( shapesA[1], 0 ) );
118 
119  BOOST_CHECK( shapesC[0]->Collide( compoundA, 100, &actual ) );
120  BOOST_CHECK( actual == 80 );
121  BOOST_CHECK( shapesC[1]->Collide( compoundA, 100, &actual ) );
122  BOOST_CHECK( actual == 80 );
123  BOOST_CHECK( compoundA->Collide( shapesC[0], 100, &actual ) );
124  BOOST_CHECK( actual == 80 );
125  BOOST_CHECK( compoundA->Collide( shapesC[1], 100, &actual ) );
126  BOOST_CHECK( actual == 80 );
127 }
128 
129 
130 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ShapeCompoundCollide)
Declares the CollisionFixture as the boost test suite fixture.
Common data for some of the SHAPE_POLY_SET tests:
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
BOOST_CHECK(v2.Cross(v1)==1)
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
struct KI_TEST::CommonTestData common
Fixture for the Collision test suite.