KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_line_chain_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 <[email protected]>
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
27#include <geometry/shape.h>
28#include <geometry/shape_arc.h>
30
31#include "fixtures_geometry.h"
32
33
34BOOST_AUTO_TEST_SUITE( SHAPE_LINE_CHAIN_COLLIDE_TEST )
35
36BOOST_AUTO_TEST_CASE( Collide_LineToLine )
37{
38 SHAPE_LINE_CHAIN lineA;
39 lineA.Append( VECTOR2I( 0, 0 ) );
40 lineA.Append( VECTOR2I( 10, 0 ) );
41
42 SHAPE_LINE_CHAIN lineB;
43 lineB.Append( VECTOR2I( 5, 5 ) );
44 lineB.Append( VECTOR2I( 5, -5 ) );
45
46 VECTOR2I location;
47 int actual = 0;
48 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 0, &actual, &location );
49
50 BOOST_CHECK( collided );
51 BOOST_TEST( actual == 0 );
52 BOOST_CHECK_MESSAGE( location == VECTOR2I( 5, 0 ), "Expected: " << VECTOR2I( 5, 0 ) << " Actual: " << location );
53}
54
55BOOST_AUTO_TEST_CASE( Collide_LineToArc )
56{
57 SHAPE_LINE_CHAIN lineA;
58 lineA.Append( VECTOR2I( 0, 0 ) );
59 lineA.Append( VECTOR2I( 10, 0 ) );
60
62 arcB.Append( SHAPE_ARC( VECTOR2I( 5, 5 ), VECTOR2I( 6, 4 ), VECTOR2I( 7, 0 ), 0 ) );
63
64 VECTOR2I location;
65 int actual = 0;
66 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &arcB, 0, &actual, &location );
67
68 BOOST_CHECK( collided );
69 BOOST_TEST( actual == 0 );
70 BOOST_CHECK_MESSAGE( location == VECTOR2I( 7, 0 ), "Expected: " << VECTOR2I( 7, 0 ) << " Actual: " << location );
71}
72
73BOOST_AUTO_TEST_CASE( Collide_ArcToArc )
74{
76 arcA.Append( SHAPE_ARC( VECTOR2I( 0, 0 ), VECTOR2I( 10, 0 ), VECTOR2I( 5, 5 ), 0 ) );
77
79 arcB.Append( SHAPE_ARC( VECTOR2I( 5, 5 ), VECTOR2I( 5, -5 ), VECTOR2I( 10, 0 ), 0 ) );
80
81 VECTOR2I location;
82 int actual = 0;
83 bool collided = static_cast<SHAPE*>( &arcA )->Collide( &arcB, 0, &actual, &location );
84
85 BOOST_CHECK( collided );
86 BOOST_TEST( actual == 0 );
87 BOOST_CHECK_MESSAGE( location == VECTOR2I( 5, 5 ), "Expected: " << VECTOR2I( 5, 5 ) << " Actual: " << location );
88}
89
90BOOST_AUTO_TEST_CASE( Collide_WithClearance )
91{
92 SHAPE_LINE_CHAIN lineA;
93 lineA.Append( VECTOR2I( 0, 0 ) );
94 lineA.Append( VECTOR2I( 10, 0 ) );
95
96 SHAPE_LINE_CHAIN lineB;
97 lineB.Append( VECTOR2I( 5, 6 ) );
98 lineB.Append( VECTOR2I( -5, 6 ) );
99
100 VECTOR2I location;
101 int actual = 0;
102 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 7, &actual, &location );
103
104 BOOST_CHECK( collided );
105 BOOST_CHECK_MESSAGE( actual == 6, "Expected: " << 6 << " Actual: " << actual );
106 BOOST_CHECK_MESSAGE( location == VECTOR2I( 0, 0 ), "Expected: " << VECTOR2I( 0, 0 ) << " Actual: " << location );
107}
108
109BOOST_AUTO_TEST_CASE( Collide_NoClearance )
110{
111 SHAPE_LINE_CHAIN lineA;
112 lineA.Append( VECTOR2I( 0, 0 ) );
113 lineA.Append( VECTOR2I( 10, 0 ) );
114
115 SHAPE_LINE_CHAIN lineB;
116 lineB.Append( VECTOR2I( 5, 6 ) );
117 lineB.Append( VECTOR2I( -5, 6 ) );
118
119 VECTOR2I location;
120 int actual = 0;
121 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 0, &actual, &location );
122
123 BOOST_CHECK( !collided );
124 BOOST_CHECK_MESSAGE( actual == 0, "Expected: " << 0 << " Actual: " << actual );
125}
126
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
An abstract shape on 2D plane.
Definition: shape.h:126
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
BOOST_TEST(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Collide_LineToLine)
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691